3 ms·
- Spawning a new thread for every request isn't good, you can reuse threads this causes a non-trivial Kernel load - The standard channel library isn't bad but
by valarauca1 9y ago
- Spawning a new thread for every request isn't good, you can reuse threads this causes a non-trivial Kernel load
- The standard channel library isn't bad but it's a far cry from great. You end up allocating every SEND. Which has its trade offs.
- You are doing a print in every thread which requires acquiring a global lock, and at least 2 system calls, and a global allocation.
- You aren't keeping your client/connection alive. So every new thread has to do a new 3 way handshake every request. 5 way if your is HTTPS.
- StreamBright 9y agoThank you, it would be useful to show how to this properly. Answers: - we are not spawning a thread for each request The following means we are creating N threads and execute a loop in every one of them, unless I misunderstand Rust entirely. for id in 0..NTHREADS { let thread_tx = tx.clone(); thread::spawn(move || { } .... - I am not sure what coould I do about the standard channel library - Doing a print at the very end once, the impact on performance is negligible - keep alive used to be broken with hyper and I am not only looking for keepalive but pipelinening as well. Let me know if you are aware of a HTTP client in Rust that can do both