ysbaddaden / execution_context

10 stars 2 forks source link

MT: M schedulers running on N threads [rough idea] #20

Open ysbaddaden opened 4 months ago

ysbaddaden commented 4 months ago

The MT context could have M schedulers running on N threads (where M < N), along with the ability to actively move a scheduler to another thread.

For example when the monitor thread notices that a fiber has been running for too long, it could detach the scheduler from the thread its running on (keeping the CPU-bound fiber running) and try to attach it to a sleeping thread, or add it to a list of pickable schedulers when all threads are busy.

When the fiber finally yields, the thread can try to reattach the scheduler it was previously running, or try to pick another one, or go to sleep.

ysbaddaden commented 1 month ago

We have a couple use cases where the ability to detach a scheduler from a thread would be useful:

straight-shoota commented 1 month ago

Why do we need to make IO blocking? I figure it could just stay async as it is, even keep attached to the event loop. But when a pinned fiber resumes, it can do so instantly (no enqueue) because it has its own thread just waiting for it.

ysbaddaden commented 1 month ago

Why bother with the evloop if we block the thread anyway? We can just do a blocking read/write syscall since we "own" the thread...

...because that would only work for the polling & libevent evloops, and IOCP for example doesn't allow to change the blocking state. Damn.