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

Improve performance of multithreaded operation in short running processes #475

Merged
merged 4 commits into from
Jul 11, 2018

Conversation

pawelchcki
Copy link
Contributor

@pawelchcki pawelchcki commented Jun 26, 2018

  • Avoid using mutex when Pids are the same, reduces lock contention improving throughput 2-3x in processes using more threads

  • For short running processes we were capped at the worker timeout which was 1s. With this change the worker is shut down immediately once data is flushed. Increasing throughput of applications like resque.

@pawelchcki pawelchcki changed the title Avoid using mutex when Pids are the same, reduces lock contention 2-3x Improve performance of multithreaded operation in short running processes Jun 26, 2018
@pawelchcki pawelchcki force-pushed the bugfix/writer_performance_improvements branch from 861d9ce to 3a6d12c Compare June 26, 2018 13:44
@pawelchcki pawelchcki added bug Involves a bug core Involves Datadog core libraries labels Jun 26, 2018
start()
if pid != @pid
@mutex_after_fork.synchronize do
if pid != @pid

Choose a reason for hiding this comment

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

You are comparing pid != @pid twice. Intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - the first comparison is done outside of the mutex to avoid locking as this check is only True once per the lifetime of the worker.

The second comparison is to make sure that other thread didn't already start the worker in between first check and locking of the mutex.

Copy link
Contributor

@delner delner Jun 26, 2018

Choose a reason for hiding this comment

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

If this is the case, I think it might be a good idea to add comments explaining this, at each line which it appears. As it's written, it's a bit unintuitive, so such an explanation would be really helpful.

I would also consider adding a link back to the issue, just so we know where this change originated from (so as to help some future version of ourselves understand this in the correct context.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah comment with explanation sounds like a good idea.

BTW @delner this could be done a bit cleaner with AtomicFixnum from concurrent-ruby but we would have to add it as a dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

My feelings are that it isn't worth adding a dependency for making things a bit cleaner, and that the tracing library should be as thin as reasonably possible.

@delner delner self-requested a review July 11, 2018 17:10
@pawelchcki pawelchcki force-pushed the bugfix/writer_performance_improvements branch from f9cb42a to 85d9300 Compare July 11, 2018 17:25
Copy link
Contributor

@delner delner left a comment

Choose a reason for hiding this comment

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

👍

@delner delner merged commit d9a1c16 into master Jul 11, 2018
@delner delner deleted the bugfix/writer_performance_improvements branch July 11, 2018 18:14
@delner delner added this to the 0.13.1 milestone Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants