Avoid use of global AtomicLong for ScheduledFutureTask ids#9599
Merged
normanmaurer merged 1 commit intonetty:4.1from Sep 25, 2019
Merged
Avoid use of global AtomicLong for ScheduledFutureTask ids#9599normanmaurer merged 1 commit intonetty:4.1from
normanmaurer merged 1 commit intonetty:4.1from
Conversation
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
|
Can one of the admins verify this patch? |
Member
|
@netty-bot test this please |
Member
|
@njhill good one! |
Member
|
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 |
Member
Author
|
@normanmaurer great idea re the label. One nit tho, wouldn't "forward-port" be more accurate? :) |
This was referenced Mar 9, 2021
Open
Open
Open
Closed
This was referenced Mar 18, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Currently the same static
AtomicLongis 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
static AtomicLong ScheduledFutureTask#nextTaskIdwith alongfield inAbstractScheduledExecutorServiceScheduledFutureTask#idbased on this when adding the task to the queue (in event loop) instead of at construction timeResult
Less contention / cache-miss possibility when scheduling future tasks
Before:
After: