[erlang-questions] httpc: connection per request

Marc Worrell marc@REDACTED
Mon Aug 1 10:21:31 CEST 2016


Hi Matwey,

You can use different profiles. One profile per connection.

A profile name is an atom, and you can start different profiles using inets.

Example code:

-spec ensure_profile(atom()) -> ok.
ensure_profile(Profile) ->
    case inets:start(httpc, [{profile, Profile}]) of
        {ok, _} -> ok;
        {error, {already_started, _}} -> ok
    end.


You can pass this profile name to httpc:request.

- Marc


> On 31 Jul 2016, at 20:55, Matwey V. Kornilov <matwey.kornilov@REDACTED> wrote:
> 
> Hello,
> 
> I use httpc in streaming mode to obtain the data from the remote hosts.
> This data are processed in the special manner.
> The processing of some stream pairs are depend on each other, i.e. the
> processing process simultaneously reads both HTTP responses (there is
> huge amount of data in each response, so I use streaming mode).
> When the pair is located at the same server I would like to have one
> connection per request, because I will easily run into dead lock
> otherwise as the following.
> The processor read some data from the first response stream and want to
> read data from the second in order to make some decision and process
> further. But the second request is awaiting until first response
> finished inside httpc. But the first response will never be finished
> because it is stop to read by processor which want second request
> running in parallel.
> 
> I would like to have one TCP connection per HTTP request in order not to
> deadlock. Is {max_keep_alive_length, 1} sufficient to achieve this?
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list