wiki:TaskScheduler

thread scheduling

the neuropil library uses coroutine inspired approach to schedule events (callback functions) and to execute work items.

the implementation in source:neuropil/include/np_jobqueue.h and source:neuropil/src/np_jobqueue.c uses the following set of components to fulfill its task:

  • a simple work queue is used to keep events in memory. events are added or inserted in priority order, a double timestamp (s.ms) is used as the sorting key.
  • a bunch of threads that compete for events in the work queue. If an event has been retrieved out of the queue, the exceution timestamp is checked. Only if the time to execute the task has been reached, the corresponding callback will be executed by the thread.
  • some mutex and conditions to prevent concurrent access to the work queue
  • a generic job argument structure to pass data to the events, or to retrieve error code of the executed callback functions.

events can be added to the work queue wit a delay at any time and are distinguished by their type:

regular events are sometimes self-repeating: after their execution they add themselves back to the work queue (also if an error during their execution occured). There should be no blocking thread in the neuropil library, because this would defeat the 'co-routine' approach.

I/O handling

neuropil uses the non-blocking libev library to perform any I/O related tasks. The corresponding libev calls are especially located in the network layer (source:neuropil/include/np_network.h) . The libev execution routine is triggered by a regular event (in source:neuropil/include/np_glia.h).

During the execution of the libev routines:

  • incoming msg events will be added to the work queue
  • outgoing msg events will be send to other nodes
  • the log file will be written
  • any user supplied I/O tasks will be executed
Last modified 3 years ago Last modified on 03/08/17 10:35:34