You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should I use different agent instances for different hosts or use a global one? #98
If I need to connect to different hosts, it's better to use a separated agent instance for each of this hosts, or use the same agent for all the connections?
I stopped using this library, and started using the native Agent class of Node. It has a keepAlive parameter, which defaults to false, but when enabled, it keeps sockets alive in a per-host basis. I made several tests comparing performance with both agents (multiple requests to a few different hosts) and the native Node (v14) implementation gave me better results than this library.
As to the question if it is better to use the same instance for all hosts, or a separated one for each host, I found no noticeable difference in performance between these approaches. Using always the same Agent instance for all requests, no matter what host, is easier to maintain, so this is how I'm doing it.
I found this to be the better performant config, at least for my use case: high concurrency, lots of requests per second, and a few selection of hosts.
import{AgentasHttpsAgent}from'https';exportconsthttpsAgent=newHttpsAgent({keepAlive: true,timeout: 30*1000,maxSockets: 8,// this is per-host.scheduling: 'fifo',});
Activity
gchicoye commentedon Jul 6, 2021
Same question, did you find out @Aex12 ?
Aex12 commentedon Jul 22, 2021
I stopped using this library, and started using the native Agent class of Node. It has a keepAlive parameter, which defaults to false, but when enabled, it keeps sockets alive in a per-host basis. I made several tests comparing performance with both agents (multiple requests to a few different hosts) and the native Node (v14) implementation gave me better results than this library.
As to the question if it is better to use the same instance for all hosts, or a separated one for each host, I found no noticeable difference in performance between these approaches. Using always the same Agent instance for all requests, no matter what host, is easier to maintain, so this is how I'm doing it.
I found this to be the better performant config, at least for my use case: high concurrency, lots of requests per second, and a few selection of hosts.
You can checkout the rest of parameters available here:
https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_new_agent_options
brandondoran commentedon Sep 15, 2021
@Aex12 did you compare
fifovslifo?Aex12 commentedon Sep 15, 2021
FIFO is better suited when you have lots of requests per second to the same host. LIFO is better when you have occasional requests to the same host.
kurtextrem commentedon Oct 5, 2021
Just a heads-up: The manual solution does not automatically call
setNoDelay()like this package does.harsh-sri commentedon Oct 13, 2023
Imo, Using same agent would be better considering the memory imact.