a very occasional diary

nondescript
[Nikita Danilov]

2022-10-12

usched: update


usched: update

Update for the previous post about stackswap coroutine implementation usched.

To recap, usched is an experimental (and very simple, 120LOC) coroutine implementation different from stackful and stackless models: coroutines are executed on the native stack of the caller and when the coroutine is about to block its stack is copied into a separately allocated (e.g., in the heap) buffer. The buffer is copied back onto the native stack when the coroutine is ready to resume.

I added a new scheduler ll.c that distributes coroutines across multiple native threads and then does lockless scheduling within each thread. In the benchmark (the same as in the previous post), each coroutine in the communicating cycle belongs to the same thread.

Results are amazing: usched actually beats compiler-assisted C++ coroutines by a large margin. The horizontal axis is the number of coroutines in the test (logarithmic) and the vertical axis is coroutine wakeup-wait operations per second (1 == 1e8 op/sec).

16 32 64 400 800 4000 8000 40000 80000 400000 800000 4000000 8000000
GO 0.0773 0.1278 0.1995 0.3260 0.3230 0.2858 0.2286 0.1427 0.1993 0.3054 0.3033 0.2866 0.2680
C++ 1.0894 1.2349 1.3448 1.2624 1.2017 1.1595 1.1417 1.1352 1.1635 1.1687 1.1387 1.0762 1.0519
UL 0.5606 0.9557 1.5157 2.0474 2.0954 2.1277 2.1484 2.1606 2.1544 2.0200 1.9326 1.8196 1.8116

I only kept the most efficient implementation from every competing class: C++ for stackless, GO for stackful and usched for stackswap. See the full results in results.darwin

No comments:

Post a Comment