nikody

nikody

HTTPoison and hackney pool connections and sockets

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.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement