This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
Pool tasks for sp_tasks::spawn
and add execution limits
#11227
Labels
I8-footprint
An enhancement to provide a smaller (system load, memory, network or disk) footprint.
J0-enhancement
An additional feature request.
Currently the way we implement the
sp_tasks::spawn
runtime API (which is roughly equivalent to astd::thread::spawn
, just called from within the runtime and without any shared memory between the caller and the callee) has a few problems from what I can see:spawn
instead ofspawn_blocking
yet it is blocking (it uses a blocking channel, and calling into the runtime is also effectively a blocking operation)It can deadlock the whole async loop when called enough times in parallel, or called enough times recursively.
Its docs also say that it's dangerous when used incorrectly.
(** - although due to it using
spawn
you'll probably exhaust all of the tokio worker threads and deadlock the whole process first)What we should do to fix this:
It would also be nice to add a hard-limit for the number of tasks which can be queued at the same time, but unfortunately that could be a source of non-determinism depending on how fast the already queued tasks are executed; we could however add a potential hard-limit to the total number of tasks.
Fortunately from what I can see no one currently really uses this API? (At least it isn't used in
polkadot
, if my grepping is correct; not sure about other chains though.)The text was updated successfully, but these errors were encountered: