3 ms·
Loved the article =D These runtimes seems heavily scewed towards being used by IO bound application. While rayon can help with CPU bound tasks. I wonder if th
by kjuulh 3y ago
Loved the article =D
These runtimes seems heavily scewed towards being used by IO bound application.
While rayon can help with CPU bound tasks. I wonder if these mix at all, it may not be desired at all. But I think fairly interesting nonetheless.
I know that tokio doesn't like being blocked by anything. You will get a hard error, if you do a blocking operation when not being spawn_blocking via. tokio. Rayon, probably doesn't trigger this warning, as it is technically not doing any WouldBlock operations.
you would probably do a spawn_blocking for rayon as you would for IO bound operations.
Anyways, mixing CPU and IO bound operations on the same CPU/machine is probably the same as mixing oil and water, and would probably be a pain in the neck to maintain and get good utilization.
It is actually smack bang in the middle of the tokio docs.rs page: https://docs.rs/tokio/latest/tokio/index.html#cpu-bound-tasks-and-blocking-code https://docs.rs/tokio/latest/tokio/index.html#cpu-bound-task...
It is also a bit interesting how these paradigms compare with Golang green threads, which also seems to yield without a lot of syntactic sugar. The same for elixir. These languages also seem to solve the IO bound problem quite well using this paradigm (you obviously doesn't get as much control as you do for rust), but powerful nonetheless.
- skippyboxedhero 3y agoThe section just above the part you have linked also explains that tokio lets you pick the runtime scheduler - https://docs.rs/tokio/latest/tokio/runtime/index.html#runtime-configurations https://docs.rs/tokio/latest/tokio/runtime/index.html#runtim... - so you can run on single or multiple threads (the default is the latter with core and blocking threads as mentioned in the section you linked). I think you can mix them (or you can, as mentioned in the link, have a separate runtime for CPU-bound tasks) but it is probably easier to use Rayon.