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

Cleanup internal threading #144

Merged
merged 5 commits into from
May 28, 2021
Merged

Cleanup internal threading #144

merged 5 commits into from
May 28, 2021

Conversation

mcculls
Copy link
Contributor

@mcculls mcculls commented Apr 22, 2021

These changes cleanup and simplify the internal threading model so that the Java tracer can upgrade to the latest level of java-dogstatsd-client. It also adds support for using a custom thread factory which allows the Java tracer to configure StatsD threads so they are marked as agent related threads.

List of the changes:

  • Avoid creating intermediate NonBlockingStatsDClients via copy-constructors
    because each call to NonBlockingStatsDClient will end up spawning threads - instead we:

    • copy the current builder (to avoid side-effects)
    • resolve implicit elements
    • use the resolved builder to create the NonBlockingStatsDClient once
  • Remove unused copy-constructors

  • Remove intermediate thread pool, clean-up shutdown logic

  • Support using a custom thread factory to spawn StatsD worker threads

  • Replace fixed-size thread pools with a much simpler arrays of threads
    (since each StatsD worker is a busy loop that takes up exactly one thread)

mcculls and others added 5 commits April 22, 2021 14:29
…structor call will spawn several threads.

Instead we:
* copy the current builder (to avoid side-effects)
* resolve implicit elements
* use the resolved builder to create the NonBlockingStatsDClient
(since each StatsD task is a busy loop that takes up exactly one thread)
protected final CountDownLatch endSignal;

protected final int workers;
protected final ThreadFactory threadFactory;
protected final Thread[] workers;
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense to me given the way the workers are used.

@@ -49,7 +48,15 @@
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);

public abstract void run();
public final void run() {
Copy link
Member

Choose a reason for hiding this comment

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

Totally unrelated to this PR, but maybe we should add an exclusion for this type if we haven't done so already, just in case.

}
}

protected abstract void processLoop();
Copy link
Member

Choose a reason for hiding this comment

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

Given that the worker is being interrupted to halt the worker, should we not invert control so the loop handles the interrupts? What if the implementation of this method catches the interrupt and resets the interrupted status?

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, I'd like to refactor the worker loop further once this change is in (I'd prefer to keep that a separate PR though)

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

@mcculls thank you so much for doing this. I think I speak not just for myself but for the community when I say really appreciate the cleanup and saner threading model. There was quite a bit of tech-debt here, this is awesome! 👏 🙇

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Forgot to approve! 🚀

@mcculls mcculls merged commit b350b75 into master May 28, 2021
@mcculls mcculls deleted the mcculls/cleanupThreading branch May 28, 2021 20:25
@truthbk truthbk added this to the 2.13.0 milestone Jun 9, 2021
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