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

=str Make use of ConcurrentHashMap instead of List to reduce contention. #408

Merged
merged 1 commit into from
Aug 6, 2023

Conversation

He-Pin
Copy link
Member

@He-Pin He-Pin commented Jun 17, 2023

Was: akka/akka#31262
refs: akka/akka#29557

Use an ConcurrentMap as set to trace the contention in onFeedbackDispatched

@mdedetrich mdedetrich modified the milestones: 1.0.1, 1.1.0 Jun 17, 2023
@mdedetrich
Copy link
Contributor

Is it possible to provide jmh benchmarks to show the difference?

@He-Pin
Copy link
Member Author

He-Pin commented Jun 17, 2023

@mdedetrich I think this is a bug fix not a performance optimization, I can switch to ConcurrentHashMap i you like.

@pjfanning pjfanning changed the title =str Make use of TireMap instead of List to reduce contention. =str Make use of TrieMap instead of List to reduce contention. Jun 17, 2023
@mdedetrich
Copy link
Contributor

Ah I see, I will get @jrudolph to review this since he made the original issue.

@He-Pin He-Pin modified the milestones: 1.1.0, 1.0.1 Jul 17, 2023
@pjfanning pjfanning modified the milestones: 1.0.1, 1.0.x Jul 17, 2023
@pjfanning pjfanning modified the milestones: 1.0.x, 1.1.0 Jul 31, 2023
@He-Pin
Copy link
Member Author

He-Pin commented Aug 6, 2023

After read the paper of TrieMap, I think I need to change it back to ConcurrentHashMap.

However, we should point out that
the nonblocking hash table does not perform compression – once
the underlying table is resized to a certain size, the memory is
used regardless of whether the elements are removed. This can be
a problem for long running applications and applications using a
greater number of concurrent data structures

@He-Pin He-Pin changed the title =str Make use of TrieMap instead of List to reduce contention. =str Make use of ConucrrentHashMap instead of List to reduce contention. Aug 6, 2023
Copy link
Contributor

@mdedetrich mdedetrich left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

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

I'm a bit confused as to the use of AtomicReference[mutable.Map] instead of just plain mutable.Map.

@He-Pin He-Pin requested a review from pjfanning August 6, 2023 10:19
@pjfanning pjfanning changed the title =str Make use of ConucrrentHashMap instead of List to reduce contention. =str Make use of ConcurrentHashMap instead of List to reduce contention. Aug 6, 2023
Signed-off-by: He-Pin <hepin1989@gmail.com>
Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

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

lgtm

@He-Pin He-Pin merged commit 464517a into apache:main Aug 6, 2023
17 checks passed
@jrudolph
Copy link
Contributor

Yes, this was originally a performance improvement. Regardless of that fact, let's not just merge changes in performance critical code without running benchmarks or discussing arguments why they can be omitted.

It has been a long time since I worked on this / proposed the change (almost 3 years... oh my). I guess in this case, it's fine, it seems after all they ran some benchmarks in Akka to validate it does not introduce obvious performance regressions.

I'm a bit confused as to the use of AtomicReference[mutable.Map] instead of just plain mutable.Map.

The comment at its declaration explains it. There's a race condition between scheduling an async callback (i.e. an incoming external event into the stream) and shutting down a stream. The atomic reference makes sure, that we will report feedback to the async callback reliably even if it raced against shutdown (this is basically what this whole feature is about).

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.

4 participants