Replies: 2 comments
-
Maybe we should do the execution of a new task a bit different. Instead of relying on signals, we might be better of doing some kind of other sleep mechanism: the parser will ask for a new task to be created, and will sleep until that task is done. Initial setup:
The biggest question would be how do we trigger tasks, and wait for certain conditions to arise. We could wake up tasks by signalling them to run for instance) |
Beta Was this translation helpful? Give feedback.
-
One way of figuring out if there is more data available in the network stack, is to have the loader always on runnable. So every loop it will be executed: it will quickly check if there is already more data available, and if not, it will yield. This is a bit of a polling situation.. but i'm not sure how we can make this a push (only set the task to runnable when there is data.. We could do this though by different threads. In that case, the loader will push more data over a channel and signals the parser task. The loader on the separate thread will do it's own loop (probably a select() call if that's available in rust). This means we don't need to poll so we don't waste any cycles on something that the OS can do better internally.. |
Beta Was this translation helpful? Give feedback.
-
i was thinking a bit about adding an event-loop in the system so we can be more flexible with the flow from http stream to screen paint.
I reckon there are eventloop based systems already available, but this would be my take on it. The flow is based on a regular OS scheduler system. There is a queue of work, where the scheduler takes the top of the queue. This is a record with a state and function call to what it should call. The eventloop would loop the tasks in the queue, and every task that is ready, will be executed. Scheduling is non-preemptive (cooperative). A process must yield the work in order for other tasks can run. Some tasks would need to wait upon other tasks (for instance, when we have javascript that we need to execute, the parser should halt, and signal the javascript to run (or basically, add a task to the queue?)
Once the javascript is completed, it will signal the parser to continue. The same setup also works when dealing with empty streams that are waiting for more packets to arrive.
The event loop tasks do NOT take into account any context. If there is context that needs to be saved between to runs of a task, it has to be saved within that task. For instance, the parser can be called from the scheduler. At certain points the parser yields the work, and later on the parser will be called again. It is the parser that should save the information where it was etc.. (basically, we are already doing this in the parser state).
This is the pseudocode:
A task would look like this:
Sending a signal allows for tasks to wake up other tasks when needed. This signal must be added to the task when registering:
This will create a task that will call the javascript executor when the task is running. It will start default in "sleep" mode (not running and skipped on each loop), until it receives a "exec_javascript" signal. At that point the sleep status will become "runnable" state and it will be picked up by the loop.
Beta Was this translation helpful? Give feedback.
All reactions