Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async runtime consumes too much CPU while idle #2

Open
wonrax opened this issue Jul 6, 2024 · 1 comment
Open

async runtime consumes too much CPU while idle #2

wonrax opened this issue Jul 6, 2024 · 1 comment
Assignees

Comments

@wonrax
Copy link
Owner

wonrax commented Jul 6, 2024

// TODO since we're not using crossbeam channel's recv(), we don't get
// the benefit of yielding the thread when the channel is empty.
// Performance opportunities:
// - implement or use crossbeam's Backoff to yield the thread or spin
//   when the channel is empty
// - park the thread and use signal mechanism to wake up the thread when
//   there's a new task
@wonrax wonrax self-assigned this Jul 6, 2024
@wonrax wonrax changed the title [rust-experiments] async runtime consumes too much CPU while idle async runtime consumes too much CPU while idle Jul 6, 2024
@wonrax
Copy link
Owner Author

wonrax commented Jul 6, 2024

Looking through the Tokio codebase, it seems like the parking mechanism is actually implemented by the I/O driver or the timer driver. If neither driver is enabled, Tokio will fall back to parking the thread using a condition variable or thread parking.

If the I/O driver is enabled, it uses Linux's epoll syscall with a timeout parameter to park the thread until a point where a timer entry needs to be woken up (this is useful for our ongoing implementation of wheel timer). If there's a new task before the timer expires, Tokio will manually fire a fake (?) I/O event to make epoll return.

If the I/O driver is not enabled but the timer driver is, the timer driver will park the thread using a condition variable, similarly with a timeout of the duration until the next timer entry expires.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant