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

BufferPool leads to wasted memory #85

Closed
nsmith5 opened this issue Apr 13, 2021 · 3 comments
Closed

BufferPool leads to wasted memory #85

nsmith5 opened this issue Apr 13, 2021 · 3 comments

Comments

@nsmith5
Copy link
Contributor

nsmith5 commented Apr 13, 2021

Problem

The current buffer pool appears to buffer writes for HTML templating. While the buffers are Reset upon resubmission to the pool, this doesn't free the underlying memory. The result in a long running web server is that the buffer pool contains ~64 * the largest template rendered.

This size can get unreasonable in applications like Gitea where some pages might contain sizable assets like pictures. My heap profiles show something like 500MiB of heap space just because of this.

Possible solutions

This buffer pool probably isn't needed at all. Simply push the concern of write buffering to the calling library. In fact, the most likely writer to be used with this library already buffers writes: http.ResponseWriter.

If a buffer pool is really needed, perhaps use something like this sized buffer pool that trims down buffers that grow past a certain size so that the pool can't grow unchecked.

@unrolled
Copy link
Owner

@nsmith5 I just merged your PR and rolled a release (v1.1.0). Do you want to try it out in production for a while before closing this issue?

@nsmith5
Copy link
Contributor Author

nsmith5 commented Apr 21, 2021

Sweet! Yeah, I'll try this out in my Gitea install and report on results

@nsmith5
Copy link
Contributor Author

nsmith5 commented Apr 22, 2021

Memory footprint drops as expected. This was merged into Gitea downstream here go-gitea/gitea#15581

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 a pull request may close this issue.

2 participants