Repository navigation
Closed
Description
I did this
Trying to transfer 3 URLs like:
https://api.adsb.lol/api/0/route/SAS4133
https://api.adsb.lol/api/0/route/BBD6810
https://api.adsb.lol/api/0/route/THY19Y
to get Airplane flight-information (in series or parallel), causes curl to hang for a really long time between each URL.
But only when built with -DUSE_HYPER !? Entering the URLs either from a config-file or set on the command-line doesn't matter.
A simple get-urls.bat file to reproduce:
@echo off
setlocal
set CURL_SSL_BACKEND=schannel
echo url=https://api.adsb.lol/api/0/route/SAS4133 > %TEMP%\curl_urls.txt
echo url=https://api.adsb.lol/api/0/route/BBD6810 >> %TEMP%\curl_urls.txt
echo url=https://api.adsb.lol/api/0/route/THY19Y >> %TEMP%\curl_urls.txt
curl -s -K - < %TEMP%\curl_urls.txt | grep "_airport_codes_iata"Running the above .bat file takes at least 1 minute to complete! With --parallel or not.
I expected the following
The transfer to complete in < 1 sec. as the curl.exe bundled with Win-10 does:
timer & c:\windows\system32\curl.exe -s https://api.adsb.lol/api/0/route/SAS4133 https://api.adsb.lol/api/0/route/BBD6810 https://api.adsb.lol/api/0/route/THY19Y | grep "_airport_codes_iata" & timer
Timer 1 on: 9:42:26
"_airport_codes_iata": "CGN-BLL-KEF",
"_airport_codes_iata": "SFO-IST",
"_airport_codes_iata": "BGO-SVG",
Timer 1 off: 9:42:26 Elapsed: 0:00:00,45
c:\windows\system32\curl -V
curl 8.0.1 (Windows) libcurl/8.0.1 Schannel WinIDN
Release-Date: 2023-03-20
Adding the --parallel option I'd assume the URLs would be issued in parallel. Doesn't look so to me.
Version info:
curl -V
curl 8.2.0-DEV (x86_64-pc-win32) libcurl/8.2.0-DEV (OpenSSL/3.2.0) Schannel
(rustls-ffi/0.10.0/rustls/0.21.0) zlib/1.2.12 brotli/1.0.9 zstd/1.5.2 c-ares/1.19.0 libssh2/1.10.1_DEV Hyper/1.0.0-rc.3
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s scp sftp smb smbs smtp
smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL SSPI threadsafe
TLS-SRP UnixSockets zstd
I'm on Windows-10, 22H2 (OS-build 19045.2965).
Activity
gvanem commentedon May 26, 2023
After updating Rust with:
a
git pullof Hyper'smasterand rebuilding everything, this issue persists.bagder commentedon May 29, 2023
Reproduces for me as well on Linux.
icing commentedon May 30, 2023
Added some debug info's to this. I see that in
Curl_hyper_stream()which is called by curl's transfer loop:hyper_waker_wake(h->read_waker)is calledhyper_executor_poll(h->exec);givesHYPER_TASK_EMPTYCurl_hyper_stream()returnshyper_wake..., NO network IOhyper_executor_poll(h->exec);givesHYPER_TASK_RESPONSEthis explains the "slowness" of handling hyper transfers.
Experimentally, if I change step 5 to call
hyper_executor_poll(h->exec);a second time, directly after the EMPTY result, it deliversHYPER_TASK_RESPONSEand the transfers are fast.This seem to be y hyper internal synchronization issue that make IO result not available though they have been processed internally. Only when calling the hyper poll function again, the result is returned.
gvanem commentedon Jun 1, 2023
@icing
Hope someone (you?) is working on a fix. I'm clueless about such internal details.
icing commentedon Jun 1, 2023
@gvanem you are right. I wanted to document my observations to drag the hyper project in. I think this is a bug on their behalf, but if the insist everything is fine, we'll make a workaround in curl.
icing commentedon Jun 1, 2023
Opened hyperium/hyper#3237
bagder commentedon Jun 1, 2023
We also have #10803 as known bug now. It is a memory-leak with hyper as a backend.
Unslowing hyper
icing commentedon Jun 19, 2023
On advisement of @seanmonstar I made some small changes that resolve the slowness for me. Pr in #11344.
I see our http/1.1 test cases work, h2 has issues with connection reuse.
bagder commentedon Jun 20, 2023
Does not fix it for @gvanem apparently
34 remaining items
marlonbaeten commentedon Oct 23, 2023
@jsha nice work!
I think your summary is correct.
Together with @folkertdev I have tried several approaches in persisting both the
hyper_executerandhyper_clientconnbetween requests. However, I was not able to persist these without triggering memory issues, and concluded that it requires more in-depth knowledge to do this without introducing any bugs. So our tests might not be the correct starting point. Just to summarize:hyptransferin theCurl_easystruct and removing the places where (parts) are cleared [1] still does not prevent it from being cleared [2] - it seems thatCurl_openis called between requests which could cause this issue.hyper_clientconnpart of theconnectdataseems more appropriate and does help persisting the data, but triggers all kinds of memory issues that I was not able to debug.hyper_executershould not be part ofconnectdata, since there might be multiple connections and, I think, there should only be onehyper_executerI hope to try out your fix for hyper this week.
Good luck!
[1] #11203 (comment)
[2] #11203 (comment)
bagder commentedon Oct 23, 2023
Curl_easyis a handle for a single transfer ( but it can be reused) whileconnectdatais for a specific connection. A transfer can use one or more connections to perform a single transfer.Curl_open()creates a new easy handle (it is the internal version ofcurl_easy_init()) and a new transfer can reuse a connection that was previously used by another transfer if the conditions are right - or create a new one.I think the libcurl story is easy enough but I can't tell much about hyper and how we are supposed to work with it since the API is undocumented unless you can do the rust-to-C translation in your head. And it seems very few can.
jsha commentedon Oct 24, 2023
I've dug into this a little and feel like I made good progress, but I believe I'm running into an issue of conflicting lifecycles. If you want to view my branch-in-progress, very non-working, it's here: https://github.com/curl/curl/compare/master...jsha:curl:fix-hyper?expand=1
Here's the lifecycle issue. @bagder and @seanmonstar please correct me if I'm wrong about these assumptions.
Hyper has read and write callbacks. These get bundled into a
hyper_io *object, which gets bundled into ahyper_clientconn_handshake *, which eventually gets bundled into ahyper_clientconn *. Once they're in there, they can't be changed for the lifetime of thehyper_clientconn *, which is the lifetime of the TCP / TLS connection.Also bundled into the
hyper_clientconn *is avoid *userpto be passed to the read and write callbacks. It is set at creation time and never changed for the lifetime of the connection.Right now Curl sets the
void *userptoCurl_easy *data. That's handy for the callbacks (Curl_hyper_recvandCurl_hyper_send), because those delegate toCurl_read/Curl_write, which want aCurl_easy *. However, I think it's semantically wrong. ACurl_easy *represents a transfer, and one connection may serve many transfers during its lifetime.Really, I think the
void *userpshould be set to astruct connectdata *conn, since it has to be chosen once at the start of the connection and can never be changed.But that runs into a problem. The
connectdatahas fieldsrecvandsend, through which we should send all data. But they have a signature like this:curl/lib/urldata.h
Lines 145 to 158 in 31d96af
In other words, to do a read or write, we need to pass a valid
Curl_easy *. But if we make thehyper_clientconn *part of theconnectdatainstead of theCurl_easy, then it can never get a pointer to the currentCurl_easyin order to pass it torecv/send.Is there any object we can set as the
void *userpin ahyper_io */hyper_clientconn *that lives as long as the connection, and allows us to find aCurl_easy *when we need to send / receive? I've thought about adding a pointer fromconnectdatato the currently functioningCurl_easy *but I figure that must be wrong or it probably would already have been done for convenience in other areas. :Dbagder commentedon Oct 24, 2023
Great research @jsha
In curl a single connection might have many concurrent transfers (when multiplexed) so a connection cannot itself identify a single transfer - each connection has a list transfers. Also, every ongoing transfer has a single current connection it uses (at a time). An individual connection is used by none, one or many transfers.
Right. Because the connection can be used by up to several hundred concurrent transfers...
icing commentedon Oct 24, 2023
There are other places in curl with the same use pattern/problem. Callbacks in OpenSSL, nghttp2 and quiche.
The solution there, all of those being connection filters, is to either:
idfor the transfer (e.g. HTTP stream id) and look up the matching easy handle at the multi.Moving hyper from a http "protocol handler" replacement to a connection filter is not a small task. But it might be the better design.
jsha commentedon Oct 24, 2023
Great, thanks for the confirmation @bagder. And thanks for pointing a way forward @icing.
I think for the short term, we should disable HTTP/2 support in the Hyper integration, because it's broken (sends the connection preface on every request) and requires a rearchitecture to fix, which might take some time. The other alternative would be to have the HTTP/2 support send only a single request per connection. But it seems better to fall back to HTTP/1.1 where connections can be reused.
jsha commentedon Oct 24, 2023
I've posted #12191 with the quick / temporary fix of disabling HTTP2 with Hyper.
jsha commentedon Nov 19, 2023
I've posted hyperium/hyper#3424 adding documentation for Hyper's FFI API.
@bagder @icing would one of you be willing to add more detail to the connection filter docs and/or cfilters.h? I looked at docs/CONNECTION-FILTERS.md and I don't understand how the connection filter API handles multiplexing of multiple requests on a single connection. Also, the docs suggest that HTTP/2 might be a connection filter, which seems to be presently the case, so maybe it needs some updating? Thanks!
gvanem commentedon Nov 24, 2023
@jsha After getting the latest Hyper + curl from
git masterand rebuilding everything, the speed has improvedvery much.
The API at ADSB-LOL has changed into a new JSON-format. So with this .bat-file:
The timings are:
Much better; not >1 minute as before.
But the Win-10 bundled curl (w/o Hyper) is still ~5 times faster.
jsha commentedon Nov 27, 2023
@gvanem thanks for verifying that things got faster.
I'm not very surprised that the Hyper backend is still slightly slower than the nghttp2 (default) backend, because the hyper backend is now using HTTP/1.1. I'm guessing that curl serializes the requests when using HTTP/1.1 and parallelizes them when using HTTP/2.
I think the solution will be as @icing said: to rewrite the Hyper backend as a connection filter so we can restore HTTP/2 support with the Hyper backend and have it work properly.
gvanem commentedon Dec 2, 2023
Has this been done? Just rebuilt everything and now it's only 20% slower than the Win-10 bundled curl:
bagder commentedon Feb 10, 2024
This is mentioned in
KNOWN_BUGS.KNOWN_BUGS: hyper is slow
hyper: unslow