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

Implement ChannelMode and sampling rate for extended aggregation #187

Merged
merged 1 commit into from Apr 15, 2021

Conversation

hush-hush
Copy link
Member

When using extended aggregation we still want to respect sampling rate for histograms, distribution and timing as it will have direct consequences on the Agent (number of metrics to aggregate).

For app sending a very high number of metrics the aggregator implements ChannelMode to avoid lock contention when generating
andom numbers.

@hush-hush hush-hush force-pushed the maxime/add-channelmode-aggregator branch 2 times, most recently from 8c443d1 to f2fb331 Compare March 16, 2021 09:13
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.

Super clean, I really don't have much to say. Added a couple of comments regarding areas that may be a bit of a concern in terms of potential performance hurdles - difficult to overcome in any case - but that we could maybe look into.

Feel free to merge.

statsd/options.go Outdated Show resolved Hide resolved
}

func (bc *bufferedMetricContexts) sample(name string, value float64, tags []string, rate float64) error {
if !shouldSample(rate, bc.random, &bc.randomLock) {
Copy link
Member

Choose a reason for hiding this comment

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

I know there's no easy way around this, I'm a little concerned about all this locking here. We have one lock per metric type which is still a pretty coarse granularity. Can't really think of a good workaround.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true. Also it's the same overhead as the default configuration right now. When using the default setting (ie mutext mode), we have the same lock and random. So the overhead should be the same with and without extended aggregation.

@@ -11,59 +11,9 @@ type (
countsMap map[string]*countMetric
gaugesMap map[string]*gaugeMetric
setsMap map[string]*setMetric
bufferedMetricMap map[string]*histogramMetric
bufferedMetricMap map[string]*bufferedMetric
Copy link
Member

Choose a reason for hiding this comment

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

So, I'm wondering if we should consider sync.Map? It's not totally clear to me, but we might get better performance. On paper a sync.Map might offer better performance when used as follows:

(1) when the entry for a given key is only ever written once but read many times, as in caches that only grow,

(2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys.

I think we have a bit of (1) in that we create the context once and then sample over and over, but it might not fit the description fully. We don't have super high concurrency for (2), and the sets of keys would not be disjoint, so I'm not sure that apples. In any case, might be worth giving it thought to decide if we should keep the current implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a really good point. I'll do that in a different PR !

When using extended aggregation we still want to respect sampling rate
for histograms, distribution and timing as it will have direct
consequences on the Agent (number of point to aggregate).

For apps sending a high number of metrics the aggregator implements
ChannelMode to avoid lock contention when generating random numbers.
@hush-hush hush-hush force-pushed the maxime/add-channelmode-aggregator branch from e3cb1a4 to 358b394 Compare April 15, 2021 11:12
@hush-hush hush-hush merged commit d052db7 into master Apr 15, 2021
@hush-hush hush-hush deleted the maxime/add-channelmode-aggregator branch April 15, 2021 12:37
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.

None yet

2 participants