Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
retrohacker committed Sep 8, 2017
1 parent fd7b3a5 commit 6c269be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/api/plugins.md
Expand Up @@ -563,6 +563,15 @@ Params:
* `halfLife` - When we sample the CPU usage on an interval, we create a series of data points. We take these points and calculate a moving average. The halfLife indicates how quickly a point "decays" to half it's value in the moving average. The lower the halfLife, the more impact newer data points have on the average. If you want to be extremely responsive to spikes in CPU usage, set this to a lower value. If you want your process to put more emphasis on recent historical CPU usage when determininng whether it should shed load, set this to a higher value. The unit is in ms. The default is to set this to the same value as interval.
* `err` - A restify error used as a response when the cpu usage limit is exceeded
You can also update the plugin during runtime using the `.update()` function. This function accepts the same `opts` object as a constructor.
```js
var plugin = restify.plugins.cpuUsageThrottle(options);
server.pre(plugin);

plugin.update({ limit: .4, halfLife: 5000 });
```
## Conditional Request Handler
```js
Expand Down
10 changes: 9 additions & 1 deletion lib/plugins/cpuUsageThrottle.js
Expand Up @@ -178,7 +178,14 @@ function cpuUsageThrottle (opts) {
// Expose internal plugin state for introspection
onRequest.state = self;

// Allow the plugin's configuration to be updated during runtime
/**
* cpuUsageThrottle.update
*
* Allow the plugin's configuration to be updated during runtime.
*
* @param {Object} opts The opts object for reconfiguring this plugin, it
* follows the same format as the constructor for this plugin.
*/
onRequest.update = function update(newOpts) {
assert.object(newOpts, 'newOpts');
assert.optionalNumber(newOpts.limit, 'newOpts.limit');
Expand All @@ -191,6 +198,7 @@ function cpuUsageThrottle (opts) {
'newOpts.err must be an error');
assert.optionalNumber(newOpts.err.statusCode,
'newOpts.err.statusCode');
self._err = newOpts.err;
}

if (newOpts.limit !== undefined) {
Expand Down

0 comments on commit 6c269be

Please sign in to comment.