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

scraping: delay creating buffer, to save memory #12953

Merged
merged 1 commit into from Oct 9, 2023

Conversation

bboreham
Copy link
Member

@bboreham bboreham commented Oct 8, 2023

We don't need the buffer to read the response until the scrape http call returns; creating it earlier means we get a larger buffer pool.

I split the scrape() method into scrape() which returns with the http response, and readResponse() which decompresses and copies the data into the supplied buffer. This design was chosen to minimize impact on the logic.

Side-note: sync.Pool can still retain a lot more memory than we want it too, especially on many-core machines.
Reducing GOMAXPROCS down to Prometheus' typical usage can reduce this effect.

We don't need the buffer to read the response until the scrape http call
returns; creating it earlier makes the buffer pool larger.

I split `scrape()` into `scrape()` which returns with the http response,
and `readResponse()` which decompresses and copies the data into the
supplied buffer. This design was chosen to minimize impact on the logic.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@roidelapluie
Copy link
Member

LGTM

@bboreham bboreham merged commit f6d9c84 into prometheus:main Oct 9, 2023
24 checks passed
@bboreham bboreham deleted the delay-scrape-buffer branch October 9, 2023 16:23
LeviHarrison pushed a commit to LeviHarrison/prometheus that referenced this pull request Oct 15, 2023
We don't need the buffer to read the response until the scrape http call
returns; creating it earlier makes the buffer pool larger.

I split `scrape()` into `scrape()` which returns with the http response,
and `readResponse()` which decompresses and copies the data into the
supplied buffer. This design was chosen to minimize impact on the logic.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Levi Harrison <git@leviharrison.dev>
LeviHarrison pushed a commit to LeviHarrison/prometheus that referenced this pull request Oct 15, 2023
We don't need the buffer to read the response until the scrape http call
returns; creating it earlier makes the buffer pool larger.

I split `scrape()` into `scrape()` which returns with the http response,
and `readResponse()` which decompresses and copies the data into the
supplied buffer. This design was chosen to minimize impact on the logic.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Levi Harrison <git@leviharrison.dev>
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.

None yet

2 participants