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

Use fast thread local and fix GC nepotism (Fixes #4749) #4750

Merged
merged 2 commits into from
Jun 23, 2023

Conversation

franz1981
Copy link
Contributor

Thanks to make the list single linked, fixing GC nepotism is now simpler, but this has forced to remove pollAndExecute
because we need 2 state variables to hold the current head/tail of the task list.

For this same reason, we are forced to define an additional InProgressHead class to keep up to date the current head in order to allow reentrant tasks to keep on being added to the current one.

@franz1981
Copy link
Contributor Author

mmm looking to the failures I see that probably I'm changing the expected order of execution of tasks, because the reentrant ones are added to be executed next, given them more priority.
I see what going on

@franz1981
Copy link
Contributor Author

I've fixed the ordering issue: now the tasks are always added in FIFO order

@vietj vietj added this to the 5.0.0 milestone Jun 21, 2023
Task task;
}

private final FastThreadLocal<InProgressTail> current = new FastThreadLocal<>();
Copy link
Member

Choose a reason for hiding this comment

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

note this will be a problem when we will use Netty 5 and Netty 4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be something to be review, but won't break, because it is still backed by JDK thread local in case the executing thread isn't a fast thread local.

Copy link
Member

Choose a reason for hiding this comment

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

my point is that, this will not be the same Java class in Netty 4 / Netty 5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's a good point indeed...I have a solution that doesn't use any thread locals, but it would complicate a lot the code there, really

Copy link
Member

Choose a reason for hiding this comment

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

yeah but we would need that eventually I think, so perhaps it is best avoiding thread local if we can now that we have the time to do it ?

Copy link
Contributor Author

@franz1981 franz1981 Jun 22, 2023

Choose a reason for hiding this comment

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

I can prepare the a different branch with another version but will use atomic queues to achieve the same, probably with worse performance.
Another version could change a lot the API and pass a queue of existing post actions to let the actions to enqueue themselves but it will super invasive and complex imo.
In the current form this one already deliver what we need Ie avoid ThreadLocal::remove and GC nepotism, so I would prefer to do it in 2 separate steps.
This code is already complex as it is, and bringing more complexity is something that should be weighted with the benefits.

Copy link
Member

Choose a reason for hiding this comment

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

fine

@@ -12,9 +12,29 @@

public abstract class Task {
Copy link
Member

Choose a reason for hiding this comment

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

no need to make this class public

@franz1981
Copy link
Contributor Author

What this pr deliver is to imply that in flight post actions would be queued in FIFO ordering and run when all the existing ones complete, which include additional post actions that can be generated by them.
@vietj any idea if it is what user can expect if compared to the original logic

@vietj
Copy link
Member

vietj commented Jun 22, 2023

it does not seem to be an issue to me, to delay all post actions until all actions are executed, perhaps this could work better combined with a max number of actions to execute that we have in another PR ? so we guarantee time execute post actions in a timely manner ?

@vietj vietj merged commit 99bc0da into eclipse-vertx:master Jun 23, 2023
7 checks passed
@vietj
Copy link
Member

vietj commented Jun 23, 2023

can you backport the PR to 4.x ?

franz1981 added a commit to franz1981/vert.x that referenced this pull request Jun 23, 2023
…clipse-vertx#4750)

* Use fast thread local and fix GC nepotism (Fixes eclipse-vertx#4749)
* Replace order of reentrant task's merge
vietj pushed a commit that referenced this pull request Jun 27, 2023
* Use fast thread local and fix GC nepotism (Fixes #4749)
* Replace order of reentrant task's merge
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.

None yet

2 participants