Skip to content

Reduce unnecessary poll wakeups#314

Merged
carllerche merged 1 commit intomasterfrom
reduce-unnecessary-wakups
Dec 4, 2015
Merged

Reduce unnecessary poll wakeups#314
carllerche merged 1 commit intomasterfrom
reduce-unnecessary-wakups

Conversation

@carllerche
Copy link
Member

Based on #280 by luca-barbieri

Currently run() results in the process waking up every second or every timer
tick if set lower because a timeout is passed to the OS wait function.

This changes the code so that run_once() still uses the timeout, but
run() will instruct the OS to wait forever when there are no timers.

The notify mechanism already uses a pipe for awakening the event loop,
so there should be no need to use a timeout for that.

This saves CPU time and battery, and is generally the correct behavior.

Miscellaneous notes:

Closes #289

@alexcrichton
Copy link
Contributor

Nice! 💴

Based on #280 by luca-barbieri

Currently run() results in the process waking up every second or every timer
tick if set lower because a timeout is passed to the OS wait function.

This changes the code so that run_once() still uses the timeout, but
run() will instruct the OS to wait forever when there are no timers.

The notify mechanism already uses a pipe for awakening the event loop,
so there should be no need to use a timeout for that.

This saves CPU time and battery, and is generally the correct behavior.

Miscellaneous notes:

 * We also fix epoll because the maximum timeout supported by the Linux kernel is
   i32::MAX, not isize::MAX.
 * We fix next_tick_ms() being truncated from u64 to usize
 * It requires nix-rust/nix#192 to allow specifying no timeout to kevent()
 * The public API of Poll::poll is changed, but that can be avoided if desired.

Closes #289
@carllerche carllerche force-pushed the reduce-unnecessary-wakups branch from b6f6b23 to 7b73ce8 Compare December 3, 2015 20:38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since std::time::Duration is stable, is there a reason not to use it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will track this in the API ticket. To date Mio has used *_ms

@carllerche carllerche merged commit 7b73ce8 into master Dec 4, 2015
@carllerche carllerche deleted the reduce-unnecessary-wakups branch December 4, 2015 04:14
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

Successfully merging this pull request may close these issues.

Unnecessary polling

3 participants