0

I am trying to understand the way Gevent/Greenlet chooses the next greenlet to be run. Threads use the OS Scheduler. Go Runtime uses 2 hierarchical queues.

By default, Gevent uses libevent to its plumbling. But how do libevent chooses the next greenlet to be ran, if many are ready to?

Is it random?

I already had read their docs and had a sight on the sourcecode. Still do not know.

Updated: Text changed to recognize that Gevent uses libevent. The question still applies over libevent.

alanjds
  • 3,972
  • 2
  • 35
  • 43
  • First of all note that greenlet itself does not 'choose' anything. Greenlet only provides a mechanism for one coroutine to yield to another. gevent is greenlet + libevent, and libevent provides the event loop. – jwg Sep 25 '17 at 07:44
  • 1
    So, an equivalent but more precise question would be: How do libevent chooses the next greenlet to be ran, if many are ready to, when used within Gevent? – alanjds Sep 28 '17 at 14:22
  • @alands, yes, I believe so. – jwg Sep 28 '17 at 14:48

1 Answers1

0

It's underlying dispatch model, is the event loop in libevent, which uses the event base, which monitors for the different events, and reacts to them accordiningly, then from what I gleamed , it will take the greenlets do some fuckery with semaphores, and then dispatch it onto libevent.

Sam Riyad
  • 41
  • 2
  • Welcome to StackOverflow! This adds some useful information, notably the presence of libevent, but I don't think it completely answers the question. – jwg Sep 25 '17 at 11:40