Threads and Goroutines
Thanks for this article.<p>The article mentions Nodejs libuv which makes everything async but not multithreaded. I want to combine the benefits of kernel threads with coroutines or goroutines&#x2F;green threads&#x2F;lightweight threads. (If anybody knows anything specifically about fibers, I&#x27;d appreciate you telling me that because I&#x27;m not familiar with them.)<p>I have a lightweight thread scheduler <a href="https:&#x2F;&#x2F;github.com&#x2F;samsquire&#x2F;preemptible-thread">https:&#x2F;&#x2F;github.com&#x2F;samsquire&#x2F;preemptible-thread</a> which is a 1:M:N scheduler (1 scheduler thread, M kernel threads, N lightweight threads) with the lightweight threads being multiplexed on the kernel threads.<p>I am working on a multithreaded architecture which I currently call 3 tier multithreaded architecture for lack of a better name. It combines request parallelism with IO and CPU parallelism and intra request parallelism.<p>We split kernel threads into three groups: app threads, which run lightweight threads, IO threads (liburing&#x2F;epoll) and traditional CPU threadpool with work stealing.<p>* There should be low latency for handling IO because of the liburing or epoll loop is dedicated to serving that request and then dispatching it for CPU heavy task or app level task.<p>* The IO threads have buffers that other threads can write to to queue up data for sockets.<p>* The IO threads are basically listeners for IO events, they either spawn a lightweight thread for running on the app threads or submit a CPU task.<p>* The app threads coordinate parallelism WITHIN a request: they spawn CPU tasks and IO tasks.<p>* You can also spawn app threads to do work outside the context of a request, such as server tasks or schedule.<p>* You never put a while (true) in a CPU task and only use cooperatively preemptable loops in the lightweight app threads.<p>* The IO threads do very little work.<p>* Nobody should block the app threads because that would prevent other requests from completing.<p>* Lockfree Ringbuffers are used by CPU threads and lightweight threads to communicate.<p>I invite feedback and comments: <a href="https:&#x2F;&#x2F;github.com&#x2F;samsquire&#x2F;three-tier-multithreaded-architecture">https:&#x2F;&#x2F;github.com&#x2F;samsquire&#x2F;three-tier-multithreaded-archit...</a>