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

Thread safety enhancements #111

Merged
merged 20 commits into from
Aug 25, 2022
Merged

Thread safety enhancements #111

merged 20 commits into from
Aug 25, 2022

Conversation

Stephen-Bao
Copy link
Contributor

This is the equivalent PR as #104, but pointing to the master branch.

To track conversation history, check #104.

Issue #, if available: #61

Description of changes: Added thread-safety enhancements, unit tests, and benchmarking code.
The benchmarking code measures the performance of the library under 3 diffrent internal synchronization situations:

  1. no internal sync for flush()
  2. using ReentrantReadWriteLock to make flush excute exclusively
  3. using Stamped to make flush excute exclusively

The main purposes of the benchmarking are:

  1. measure the extra overhead introduced by adding an extra lock on single-threaded users
  2. gather information to decide whether to provide a separate synced flush() while preserving the old one
  3. compare the performance of ReentrantReadWriteLock & StampedLock

Here are the benchmarking results:

  1. Single-threaded Use Cases

image

This proves that adding either lock would not cause an significant extra delay to single-threaded users.
  1. Single Method Performance in Async Context
    a. each thread publishes 1000 metrics

image

b. each thread flushes 100 times

image

These tests indicates that internal sync with a lock increases average ops time on single method, but overall ops time is still fast enough.
  1. Mixed Methods Performance in Async Context
    Each thread executing mixed metheds 100 times:

image

This illustrates the overall performance under different lock situations, especially the performance difference between the two locks.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Stephen-Bao Stephen-Bao changed the title Thread safety Thread safety enhancements Aug 19, 2022
@Stephen-Bao Stephen-Bao merged commit 237aa98 into master Aug 25, 2022
@markkuhn markkuhn mentioned this pull request Aug 25, 2022
@markkuhn markkuhn added the enhancement New feature or request label Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants