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.

[HELP] What's the underlying connection reusing policy, can it be RR

From: 白水月 via curl-library <curl-library_at_lists.haxx.se>
Date: Wed, 19 Jan 2022 17:34:37 +0800 (CST)

Hi all,

I want to implement a http connection pool with libcurl. My design is something like this:
1. There are N (say 3) CURL handles in the pool, connecting to the same server(say 1.1.1.1 80) simutaneously. All curl handle is managed by a CURLM handle for I want to use async perfmorn.
2. At the very beginning, everything goes fine. The CURLM create 3 tcp connection to 1.1.1.1:80, each for one CURL handle.
3. The pool will send keepalive request periodically to the server(1.1.1.1:80) in case that the sever close the connection. But I cannot let all CURL handles to send keepalive request at the same time,
      otherwise cause a deny of service(no idle CURL handle to use), if happened to that the user(client which use the pool) need one CURL handle
4. As time pass by, some underlying TCP connection was close by the server. The periodic keepalive request fail to save the underlying TCP connection due to libcurl will reuse existing connection,
      which leads to one connection(in this case) never send keepalive request to server.


What I have tried:
1. I tried to bind the underlying curl_socket_t with a CURL handle(with CURLINFO_ACTIVESOCKET option), the it change then force CURL to create a new connection(with CURLOPT_FRESH_CONNECT),
but fail due to each time CURL may reuse to a different socket(corresponding to a different connection). It almost create a new connection all the time, making it meaningless as a pool.


2. I also try to record the ip addr of the closing connection(with CURLOPT_CLOSESOCKETFUNCTION), and then force a new connection when send a keepalive request. But It takes some
effort to mantains the information.


Another "easy" approach is if we can set the resuse policy of existing connections to Round Robin, it seems everything goes well.
But I fail to find out any stuff about the reusing policy. Is it possible to do this? And what's best practise for the scenario that I faced?






--
Best wishes!
--------------------------------------------------------------------------------------------------------
watermoon
Email: watermoon3322_at_163.com

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-01-19