performance of a lot of short-alive tasks #3749
Unanswered
wangjia184
asked this question in
Q&A
Replies: 1 comment 3 replies
-
It seems like all the tasks you spawn will wait on some previous oneshot, essentially making all the tasks run sequentially. It seems to me that you should be able to optimize this if you spawn a single task for handling all the operations. You could think of it as an actor and send it new tasks through an mpsc channel. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using tokio to spawn a lot of tasks(e.g. 30000 / second).
The tasks do not perform I/O operation nor blocking operation.
Each task
await
on aJoinHandle
of another task, or maybe aoneshot::Receiver
signaled by another task.When the waited
JoinHandle
oroneshot::Receiver
is signaled, the task handle the logic and then exits.The flame graph shows that a lot of time is spent on parking_lot stuff.
The full source code can be found here.
I am asking here if I can optimize the code somehow.
Is that normal
parking_lot
takes such a lot of time in flame graph?Would it be better if I avoid
spawn
so many tasks? e.g. usingFuturesUnordered
to watch on theoneshot::Receiver
, and having a fixed number of tasks executing the code in queue after they are signaled.Beta Was this translation helpful? Give feedback.
All reactions