google-api-go-client icon indicating copy to clipboard operation
google-api-go-client copied to clipboard

gensupport: Allow user to provide his own buffer used for uploading

Open zimnx opened this issue 4 years ago • 10 comments

When uploading lots of files using ObjectStorage.Insert(), each file allocates his own buffer. This results in increased CPU usage and high RSS memory.

WithBuffer allows user to provide his own buffer which will be used for streaming.

Graph below shows how many allocations were done during upload of ~30k of 10MB files: Selection_132 With this change, there're no allocations at all on library side (pool.New is code on caller side) Selection_135

zimnx avatar Aug 20 '20 15:08 zimnx

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Aug 20 '20 15:08 google-cla[bot]

@googlebot I signed it!

zimnx avatar Aug 20 '20 15:08 zimnx

@zimnx Can you please create an issue for this PR. We like to discuss features on issues before implementing them. Thanks!

codyoss avatar Aug 20 '20 17:08 codyoss

Added #638

zimnx avatar Aug 25 '20 08:08 zimnx

any chance to merge it soon? Other MediaOptions are not directly used in generated clients, there are only mentions about them in comments around Media function where they can be used.

zimnx avatar Aug 28 '20 08:08 zimnx

any chance to merge it soon? Other MediaOptions are not directly used in generated clients, there are only mentions about them in comments around Media function where they can be used.

Ahh I see I was mistaken about that-- so it will just be the manual client writer that will need to be updated for storage (and maybe bigquery).

I'm going to do a bit more discussion with my colleagues and let you know. You'd also definitely have to add a test for the new media option to https://github.com/googleapis/google-api-go-client/blob/326e17a21103f4ccf44ac1b40587ce7bcdd58b14/internal/gensupport/media_test.go#L150 (but no need to do that now, let me make sure I have approval on this direction first).

tritone avatar Aug 28 '20 14:08 tritone

Hi folks, any updates regarding merging this? :)

zimnx avatar Sep 14 '20 09:09 zimnx

@tritone @codyoss kind reminder

zimnx avatar Sep 28 '20 10:09 zimnx

👋 Regularly seeing high heap/allocations which this PR could help. Anything else needed to get this merged?

danp avatar Jan 30 '23 18:01 danp

If it helps anyone: we "fixed" this by setting ChunkSize=0 on all our Writers, which disables use of the buffer entirely. Since we do our own retries elsewhere that seems fine.

danp avatar Jun 12 '23 13:06 danp