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

Memory Leak s3gof3r/pool.go #129

Open
fakarakas opened this issue Jan 9, 2018 · 6 comments
Open

Memory Leak s3gof3r/pool.go #129

fakarakas opened this issue Jan 9, 2018 · 6 comments

Comments

@fakarakas
Copy link

Hello,
I am currently writing a webservice to centralize the upload to S3 for different applications. This webservice is using s3gof3r for the upload and download.

I run some stress test with 20 concurrent uploads of 100 MB and i got a large memory usage.

The issue seems to come from pool.go, is there anyway to tweak the API for a less memory consumption ? Thanks

pprof output

Dropped 76 nodes (cum <= 0.01GB)
      flat  flat%   sum%        cum   cum%
    2.34GB 99.71% 99.71%     2.34GB 99.71%  s3proxy/vendor/github.com/rlmcpherson/s3gof3r.bufferPool.func1 /Users/fatih/go/src/s3proxy/vendor/github.com/rlmcpherson/s3gof3r/pool.go
ROUTINE ======================== s3proxy/vendor/github.com/rlmcpherson/s3gof3r.bufferPool.func1 in /Users/fatih/go/src/s3proxy/vendor/github.com/rlmcpherson/s3gof3r/pool.go
    2.34GB     2.34GB (flat, cum) 99.71% of Total
         .          .     30:	}
         .          .     31:	go func() {
         .          .     32:		q := new(list.List)
         .          .     33:		for {
         .          .     34:			if q.Len() == 0 {
    2.34GB     2.34GB     35:				q.PushFront(qb{when: time.Now(), s: make([]byte, bufsz)})
         .          .     36:				sp.makes++
         .          .     37:			}
         .          .     38:
         .          .     39:			e := q.Front()
         .          .     40:
@fakarakas
Copy link
Author

Anyway,
The problem was coming from our part when we were parsing the multipart form with the file.
To decrease the memory usage we tweaked this buffer :

	c.Request.ParseMultipartForm(2 << 20); // here 2MB, default is 32 MB in net.http

@abhimanyubabbar
Copy link

@fakarakas : Should you close this issue ?

@bcongdon
Copy link

For what it's worth, I'm experiencing this same issue

@blmoore
Copy link

blmoore commented Jul 30, 2019

I'm seeing this specifically when uploading a large number of small files (000s). Can reduce the impact by reducing concurrency + part size but still seeing memory use grow indefinitely

@MaerF0x0
Copy link

+1 Also seeing in our production code
Screen Shot 2019-08-29 at 2 45 55 PM

@kd7lxl
Copy link

kd7lxl commented Jul 21, 2021

We were seeing behavior matching all these symptoms, and it turned out there was a reader we forgot to call .Close() on. Anyone who is hitting this, look really closely to see if you are leaking unclosed readers or writers.

// Callers should call Close on r to ensure that all resources are released.

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

6 participants