Based on the fact that node uses a single thread to manage everything, I am curious how I should go about handling a low-priority job
This job is constantly running and analyzing data (let's say it is a setTimeout
), but what it does takes a lot of time, and I want it to have a really low priority in the scheduler.
I don't think I can run it in a separate process, because I need to modify its working instructions really often (it works using the variables of my main process, so it needs to be able to access them constantly).
You can imagine this as a big stack of tasks, that it will constantly work on, but the working set for these tasks is controlled by the main process.
- A separate process would need constant requests between the two to exchange data, so that seems like a bad idea
- A separate thread, like a web worker, may be faster at that? I don't know if node supports them though
- The best thing would be for it to be a simple event function running on a timer, which respects the principles of node, but I need to somehow tell the scheduler to spend less time on this function than on the rest of the program. Is there any way of doing it?