Re:Do svidaniya, Igor, and thank you for Nginx
by CrLf on Wednesday January 19, 2022 @07:38AM
(#29992825)
> HAProxy is able to keep a connection queue and feed a maximum of (for example) 4 concurrent requests to the backend(s), thus providing back-pressure to incoming requests.
NGINX can do this as well, either with the "max_conns" parameter for upstreams, or (trickier, but perhaps more effective when the upstream is async) in combination with rate limiting:
limit_req_zone $server_name zone=root:10m rate=100r/s;
limit_req_status 429;
location / {
limit_req zone=root burst=100 delay=4;
}
The reason being that (unless my information is stale), NodeJS will happily accept all the connections thrown at it, eventually causing each connection to be starved of compute capacity and finally falling over. HAProxy is able to keep a connection queue and feed a maximum of (for example) 4 concurrent requests to the backend(s), thus providing back-pressure to incoming requests. Makes it a lot easier if you need to eventually scale your app horizontally, too.