carbond.limiter.TooBusyLimiter¶
extends FunctionLimiter
TooBusyLimiter limits connections based on how busy
the process is.
Properties¶
- ¶
absMaxOutstandingReqs IntegerRequired Description The absolute maximum number of outstanding requests.
- ¶
useFiberPoolSize BooleanRequired Description Use Fiber’s pool size to set absMaxOutstandingReqs.
- ¶
fiberPoolAllowedOverflow NumberRequired Description Allow for more requests than Fiber.poolSizeif limiting onFiber.poolSize(i.e,absMaxOutstandingReqs == fiberPoolOverflow * Fiber.poolSize + Fiber.poolSize). Note, this only applies ifuseFiberPoolSizeistrue.
- ¶
toobusyMaxLag IntegerDefault 70Description The number of milliseconds Node’s event loop must lag to trigger rate limiting of future requests.
- ¶
toobusyInterval IntegerDefault 500Description 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 FunctionLimiterArguments 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 istrueand a debug message will be logged if the latter istrue.If the current number of outstanding requests is greater than
maxOutstandingReqsor the event loop appears to be lagging too far behind, the request will be rejected and a503will be sent to the client. If the event loop is lagging,maxOutstandingRequestswill be updated to reflect the current number of outstanding requests.If the request is allowed and
maxOutstandingReqsis less thanabsMaxOutstandingReqs,maxOutstandingReqswill increase exponentially with each additional request up toabsMaxOutstandingReqs.Finally,
outstandingReqsis incremented, a callback is registered do decrement the counter on request completion, and control is passed to the next handler.