hapi
hapi copied to clipboard
Add support for event loop utilization based load limit
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: n/a
- module version: n/a
- environment (e.g. node, browser, native): n/a
- used with (e.g. hapi application, another framework, standalone, ...): n/a
- any other relevant information: n/a
What problem are you trying to solve?
Hapi currently supports limiting the server load by measuring the event loop delay and memory usage. Node recently introduced a new metric event loop utilization which is meant to more accurately measure the cpu utilization, a good candidate for this functionality:
ELU is similar to CPU utilization, except that it only measures event loop statistics and not CPU usage. It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait). No other CPU idle time is taken into consideration.
Do you have a new or modified API suggestion to solve the problem?
We could introduce a new option as part of the server load options:
server.options.loadmaxEventLoopUtilization- maximum event loop utilization value in milliseconds over which incoming request are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
'use strict';
const Hapi = require('@hapi/hapi');
const server = Hapi.server({
load: {
maxEventLoopUtilization: 0,
},
});
While I expect that reporting the eventLoopUtilization could be a useful metric, I feel a maxEventLoopUtilization option could be dangerous to use. The point of the "max" limits is to drop incoming requests in order to better serve the existing ones. So a value of 0.95 could seem appropriate. However, a fully loaded system might never trigger this, and could max out at eg. 0.5.
Do you have a specific idea of how this could be applied? Or done some actual load-testing that shows that this can help?
Reconsidering this, and I think it is probably useful as just another way to handle some cases of high load.
This seems as a nice addition to hapi. Thanks @jonathansamines for the suggestion. The API proposal LGTM.
This is already supported as of @hapi/hapi 21.0.0.
Adding to the release notes 👍