-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should I use different agent instances for different hosts or use a global one? #98
Comments
Same question, did you find out @Aex12 ? |
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 { Agent as HttpsAgent } from 'https';
export const httpsAgent = new HttpsAgent({
keepAlive: true,
timeout: 30 * 1000,
maxSockets: 8, // this is per-host.
scheduling: 'fifo',
}); You can checkout the rest of parameters available here: |
@Aex12 did you compare |
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. |
Just a heads-up: The manual solution does not automatically call |
Imo, Using same agent would be better considering the memory imact. |
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?
The text was updated successfully, but these errors were encountered: