6 ms·
Threads are bad for highly concurrent systems that wants to run fast. Running 10000 threads will result in huge amounts of context-switching because it is the k
by kqueue 16y ago
Threads are bad for highly concurrent systems that wants to run fast. Running 10000 threads will result in huge amounts of context-switching because it is the kernel's job to schedule the threads and run them.
Now compare that to coroutines, where you can switch between 10000 threads in the userland.
If you want to take advantage of cores when using coroutine, then run several coroutine schedulers, each in a pthread, and let them communicate over local sockets.
- bad_user 16y agoWith coroutines multithreading is "cooperative". It's your job to release control to the run-loop. Doing it efficiently is an art and the OS is a lot more efficient than you, even with all the context switching. Going async is premature-optimization in my opinion, especially since with a Java server you can get to a couple thousands of synchronous requests/second easily. You also missed the point of the fucking article.
- kqueue 16y agoHmm, obviously you haven't written any serious http proxy/server that required to handle 10k+ of concurrent connections. Couple of thousands of sync connections is nothing in high performance servers. There isn't much scheduling about coroutines, you wake up the coroutine on the event that it slept on (read/write/sleep), that's it. If you want to prioritize, you can do so, but with minimal advantage. >Doing it efficiently is an art and the OS is a lot more efficient than you, even with all the context switching At this point, I am pretty sure you don't understand context-switching and its implications, and you don't know how coroutines work.