So i currently have a node server running using the built in http module that is doing some heavy CPU computations, so I only want to allow 10 inbound requests at I time. I saw people some people using http.globalAgent.maxSockets = 10;
to limit the amount of outbound connections, but this still allows over 10 conncurrent connections to my server
I also saw people using server.maxConnections = 10;
but this just straight up rejects any connections after 10.
I want a way to limit inbound connections using the http module that allows me to only accept 10 open connections at once, and then put the rest into some kind of queue that will be processed once one of the other connections is finished. Is there an easy way to do this?
this concept is about throttling requests . there is a package in express you can use that . try this:
https://www.npmjs.com/package/express-throttle
and for stand alone http request you can use :
https://github.com/chilts/oibackoff
https://github.com/jhurliman/node-rate-limiter
https://www.npmjs.com/package/simple-rate-limiter
but about your case, you need to limit the usage of route per period of time. you can use : https://github.com/sindresorhus/p-queue