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

Optimize synchronized in PartitionedDispatcher #8640

Conversation

artembilan
Copy link
Member

Even if the PartitionedDispatcher.populatedPartitions() is fast, in-memory, non-blocking operation, its active call from the dispatch() on every message sent to the channel may pin the virtual thread.

  • Optimize the populatedPartitions() for double if where we will step into a synchronized block only for first several concurrent messages

Cherry-pick to 6.1.x

Even if the `PartitionedDispatcher.populatedPartitions()`
is fast, in-memory, non-blocking operation, its active call from the `dispatch()`
on every message sent to the channel may pin the virtual thread.

* Optimize the `populatedPartitions()` for double `if`
where we will step into a `synchronized` block only for first several concurrent messages

**Cherry-pick to `6.1.x`**
@artembilan artembilan force-pushed the PartitionedDispatcher_optimize_synchronized branch from c633d97 to f164fab Compare June 7, 2023 23:11
@@ -151,10 +151,16 @@ public boolean dispatch(Message<?> message) {
return partitionDispatcher.dispatch(message);
}

private synchronized void populatedPartitions() {
private void populatedPartitions() {
if (this.partitions.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You will probably need a // NOSONAR here (and other unsynchronized uses) to prevent Sonar from complaining.

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'm not sure how that suppose to complain since this property is final.
Plus our Sonar instance it out of order for a while.
I'd prefer to look into this when we come back into business with Sonar and it indeed will complain respectively.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think being final matters, I believe Sonar will report a smell for inconsistent synchronization of fields.

@garyrussell garyrussell merged commit 33f0b8e into spring-projects:main Jun 8, 2023
2 checks passed
garyrussell pushed a commit that referenced this pull request Jun 8, 2023
Even if the `PartitionedDispatcher.populatedPartitions()`
is fast, in-memory, non-blocking operation, its active call from the `dispatch()`
on every message sent to the channel may pin the virtual thread.

* Optimize the `populatedPartitions()` for double `if`
where we will step into a `synchronized` block only for first several concurrent messages

**Cherry-pick to `6.1.x`**
@garyrussell
Copy link
Contributor

...and cherry picked as 0350a64

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

2 participants