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
storage: NewWriter taking up too much memory #3903
Comments
Likely related to googleapis/google-api-go-client#638 |
Ah, definitely @codyoss. Looks like it's been open for quite awhile. Any updates on the situation? |
Hi @jherman , yes I need to circle back to that PR to allow buffer management by end users. However, you can already control how much memory is used for each Writer using Writer.ChunkSize. How large are the files you're uploading? Especially if you're uploading small files, you definitely want to set this to a smaller value. |
Hi @tritone, thanks for the tip. My files are only ~17KB. I'll read up on the ChunkSize. Can you recommend where to start? EDIT: OK, just realized this probably doesn't help me. Running the following line: wc := client.Bucket("my-bucket").Object("my-path").NewWriter(ctx) will immediately cause the memory allocation to go up, so specifying |
For the Go library specifically, we just have the docs for Writer that I linked to, plus cross-library documentation here which can give more intuition for how this is interpreted overall. For your use case, I would set Did you see experimentally that I'd try the following:
What does the allocation look like when you do this? |
@tritone, yes, it's NewWriter that is causing the allocation. Check out my sample above. I print out memory allocations before and after, only instantiating the NewWriter instance and immediately closing it (thinking closing would help but doesn't). I think you can directly copy & paste that code above, and run it and see this for yourself as well. Is this a bug? |
It would be-- let me verify that I can reproduce locally and report back. |
Yeah, so it's being allocated upon
Memory allocated:
|
Ah, that's excellent news @tritone. That helps tremendously, thank you! Also sorry about wasting your time on the reproduction - I could have sworn it was doing it after the instantiating. |
No worries, glad it helps! I'm going to close out this issue for now-- hopefully adjusting ChunkSize will be sufficient for your use case but we do still want to add the ability to implement buffer pooling as well (this becomes more important when managing workloads with larger objects). |
Client
Cloud Function
Environment
Cloud Function on GCP
Go Environment
$ go version
$ go env
Code
e.g.
OUTPUT:
Note that this code example is the sake of brevity.
Expected behavior
Free up memory after closing NewWriter instance
Actual behavior
Each NewWriter instance takes about 16-18MB
This problem is exacerbated when used in a Cloud Function. In my specific case, I have to write many files to storage, with each TextWriter taking up this much memory, the Cloud Function get's interrupted because memory is quickly exceeded. How does one reclaim the memory after closing a NewWriter?
The text was updated successfully, but these errors were encountered: