question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Storage] LOH Allocation Uploading and Downloading

See original GitHub issue

Is your feature request related to a problem? Please describe.

Doing some scalabilty testing on our application, prefview reported high allocation to Large Object Heap stemming from UploadObjectAsync and DownloadObjectAsync APIs. Tracing this back to ResumableUpload.cs and MediaDownloader.cs .This seems due, in part, to default chunk size of 10 MB. A 10 MB byte array is allocated and used to chunk the stream.

I am able to lower the chunk size (and thus byte array size) for downloads low enough that allocations stay off the Large Object Heap. However, due to the limitation in minimum upload chunk size of 1024 * 256 bytes, I am unable to keep upload byte arrays off the LOH.

Describe the solution you’d like

It would be ideal to find a way to buffer the streams without excess memory allocations.

Perhaps it’s possible to reduce the allocations in .Net core environment by using ArrayPool<T> feature. This may require multi targeting.

Describe alternatives you’ve considered None

Additional context Testing done on:

  • OS: Windows Server 2016
  • .NET version: netcoreapp3.1
  • Package name and version: Google.Cloud.Storage.V1

Can provide prefview screen shots if desired.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
jskeetcommented, Mar 26, 2020

Right, this is now fixed in google-api-dotnet-client - but it won’t be available until we’ve done a new release of Google.Apis etc. We’ve got a new feature going in there soon, at which point we can release 1.45 of Google.Apis, and I can target that in a new beta of the storage library.

Sorry it’s taken so long to get to this, but I’m very pleased with the result - not only does it avoid allocating any large objects, but it also massively reduces the amount of allocation in general, when you’re uploading a large seekable stream or a small-but-not-seekable stream.

1reaction
jskeetcommented, Feb 13, 2020

Just to say, I’m afraid this is currently relatively low priority compared with the other things we’ve got going on at the moment. I haven’t forgotten about this, but I’m unlikely to get to it for a little while.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Dangers of the Large Object Heap - Simple Talk
When the LOH fills up and the program wants to allocate a new small block, .NET tries to re-use free space before it...
Read more >
c# - Large Arrays, and LOH Fragmentation. What is the ...
NET has to allocate more and more memory in order to place your large objects, i.e. the LOH gets fragmented. Now, having said...
Read more >
Large object heap (LOH) on Windows
This means the allocation cost of a large object is dominated by memory clearing (unless it triggers a GC). If it takes two...
Read more >
To Heap or not to Heap; That's the Large Object Question?
The first, ArrayNoLOH<T> , is backed by unmanaged memory (not LOH) that's allocated in its Constructor and released in its Dispose—like ...
Read more >
Memory Fragmentation, your worst nightmare
Memory fragmentation is when the sum of the available space in a memory heap is large enough to satisfy a memory allocation request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found