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

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement