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

Avoid unnecessary event loop wakeups #9605

Merged
merged 1 commit into from
Oct 12, 2019

Commits on Oct 12, 2019

  1. Avoid unnecessary epoll event loop wake-ups

    Motivation
    
    The recently-introduced event loop scheduling hooks can be exploited by
    the epoll transport to avoid waking the event loop when scheduling
    future tasks if there is a timer already set to wake up sooner.
    
    There is also a "default" timeout which will wake the event
    loop after 1 second if there are no pending future tasks. The
    performance impact of these wakeups themselves is likely negligible but
    there's significant overhead in having to re-arm the timer every time
    the event loop goes to sleep (see netty#7816). It's not 100% clear why this
    timeout was there originally but we're sure it's no longer needed.
    
    Modification
    
    Combine the existing volatile wakenUp and non-volatile prevDeadlineNanos
    fields into a single AtomicLong that stores the next scheduled wakeup
    time while the event loop is in epoll_wait, and is -1 while it is awake.
    
    Use this as a guard to debounce wakeups from both immediate scheduled
    tasks and future scheduled tasks, the latter using the new
    before/afterScheduledTaskSubmitted overrides and based on whether the
    new deadline occurs prior to an already-scheduled timer.
    
    A similar optimization was already added to NioEventLoop, but it still
    uses two separate volatiles. We should consider similar streamlining of
    that in a future update.
    
    Result
    
    Fewer event loop wakeups when scheduling future tasks, greatly reduced
    overhead when no future tasks are scheduled.
    njhill committed Oct 12, 2019
    Configuration menu
    Copy the full SHA
    aac896d View commit details
    Browse the repository at this point in the history