Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set maximum http client connections in Node.js

Tags:

http

node.js

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?

like image 929
thesmart Avatar asked Nov 30 '12 17:11

thesmart


1 Answers

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.

like image 187
Ohad Kravchick Avatar answered Oct 22 '22 14:10

Ohad Kravchick