Hello,
I'm new to both asynchronous i/o and fibers. I'm trying to grok on a high-level how fiber scheduling works in vibe-d.
As I understand, Fibers in DLang must be called, and then somewhere within the Fiber it must yield or naturally end if it wants to relinquish control back to the caller. The idea is that a Fiber scheduler could take some aggregate of Fibers and run them in an efficient way.
I'm interested in studying vibe-d's approach to this fiber scheduling problem. However, I'm a bit hazy even after reading the source code – it seems to be above my head.
My understanding, which is most definitely flawed (feel free to correct!), is that
- There is a queue of
Fibers (or some derivative ofFibers) - If a
Fiberissues a vibesleep(), a driver timer (say libevent) is created, and during the sleep time, events are processed (the event loop goes through some iterations). When the timer goes off, theFiberis called again and resumes. Perhaps some other blocking operations are similar. - If a
Fiberyields or ends, events are processed and the nextFiberin the queue iscalled. If it was ayield, it is placed in the back of the queue. If it ended, it is removed from the queue. - Each Thread probably has its own
Fiberscheduler.
And some things I can't figure out:
- When and where are the new
Fibers added to theFiber'queue'? - Why is there so much timer code in the drivers? I can't think of much use except for making a timer for when
Fibers sleep. - Does each
Threadhave its ownFiberqueue so to speak? - How are
Fibers balanced betweenThreads when worker threads are enabled?
Now obviously I'm not looking for an exacting in-depth technical description, just a high-level description or psuedocode with the major points, because I feel like I'm really missing out on some fundamental understanding. I'm currently more interested in fiber scheduling because as it stands, I know I'm missing some significant chunks.
Regards,
Kelet