The last thing that I think may be the source of performance problem is the size of the buffer. But after some tests, it seems that 1<<22 is a good size on my machine. I don’t know which one is use one the other solution.

const BUF_SIZE : usize = 1<<22;

How can I improve that code ? I’m pretty sure, I can do better with Rust.

To benchmark the solution, I simply download a file to /dev/null with wget "http://localhost:1337" -0 /dev/null. The file is about 7Gio big.

I’m now pretty sure that the problem is how I read the file. I would like to confirm or deny it using a profiler but I’m new to Rust so it seems a bit complicated. Like every little thing actually. ¯\_(ツ)_/¯

Each time the Stream need a chunk, I read it. But, I shouldn’t wait to need a chunk to start reading the next one.

From my test can read a file @425MB/s and the speed of the network is virtually @600MB/s (on the loopback interface I mean). I should be able to send a file at about 400MB/s.