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

perf: reduce allocs when rendering metrics #3214

Merged
merged 1 commit into from
Oct 17, 2024
Merged

perf: reduce allocs when rendering metrics #3214

merged 1 commit into from
Oct 17, 2024

Conversation

cgrinds
Copy link
Collaborator

@cgrinds cgrinds commented Oct 16, 2024

This PR reduces allocations by an order of magnitude through two optimizations:

  1. Avoiding slice reallocations
  2. Rendering metrics into a shared buffer

Scenario

  • Poll sar with single RestPerf volume collector
  • Changed collector.go to export each matrix 240 times
  • Take heap dump and report on alloc_space bytes for Prometheus.render

Results

Before change:
1.41 GB is alloced from render

After change:
124.64 MB is alloced from render

Thanks to ChrisGautcher for reporting

This PR reduces allocations by an order of magnitude through two optimizations:
1. Avoiding slice reallocations
2. Rendering metrics into a shared buffer

## Scenario

- Poll sar with single RestPerf volume collector
- Changed collector.go to export each matrix 240 times
- Take heap dump and report on `alloc_space` bytes for `Prometheus.render`

## Results

Before change:
1.41 GB is alloced from `render`

After change:
124.64 MB is alloced from `render`

Thanks to ChrisGautcher for reporting
@Hardikl Hardikl merged commit 60fa831 into main Oct 17, 2024
6 checks passed
@Hardikl Hardikl deleted the cbg-prom-perf branch October 17, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants