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 use of global AtomicLong for ScheduledFutureTask ids #9599

Merged
merged 1 commit into from Sep 25, 2019

Conversation

njhill
Copy link
Member

@njhill njhill commented Sep 24, 2019

Motivation

Currently the same static AtomicLong is used to allocate a unique id whenever a task is scheduled to any event loop. This could be a source of contention if delayed tasks are scheduled at a high frequency and can be easily avoided by having a non-volatile id counter per queue.

Modifications

  • Replace static AtomicLong ScheduledFutureTask#nextTaskId with a long field in AbstractScheduledExecutorService
  • Set ScheduledFutureTask#id based on this when adding the task to the queue (in event loop) instead of at construction time
  • Add simple benchmark

Result

Less contention / cache-miss possibility when scheduling future tasks

Before:

Benchmark      (num)   Mode  Cnt    Score    Error  Units
scheduleLots  100000  thrpt   20  346.008 ± 21.931  ops/s

After:

Benchmark      (num)   Mode  Cnt    Score    Error  Units
scheduleLots  100000  thrpt   20  654.824 ± 22.064  ops/s

Motivation

Currently a static AtomicLong is used to allocate a unique id whenever a
task is scheduled to any event loop. This could be a source of
contention if delayed tasks are scheduled at a high frequency and can be
easily avoided by having a non-volatile id counter per queue.

Modifications

- Replace static AtomicLong ScheduledFutureTask#nextTaskId with a long
field in AbstractScheduledExecutorService
- Set ScheduledFutureTask#id based on this when adding the task to the
queue (in event loop) instead of at construction time
- Add simple benchmark

Result

Less contention / cache-miss possibility when scheduling future tasks

Before:

Benchmark      (num)   Mode  Cnt    Score    Error  Units
scheduleLots  100000  thrpt   20  346.008 ± 21.931  ops/s

Benchmark      (num)   Mode  Cnt    Score    Error  Units
scheduleLots  100000  thrpt   20  654.824 ± 22.064  ops/s
@netty-bot
Copy link

Can one of the admins verify this patch?

@normanmaurer
Copy link
Member

@netty-bot test this please

Copy link
Contributor

@franz1981 franz1981 left a comment

Choose a reason for hiding this comment

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

Good catch!!

@normanmaurer
Copy link
Member

@njhill good one!

@normanmaurer normanmaurer added this to the 4.1.42.Final milestone Sep 25, 2019
@normanmaurer normanmaurer merged commit 2791f0f into netty:4.1 Sep 25, 2019
@njhill njhill deleted the schedule-contention branch September 25, 2019 05:46
@normanmaurer
Copy link
Member

normanmaurer commented Sep 25, 2019

I need to think about how to port this to master in a safe way. For now I created a label "needs_backport" that we can use to mark PR's that need to be ported. Once done we should remove the label

@njhill
Copy link
Member Author

njhill commented Sep 25, 2019

@normanmaurer great idea re the label. One nit tho, wouldn't "forward-port" be more accurate? :)

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

Successfully merging this pull request may close these issues.

None yet

4 participants