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

**URL:** <https://users.rust-lang.org/t/file-reading-async-sync-performance-differences-hyper-tokio/34696>\
**Category:** help\
**Created:** [November 17, 2019, 2:01pm UTC](https://users.rust-lang.org/t/file-reading-async-sync-performance-differences-hyper-tokio/34696 "2019-11-17T14:01:36Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![viktor\_h](https://avatars.discourse-cdn.com/v4/letter/v/9dc877/32.png) [@viktor\_h](https://users.rust-lang.org/u/viktor_h)\
**Post date:** [November 19, 2019, 11:26pm UTC](https://users.rust-lang.org/t/file-reading-async-sync-performance-differences-hyper-tokio/34696/10 "2019-11-19T23:26:24Z")

</div>

> [@alice](#):
>
> The advantage of async code becomes much more pronounced if the tasks become smaller.

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.

> [@alice](#):
>
> In this case your executor is probably `tokio` , and that is where the round-robin serving happens.

Thanks to you, and to tokio then! 🙂

> [@Kruzer](#):
>
> If you can try, then try with 5,000 users, in that case async code is supposed to finish faster.

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.

---

_[View the full topic](https://users.rust-lang.org/t/file-reading-async-sync-performance-differences-hyper-tokio/34696)._
