-
I understand that curl's multi interface executes all requests in a single thread. So even though Isahc's |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hmm, good question. It is true that curl is unable to take advantage of multiple cores, so it might be possible to squeeze more performance out by creating 1-2 clients per core. Though in practice I am not sure, it might be worth benchmarking the difference first. Note that a client uses things like connection pooling and HTTP/2 multiplexing to improve performance for multiple requests to the same destination, so it might be possible that under certain circumstances using a separate core reduces the CPU time, but increases the network time since there's less of the aformentioned optimizations taking place. |
Beta Was this translation helpful? Give feedback.
-
In an asynchronous crate like |
Beta Was this translation helpful? Give feedback.
-
While libcurl is Isahc's greatest strength, it is often its greatest weakness as well. Using a background thread was a compromise that seemed like the only way to interop with futures considering curl's multi interface without extereme hacks. The core problem is that a curl multi handle is essentially Now you could assign every request its own multi handle, allowing you to make incremental progress for each request separately (and could ultimately tie into something like a Tokio executor), you would have no sharing of resources between each request, and would lose connection pooling and reuse, DNS caching, etc. (It may be worth noting that this is how Isahc 0.1 worked.) Even so, you could still get these things back by sharing data between all the handles, but then you have to introduce mandatory mutexes for these things, which would be locked by any one request at any one time, potentially lowering the throughput that you sought to gain. A second, totally separate problem is that curl is incompatible with vanilla IOCP on Windows, which In other words, curl is currently incompatible with All this to say that, yeah, having a separate thread kinda sucks for some scenarios, but it's really the best option with respect to compatability, safety, and complexity. Really the only downsides are: (a) doesn't work on systems without thread support, and (b) can't parallelize any CPU-bound work that curl does. It might be worth looking at the |
Beta Was this translation helpful? Give feedback.
-
Closing this, as I think the question has been answered. Feel free to re-open if you have follow-up questions! |
Beta Was this translation helpful? Give feedback.
While libcurl is Isahc's greatest strength, it is often its greatest weakness as well. Using a background thread was a compromise that seemed like the only way to interop with futures considering curl's multi interface without extereme hacks.
The core problem is that a curl multi handle is essentially
!Send
. All easy handles attached to the multi handle must not be used except through the attached multi handle to drive the transfer. Sincecurl_multi_perform
does all the CPU work for all handles in one call, it isn't possible to parallelize this work across multiple threads, and it isn't possible to split each request into its own future that an executor canpoll
. Either all the requests m…