carbond.limiter.TooBusyLimiter

extends FunctionLimiter

TooBusyLimiter limits connections based on how busy the process is.

Properties

absMaxOutstandingReqs Integer
Required  
Description The absolute maximum number of outstanding requests.
useFiberPoolSize Boolean
Required  
Description Use Fiber’s pool size to set absMaxOutstandingReqs.
fiberPoolAllowedOverflow Number
Required  
Description Allow for more requests than Fiber.poolSize if limiting on Fiber.poolSize (i.e, absMaxOutstandingReqs == fiberPoolOverflow * Fiber.poolSize + Fiber.poolSize). Note, this only applies if useFiberPoolSize is true.
toobusyMaxLag Integer
Default 70
Description The number of milliseconds Node’s event loop must lag to trigger rate limiting of future requests.
toobusyInterval Integer
Default 500
Description The interval at which Node’s event loop lag will be tested.
maxOutstandingReqs Integer (read-only)
Description The current allowed number of outstanding requests.
outstandingReqs Integer (read-only)
Description The current number of outstanding requests.

Methods

fn (req, res, next) overrides FunctionLimiter
Arguments req (express.request): The current Request object.
res (express.response): The current Response object.
next (Function): Continuation.
Description

Evaluates whether the current request should be allowed based on how busy the server process is.

Each time this method is invoked, it will check if the event loop appears to be lagging and if the number of outstanding requests is greater than Fiber ‘s current pool size. A warning will be logged if the former is true and a debug message will be logged if the latter is true.

If the current number of outstanding requests is greater than maxOutstandingReqs or the event loop appears to be lagging too far behind, the request will be rejected and a 503 will be sent to the client. If the event loop is lagging, maxOutstandingRequests will be updated to reflect the current number of outstanding requests.

If the request is allowed and maxOutstandingReqs is less than absMaxOutstandingReqs, maxOutstandingReqs will increase exponentially with each additional request up to absMaxOutstandingReqs.

Finally, outstandingReqs is incremented, a callback is registered do decrement the counter on request completion, and control is passed to the next handler.

Example