I need to increase the number of outbound http sockets usable by a module I am writing. I know it is possible to do this globally using:
// increase max sockets
http.globalAgent.maxSockets = 1000;
What is the best pattern for authoring a module's maxSocket limit without affecting other modules?
Your best option is to pass an Agent object to every http and https request you are making, with maxSockets configured to your liking. This will have no effect on other modules. See http://nodejs.org/docs/latest/api/http.html#http_http_request_options_callback.
If you are using a framework yourself, rather than relying on the http module directly, it might be difficult and require some patching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With