duduvz14
Async http requests using a single connection
I’m developing an application that needs to make frequent API calls to a web server, but the server only allows me to have one active http connection at a time. As i need to make several hundred requests every few minutes, i need this to be done asynchronously. I’ve thought about creating a hackney pool with a limit of one connection and using it for the requests. Does that sound like a good solution? How could I optimize performance in such a situation?
Thanks in advance.
Most Liked
benwilson512
Does the remote server support HTTP2? I’d consider looking into Mint, https://elixir-lang.org/blog/2019/02/25/mint-a-new-http-library-for-elixir/ it’s an HTTP client that would let you have the kind of control you need for this.
benwilson512
As I understand it that’s correct, HTTP1 does not let you multiplex different requests over a single connection.
sribe
They must be handled in order. You can send request #2 before getting the response to request #1, so you can overlap I/O, but responses will be in order, and 99.99% likely the server will process them in strictly sequential order. There is basically no concurrency over a single HTTP 1 connection. So you cannot have “optimum concurrency” for your requests because your provider is explicitly forbidding it.







