-
Notifications
You must be signed in to change notification settings - Fork 10
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
ekump/APMSP-1805 lazily init cadence client #890
Conversation
7dbf470
to
0d252c6
Compare
use std::thread; | ||
|
||
#[tokio::test] | ||
async fn test_thread_safety() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how useful this test is? It is just checking that we don't set a client until after we send. I couldn't think of a better way to unit test this.
0d252c6
to
6714915
Compare
6714915
to
0f7acb1
Compare
BenchmarksComparisonBenchmark execution time: 2025-02-20 23:14:59 Comparing candidate commit 13124e6 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 51 metrics, 2 unstable metrics. scenario:benching deserializing traces from msgpack to their internal representation
CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
Group 13
BaselineOmitted due to size. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #890 +/- ##
==========================================
+ Coverage 71.75% 71.79% +0.03%
==========================================
Files 328 328
Lines 48514 48577 +63
==========================================
+ Hits 34813 34874 +61
- Misses 13701 13703 +2
|
/// Set the destination for dogstatsd metrics, if an API Key is provided the client is disabled | ||
/// as dogstatsd is not allowed in agentless mode. Returns an error if the provided endpoint | ||
/// is invalid. | ||
pub fn set_endpoint(&mut self, endpoint: Endpoint) -> anyhow::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function wasn't used anywhere else in libdatadog. I can leave it in as it is technically a breaking API change if we think the crate is being used outside of libdatadog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general, but I have a few questions.
4933211
to
c5bb7c9
Compare
APMSP-1805. Sidecar potentially has 100s of sessions, each of which creates dogstatsd clients. Defer initalizing new cadence clients until we are actually ready to send. Cadence creates a new OS thread every time a client is initialized.
c5bb7c9
to
61d2838
Compare
9d3ee1a
to
b37dc4e
Compare
b37dc4e
to
13124e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
DogStatsDAction::Set(metric, value, tags) => { | ||
do_send(client.set_with_tags(metric.as_ref(), value), tags) | ||
let client_opt = match self.get_or_init_client() { | ||
Ok(guard) => guard, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: variable name guard
is a bit confusing since it's the client option now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, forgot to update this variable. I'll make a note to update it in another PR.
What does this PR do?
Wait until send is called on dogstatsd client to initialize the cadence client.
Motivation
After this PR PHP customers in serverless environments started to experience an issue running out of file descriptors / threads. It is believed to be related to the creation of a new cadence client when initializing a new dogstatsd_client. This PR should re-establish previous behavior where the cadence client is lazily initialized when sending stats.
Additional Notes
We couldn't simply revert to using the previous code in the sidecar that lazily initialized the cadence client because the dogstatsd client is used in the Data Pipeline Trace Exporter inside async code and you can't just make the
send
method&mut self
to allow us to set the client. So we have to use interior mutability viaArc
andMutex
.How to test the change?
Unit tests added and existing ones continue to work. PHP team manually verified this resolves the thread count issue.