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

Efficient Batch Observation Support for Native Histograms #1157

Open
callumdonald96 opened this issue Oct 16, 2024 · 3 comments
Open

Efficient Batch Observation Support for Native Histograms #1157

callumdonald96 opened this issue Oct 16, 2024 · 3 comments

Comments

@callumdonald96
Copy link

We have a use case where we need to record multiple observations of the same value in a Native Histogram.

Currently, this requires calling the observe method repeatedly in a loop:

for (int i=0; i<observations; i++) {
histogram.labelValues(labelValues).observe(value);
}

This approach becomes inefficient when dealing with a large number of observations.

To improve performance, it would be helpful to have a method that allows batching these observations into a single call.

We would like to introduce a new method that accepts the value to observe and the number of times it should be recorded:

histogram.labelValues(labelValues).observe(value, observations);

This method would internally update the histogram as if observation number of values have been observed, but without the overhead of multiple method calls.

@fstab
Copy link
Member

fstab commented Oct 17, 2024

Thanks for the issue.

If you are concerned about performance, try to look up the label values only once and then use the data point directly:

DistributionDataPoint dataPoint = histogram.labelValues("a", "b");
for (Double value : observations) {
    dataPoint.observe(value);
}

There's documentation on this here: https://prometheus.github.io/client_java/getting-started/performance/.

I don't think the observe() call has a measurable performance impact, I suspect it's the label value lookup.

@callumdonald96
Copy link
Author

callumdonald96 commented Oct 18, 2024 via email

@fstab
Copy link
Member

fstab commented Oct 28, 2024

A batch observe function that achieves this in constant time is a feature that would help us achieve the scale we require.
Is this possible with the way Native Histograms are implemented today?

I don't see a way to do this. I think insertion time will scale linearly with the number of observations, even if we implement a batch insert API.

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

No branches or pull requests

2 participants