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

Add a way to limit the number of samples we keep for buffered metrics #283

Merged

Conversation

iksaif
Copy link
Contributor

@iksaif iksaif commented Sep 27, 2023

Sampling rates are an inefficient mechanism to sample distributions because it requires the user to dynamically compute the sampling rate in order to effictively limit the load induced by distributions.

This adds WithMaxSamplesPerContext(int) which will limit the number of samples we keep per contexts to a fixed number that will be high enough to stay statisically relevant.

The sampling is done using using an algorithm called Vitter’s R), which randomly selects values with linearly-decreasing probability. This is a commonly used algorithm in instrumentation libraries (such as codahale). (see http://www.cs.umd.edu/~samir/498/vitter.pdf)

Additionally this fixes the computation of the rate for buffered metrics, this is important because it is forwarded to the agent and passed down to the sketches in order to make sure that we can still compute the count of events.

Here's the result on an application sending ~10 000 samples per second per distribution contexts

avg-cpu
Agent CPU

rate-bytes
dogstatsd Bytes/sec

The impact on the application itself:
appcpu

@iksaif iksaif marked this pull request as ready for review September 28, 2023 08:13
statsd/metrics.go Outdated Show resolved Hide resolved
statsd/metrics.go Outdated Show resolved Hide resolved
statsd/metrics.go Outdated Show resolved Hide resolved
statsd/aggregator.go Outdated Show resolved Hide resolved
statsd/aggregator.go Outdated Show resolved Hide resolved
statsd/options.go Show resolved Hide resolved
statsd/options.go Show resolved Hide resolved
statsd/metrics.go Outdated Show resolved Hide resolved
statsd/metrics.go Show resolved Hide resolved
statsd/worker.go Outdated Show resolved Hide resolved
statsd/buffered_metric_context.go Show resolved Hide resolved
@iksaif iksaif force-pushed the corentin.chary/max-samples-and-distrib-rates branch from 925f953 to 14adef5 Compare October 11, 2023 09:06
Sampling rates are an inefficient mechanism to sample distributions because
it requires the user to dynamically compute the sampling rate in order to effictively
limit the load induced by distributions.

This adds `WithMaxSamplesPerContext(int)` which will limit the number of samples
we keep per contexts to a fixed number that will be high enough to stay statisically
relevant.

The sampling is done using using an algorithm called Vitter’s R), which randomly selects values
with linearly-decreasing probability. This is a commonly used algorithm in instrumentation
libraries (such as codahale). (see http://www.cs.umd.edu/~samir/498/vitter.pdf)

Additionally this fixes the computation of the `rate` for buffered metrics, this is important
because it is forwarded to the agent and passed down to the sketches in order to make sure that
we can still compute the count of events.
@iksaif iksaif force-pushed the corentin.chary/max-samples-and-distrib-rates branch from 3a1df67 to 1ee2618 Compare October 12, 2023 12:57
@carlosroman carlosroman self-requested a review October 13, 2023 12:07
@remeh remeh merged commit aafbe8f into DataDog:master Oct 16, 2023
23 checks passed
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