Web server for serving static files

Hi its me again!
Im writing http sever for serving static files, for university task. I cant use libs that implements any part of http and multithreading. But server should be comparable by performace with nginx. How I undestand I cant use {std::mscp::Channel , Sender, Reciever}
But I writed two wesions of program:

  • First vesion: Threapool for handling connections

  • Second version: I’m using mio for non blocking io and threads that wraps event loop

But after running tests ab I found, that first version is faster than second and also more stable.
Second version blocks connections at the end ab testing.
Here is code of my first program: https://github.com/HustonMmmavr/hl_server/blob/master/src/server/server.rs
Code of second: https://github.com/HustonMmmavr/async_server/blob/master/src/server/server.rs
Also Here is ab results

For first version: ab -r -n 10000 -c 1000 localhost:5467/httptest/160313.jpg
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software: Mavri
Server Hostname: localhost
Server Port: 5467

Document Path: /httptest/160313.jpg
Document Length: 267037 bytes

Concurrency Level: 1000
Time taken for tests: 1.382 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2671810000 bytes
HTML transferred: 2670370000 bytes
Requests per second: 7237.89 [#/sec] (mean)
Time per request: 138.162 [ms] (mean)
Time per request: 0.138 [ms] (mean, across all concurrent requests)
Transfer rate: 1888501.43 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 80 273.8 0 1033
Processing: 2 51 45.4 35 310
Waiting: 1 40 50.7 26 310
Total: 12 131 302.3 37 1339

Percentage of the requests served within a certain time (ms)
50% 37
66% 41
75% 67
80% 74
90% 101
95% 1094
98% 1312
99% 1327
100% 1339 (longest request)

For second version: ab -r -n 10000 -c 500 localhost:5467/httptest/160313.jpg
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
apr_pollset_poll: The timeout specified has expired (70007)
Total of 9936 requests completed

I cant really understand why is it so, or what i’m doing wrong?
Can you help me?

I didn’t look too closely but I didn’t see where you handle edge triggering properly - you need to read/write from the socket until it gives you a WouldBlock error. Similarly, it seems like HttpClient::write assumes it’s able to write the entire buffer in one shot, but that may not be the case - if the socket doesn’t take the entire response, you need to keep the client registered for write and come back around to it when it’s ready again and pick up writing from where you left off. Similarly for reads until you get a valid frame (request).