[19256] Remove mutex from TimedEventImpl#3745
Merged
MiguelCompany merged 2 commits intoeProsima:masterfrom Jul 27, 2023
cvilas:vilas/lockless_timedevent
Merged
[19256] Remove mutex from TimedEventImpl#3745MiguelCompany merged 2 commits intoeProsima:masterfrom cvilas:vilas/lockless_timedevent
MiguelCompany merged 2 commits intoeProsima:masterfrom
cvilas:vilas/lockless_timedevent
Conversation
Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com>
Member
|
@richiprosima Please test mac |
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
MiguelCompany
approved these changes
Jul 25, 2023
Member
MiguelCompany
left a comment
There was a problem hiding this comment.
Thank you @cvilas for such a well-crafted description.
I fully agree that using atomics here is better than a mutex, especially since next_trigger_time_ is always updated from the same thread.
I added a commit to please the linter, but other than that, the code changes look good.
Contributor
Author
Thanks @MiguelCompany. Credit goes to https://github.com/iamholger for identifying the issue and proposing a potential fix. I am just the messenger, as he is away from work at the moment. |
Member
|
@Mergifyio backport 2.11.x 2.10.x 2.6.x |
Contributor
✅ Backports have been createdDetails
|
Member
|
Thanks to @iamholger, then! Adding him as co-author on the merge commit! |
mergify bot
pushed a commit
that referenced
this pull request
Jul 27, 2023
* Removes mutex from TimedEventImpl Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> * Please linters. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Holger Schulz <holger.schulz@durham.ac.uk> (cherry picked from commit a7697c7)
mergify bot
pushed a commit
that referenced
this pull request
Jul 27, 2023
* Removes mutex from TimedEventImpl Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> * Please linters. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Holger Schulz <holger.schulz@durham.ac.uk> (cherry picked from commit a7697c7)
This was referenced Jul 27, 2023
mergify bot
pushed a commit
that referenced
this pull request
Jul 27, 2023
* Removes mutex from TimedEventImpl Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> * Please linters. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Holger Schulz <holger.schulz@durham.ac.uk> (cherry picked from commit a7697c7)
9 tasks
MiguelCompany
pushed a commit
that referenced
this pull request
Aug 1, 2023
* [19256] Remove mutex from TimedEventImpl (#3745) * Removes mutex from TimedEventImpl Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> * Please linters. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Holger Schulz <holger.schulz@durham.ac.uk> (cherry picked from commit a7697c7) * Added atomic time_point initialization (#3760) Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> --------- Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> Co-authored-by: Vilas Kumar Chitrakaran <cvilas@gmail.com> Co-authored-by: jsantiago-eProsima <90755661+jsantiago-eProsima@users.noreply.github.com>
MiguelCompany
pushed a commit
that referenced
this pull request
Aug 7, 2023
* [19256] Remove mutex from TimedEventImpl (#3745) * Removes mutex from TimedEventImpl Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> * Please linters. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Holger Schulz <holger.schulz@durham.ac.uk> (cherry picked from commit a7697c7) * Added atomic time_point initialization (#3760) Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> --------- Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> Co-authored-by: Vilas Kumar Chitrakaran <cvilas@gmail.com> Co-authored-by: jsantiago-eProsima <90755661+jsantiago-eProsima@users.noreply.github.com>
EduPonz
pushed a commit
that referenced
this pull request
Aug 10, 2023
* [19256] Remove mutex from TimedEventImpl (#3745) * Removes mutex from TimedEventImpl Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> * Please linters. Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> --------- Signed-off-by: Vilas Chitrakaran <cvilas@gmail.com> Signed-off-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Miguel Company <MiguelCompany@eprosima.com> Co-authored-by: Holger Schulz <holger.schulz@durham.ac.uk> (cherry picked from commit a7697c7) * Added atomic time_point initialization (#3760) Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> --------- Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> Co-authored-by: Vilas Kumar Chitrakaran <cvilas@gmail.com> Co-authored-by: jsantiago-eProsima <90755661+jsantiago-eProsima@users.noreply.github.com>
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.
Eliminates the overhead of mutex locking in a method in TimeEventImpl that is frequently called.
Description
While investigating scalability of discovery service on a large distributed system, hotspot analysis using Intel vtune showed that most time is spent with mutexes. Further analysis identifies a particular culprit whose removal increases the performance by 2x.
The following is from a machine with Haswell CPU running a SERVER participant. Evidently, 50% of the compute is spent locking and unlocking a mutex. The CPU consumption measured by top is of the order of 37%.
The performance analysis with vtune allows the construction of a so-called flamegraph that makes it very easy to understand the caller-callee relationship. The graph makes it very clear that the vast majority of the mutex locks and unlocks can be attributed to the function
eProsima::fastrtps::rtps::event_compare.Looking at the source code we can see that the mutex is locked and unlocked during a sort operation:
The mutex protects a couple of data members that can be wrapped in
std::atomicinstead. After eliminating the mutex, the flame graph becomesAt least in our use case, we are able to see an improvement in how well the discovery service scales without the lock.
Contributor Checklist
versions.mdfile (if applicable).Reviewer Checklist
@Mergifyio backport 2.11.x 2.10.x 2.6.x