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, Fiber
s in DLang must be call
ed, 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 Fiber
s 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
Fiber
s (or some derivative ofFiber
s) - If a
Fiber
issues 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, theFiber
is called again and resumes. Perhaps some other blocking operations are similar. - If a
Fiber
yields or ends, events are processed and the nextFiber
in the queue iscall
ed. 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
Fiber
scheduler.
And some things I can't figure out:
- When and where are the new
Fiber
s 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
Fiber
s sleep. - Does each
Thread
have its ownFiber
queue so to speak? - How are
Fiber
s balanced betweenThread
s 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