File reading: async / sync performance differences (hyper, tokio)

Yes. And yet, as I'm expecting downloads from slow clients, larger files also means more concurrent requests... for which async looked like the better match. Though these tests show that it probably does not matter much, as long as my site does not get slashdotted.

Thanks to you, and to tokio then! :slight_smile:

Sorry, I don't have the time for 5000 requests today, but here are 1000 (after increasing the nofile limit in /etc/security/limits.conf):

1000 simultaneous requests Peak RSS usage RSS usage afterwards Max. request time CPU time
Sync in channel 573 MB 24 MB 10:29 min 13:00 min
Async, codec::FramedRead 62 MB 46 MB 17:03 min 32:55 min
Async, own Stream 49 MB 38 MB 16:18 min 35:00 min

While the gap seems to be narrowing for the total request time, this is not the case for CPU time.
This is explained by the sync version only going to about 120% CPUs, whereas the async versions
use two full cores and more.

In my view, the "scalable" promise of async was always about having less than linear memory consumption: being able to serve more clients with the same amount of memory. CPU time is a different thing. Whether async uses less CPU time, that may depend about how the OS / the libraries actually implement threads, and how fast the two types of context switching are.