s3gof3r icon indicating copy to clipboard operation
s3gof3r copied to clipboard

Memory Leak s3gof3r/pool.go

Open fakarakas opened this issue 7 years ago • 6 comments

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 
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 avatar Jan 09 '18 09:01 fakarakas

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

fakarakas avatar Jan 12 '18 15:01 fakarakas

@fakarakas : Should you close this issue ?

abhimanyubabbar avatar Jan 23 '18 15:01 abhimanyubabbar

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

bcongdon avatar Apr 13 '18 16:04 bcongdon

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

blmoore avatar Jul 30 '19 13:07 blmoore

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

MaerF0x0 avatar Aug 29 '19 21:08 MaerF0x0

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.

https://github.com/rlmcpherson/s3gof3r/blob/864ae0bf7cf2e20c0002b7ea17f4d84fec1abc14/s3gof3r.go#L113

kd7lxl avatar Jul 21 '21 15:07 kd7lxl