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

Reuse buffers in bufio.Scanners #16

Closed
sinkingpoint opened this issue Jul 11, 2024 · 3 comments
Closed

Reuse buffers in bufio.Scanners #16

sinkingpoint opened this issue Jul 11, 2024 · 3 comments

Comments

@sinkingpoint
Copy link
Contributor

At the moment, every parser (one of which is constructed for each message), allocates a new buffer (https://github.com/leodido/go-syslog/blob/develop/octetcounting/scanner.go#L42). In high throughput scenarios, this can chew up a huge amount of CPU allocating memory to parse messages. I would like to propose that we create a new sync.Pool that stores bufio.Readers which https://github.com/leodido/go-syslog/blob/develop/octetcounting/scanner.go#L40 can pull from, rather than allocating a new buffer every time.

@sinkingpoint
Copy link
Contributor Author

As a demonstrative, we were chewing 70 cores using go-syslog through the OpenTelemetry Collector, which reduced to 3 when introducing a sync.Pool to store/reuse bufio.Readers

image

pprof:

image

@leodido
Copy link
Owner

leodido commented Sep 17, 2024

I love the analysis @sinkingpoint (ty!). Also, I like the idea of a pool for buffers.

Would love to get a PR and review it!

@sinkingpoint
Copy link
Contributor Author

Sure: #18

@leodido leodido closed this as completed Sep 18, 2024
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

No branches or pull requests

2 participants