[drafting] collector#collect performance improve - #782
Conversation
|
Hi, performance improvements are always welcome, thanks very much. However, in this specific case I'm not sure if we really have a problem with the current implementation. Each Sample will create a time series in the Prometheus server. So if you're saying you end up with millions of Sample instances, that would imply you are exporting millions of time series to your Prometheus server from a single application. I think this will make your Prometheus server run out-of-memory unless you put effort into scaling out your time series database. Moreover, Java is typically very good at collecting short-lived objects. And scraping is bound by the scrape interval, which will be in the order of magnitude of 15-30 seconds, i.e. this is not called very often. I'm wondering if there is actually a measurable difference when you manage to remove this single object creation. I would appreciate if you could provide some benchmark data showing that this actually solves a real-world problem. A benchmark would be good anyway, because with that we can compare the numbers before and after the change. |
|
This approach would most likely result in lower memory usage (related to the use of the |
In In this PR, the point is there are too much costs when collect metrics(parse |
|
Hi, you are absolutely right about the 5 threads. I just pushed a quick PR reducing the core thread pool size to 1 (#786). Thanks for bringing this up! For the other topic with the millions of |
Right, I'm trying to finish this PR and provide a simple test. It would take some time, I have to translate |
|
@tjiuming May I make a suggestion... Since it appears that you are trying to implement a visitor pattern... I would implement it as such. This would allow you to write/use a custom writer/formatter and may be a more palatable change. |
Thanks, I also considering that provide facade and data-structure is enough, developers could expose metrics data by their own way. |
|
Hi, just two quick remarks while you are looking into this:
One more remark: I saw that you are planning to introduce reflection and |
…v/collect_performance
|
@tjiuming you need to close one of the PRs. It's not clear which branch of code you are actually working with. |


currently, Prometheus is a very popular metrics system and has widely usages.
but there is a small problem: too many
Samplesobjects allocations whenCollector#collect, if we have 100k+ metrics in a system, there are millionsSamplesobjects will be generated when we collect them, it can become quite expensive in GC overhead.This PR is purposed to fix the problem: write
metrics stringintoWriterdirectly, withoutSamplesobjects allocations. It could reduce heap memory usages and GC pressure.This PR is in drafting, it will be finished after community approved.
Example: