curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Couldn't connect to host (err: 7)

From: Hadi Rezaee via curl-library <curl-library_at_cool.haxx.se>
Date: Mon, 21 Sep 2020 11:33:46 +0330

Hello Daniel :)
and Thanks for the response.

If you keep doing requests against the same machine very frequently, why
> does
> it create new connections at all, shouldn't they all reuse the connection?
>

Correct,
The issue here is that obviously webserver has to process each request, and
the average time for processing each request is around 100ms. (based on
request types, the response time could be vary, for example there could be
a request which needs 500ms to be processed at webserver side)
While the client has to make 700~ REST calls for each second.

So, basically if we only use 1 handler at a time, all requests would be
queued. (and the client is very sensitive about receiving the responses in
a specified time-window)

Our current setup is:
client is multi-threaded and at startup client will make curl-handlers
associated with mutexes (each curl-handler, 1 mutex).
The handlers are getting initialized with these options:
CURLOPT_TIMEOUT_MS = 3000
CURLOPT_TCP_KEEPALIVE = 1
CURLOPT_TCP_KEEPIDLE = 60
CURLOPT_TCP_KEEPINTVL = 30

Then threads will look into the list to find a curl-handler that its
mutex is not locked, and then use the free curl-handler to submit the
request (perform())
And finally when we're done with a handler, we'd "call curl_easy_reset".

CURLE_COULDNT_CONNECT means that the TCP handshake failed (connect() failure
> typically). It *usually* implies that the server didn't accept it, but it
> can
> also be due to resource problems client side. If you use a thousand handles
> within the same process, you can probably run into a too many open sockets
> problem.

Thanks for clarification,

Regards,
Hadi

On Mon, Sep 21, 2020 at 12:59 AM Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Sun, 20 Sep 2020, Hadi Rezaee via curl-library wrote:
>
> > Still we're not sure what is bottle-neck here. Is it client+libcurl or
> > webserver or even machine.
>
> There's just not enough details for us to tell.
>
> If you keep doing requests against the same machine very frequently, why
> does
> it create new connections at all, shouldn't they all reuse the connection?
>
> You say 700 requests per second, but why do you use one thousand handles
> for
> that? You should be able to use a single one.
>
> CURLE_COULDNT_CONNECT means that the TCP handshake failed (connect()
> failure
> typically). It *usually* implies that the server didn't accept it, but it
> can
> also be due to resource problems client side. If you use a thousand
> handles
> within the same process, you can probably run into a too many open sockets
> problem.
>
> --
>
> / daniel.haxx.se | Commercial curl support up to 24x7 is available!
> | Private help, bug fixes, support, ports, new features
> | https://www.wolfssl.com/contact/
>

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-09-21