Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to multiple servers using axios keep alive

I'm refactoring a server that pulls information from several different APIs to use a keep-alive connection. The only example I've seen that uses keep alive with axios uses a single axios instance with an agent that has keep alive set to true. If I'm connecting to multiple api's, that are all run on different servers, can I use a single axios instance or would I have to create an instance for each server that I connect to?

like image 607
Developer Extraordinare Avatar asked Dec 22 '25 01:12

Developer Extraordinare


1 Answers

After considerable testing (we set up a server to connect to several host simultaneously and let it run for a bit) it looks like you only need a single axios instance and a single agent to handle any number of hosts. As a side note, the agentkeepalive package is a good agent to use because it handles cleaning up sockets that the https agent package doesn't

like image 131
Developer Extraordinare Avatar answered Dec 24 '25 04:12

Developer Extraordinare