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

Use buffered writer #1241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

michaldo
Copy link

Without buffered reader, every single output character through given stack goes to "StreamEncoder public void write(int c)" and single element char array is created. It makes pressure to GC and CPU

In my case 800K char[1] arrays are created and garbage collected

BufferedReader reduce the pressure

write:130, StreamEncoder (sun.nio.cs)
write:201, OutputStreamWriter (java.io)
writeMetadata:338, PrometheusTextFormatWriter (io.prometheus.metrics.expositionformats) 
writeGauge:129, PrometheusTextFormatWriter (io.prometheus.metrics.expositionformats) 
write:68, PrometheusTextFormatWriter (io.prometheus.metrics.expositionformats) 
write:48, PrometheusOutputFormat$1 (org.springframework.boot.actuate.metrics.export.prometheus) 
scrape:87, PrometheusScrapeEndpoint (org.springframework.boot.actuate.metrics.export.prometheus)
StreamEncoder public void write(int c) throws IOException {
  char[] cbuf = new char[1];
  cbuf[0] = (char) c;

Without buffered reader, every single output character through given stack goes to "StreamEncoder public void write(int c)" and single element char array is created.
It makes pressure to GC and CPU
BufferedReader reduce the pressure

write:130, StreamEncoder (sun.nio.cs)
write:201, OutputStreamWriter (java.io)
writeMetadata:338, PrometheusTextFormatWriter (io.prometheus.metrics.expositionformats)
writeGauge:129, PrometheusTextFormatWriter (io.prometheus.metrics.expositionformats)
write:68, PrometheusTextFormatWriter (io.prometheus.metrics.expositionformats)
write:48, PrometheusOutputFormat$1 (org.springframework.boot.actuate.metrics.export.prometheus)
scrape:87, PrometheusScrapeEndpoint (org.springframework.boot.actuate.metrics.export.prometheus)

StreamEncoder public void write(int c) throws IOException {
  char[] cbuf = new char[1];
  cbuf[0] = (char) c;

Signed-off-by: Michal Domagala <michaldo@github.io>
@michaldo michaldo force-pushed the use-buffered-writer branch from b26dd34 to b9421b5 Compare December 22, 2024 18:41
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 this pull request may close these issues.

1 participant