We build async http solution on Actix based on Rust. We spawn two task:
- Parsing blockchain blocks. This task not consumed much resources cause between blocks enough time for process. This task creates micro task, like "query data", "parse data", "save data".
- Review already loaded blocks. This task we run time to time, like once a week, but this task create a high load.
When second task runs it looks like eager, and became block the executing some of small task from 1. If I stopped 2 task, all task from first correctly finished.
The question: how I can temporary stop or pause executing second task for give other small task to be finished?
Asynchronous tasks are cooperative multitasking, that means your second task has to
.awaitsomething in it's body, you cannot make it stop or pause from the outside.CPU bound tasks are not meant to be run in asynchronous tasks anyways, so your best bet is to not put the review task in a task to begin with.
There is a dedicated section on the topic of CPU bound tasks in the
tokiodocumentation, it suggests: