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

Enhancement Request: Period flush or a function call to flush BufferedMetricSink #100

Closed
rohitjoshi opened this issue Aug 16, 2020 · 6 comments · Fixed by #101
Closed

Enhancement Request: Period flush or a function call to flush BufferedMetricSink #100

rohitjoshi opened this issue Aug 16, 2020 · 6 comments · Fixed by #101

Comments

@rohitjoshi
Copy link

Most of the application will have varying traffic and may be very lower and may not reach the buffer size. Is it possible to provide a flush() function so application can call it periodically?

@56quarters
Copy link
Owner

Hi @rohitjoshi ,
Sure, it's possible to add a flush method to the buffered sinks so that applications could periodically flush metrics. However, the buffer in the sink is only 512 bytes by default which ends up being about 10-20 metrics. If an your application isn't emitting enough metrics to fill the buffer, would the non-buffering UdpMetricSink be a better choice? Thanks!

@rohitjoshi
Copy link
Author

@56quarters Due to the peak throughput requirement (500K+), I have increased buffer to 8196 and would like to periodically flush when volume is too low.

@56quarters
Copy link
Owner

Got it, that makes sense. I think adding a .flush() method to the MetricSink trait makes sense in this case. Would that work for your usecase?

@rohitjoshi
Copy link
Author

👍 Thank you 🙏

56quarters added a commit that referenced this issue Aug 17, 2020
Allow applications to periodically flush any buffered metrics
before they would otherwise be flushed due to the buffer filling
up.

Fixes #100
56quarters added a commit that referenced this issue Aug 17, 2020
Allow applications to periodically flush any buffered metrics
before they would otherwise be flushed due to the buffer filling
up.

Fixes #100
@rohitjoshi
Copy link
Author

rohitjoshi commented Sep 25, 2020

Can you support .flush() method for StatsdClient object? I am creating StatsdClient from QueuingMetricSink where flush method not available.

let uds_sink = BufferedUnixMetricSink::with_capacity(uds_path, socket, buffer_size);
let queuing_sink = QueuingMetricSink::from(uds_sink);
let client = StatsdClient::from_sink(&conf.prefix, queuing_sink);

@56quarters
Copy link
Owner

56quarters commented Sep 25, 2020

I don't think it makes sense to add this very I/O focused method to the StatsdClient. You can solve this by keeping an Arc<dyn MetricSink + Send + Sync> around to the QueuingMetricSink in a another custom sink that wraps it and runs .flush() in a thread every N seconds or so.

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 a pull request may close this issue.

2 participants