I guess this is not a strictly Phoenix question so I’ll not tag it as such. I am wondering about the following - as HTTPoison uses hackney, can I set it up so it uses one socket for multiple concurrent requests (for that matter, requests to one host)?
The HTTPoison documentation says:
Normally hackney opens and closes connections on demand,
but it also creates a default pool of connections which are reused for requests to the same host.
If the connection and host support keepalive, the connection is kept open until explicitly closed.To use the default pool, you can just declare it as an option:
HTTPoison.get("httpbin.org/get", [], hackney: [pool: :default])
I tried using a custom pool with a large number of max_connections. However, I believe in this case hackney opens a new socket for each connection. Actually, I’m not sure if it is exactly for each connection but it certainly opens a lot of new sockets if I bump up the number of the max_connections for the pool I use. This looks like it should behave in this way, though.
Still, the hackney readme says that connections can be reused, which I take to also mean in essence that sockets can be reused:
By default all connections are created and closed dynamically by hackney
but sometimes you may want to reuse the same reference for your connections.
It’s especially useful if you just want to handle serially a couple of requests.
This discussion mentions that connections are reused for subsequent requests - HTTPoison connection pools - #3 by jola. But I was wondering if they can be reused for concurrent requests.
Edit: Added one more paragraph.