Groups | Blog | Home
all groups > dotnet clr > august 2004 >

dotnet clr : RE: Forcing a Large Object Heap allocation


Frank
8/1/2004 10:05:45 AM
Bruno,

I am working on an app that MUST be responsive at all times. Our application
has a very large managed memory footprint (> 1GB of small objects). We are
seeing that our app hangs for a couple of seconds when the garbage collector
compacts heap. Since our app must remain responsive we would rather take the
hit of allocating on the LOH and avoid the "compacting" phase all together.
The LOH has been described as being more similar to the C++ heap, which is
what we want. However, we want to try to avoid making calls into unmanaged
code for all our allocations and deallocations. Pinning many small objects
in the regular heap causes poorer performance than allocating many large
objects in the LOH.

Is there any way to avoid the ~2 second pause caused by the compacting
process?

Thanks,

Frank

[quoted text, click to view]

Bruno Jouhier [MVP]
8/1/2004 1:12:10 PM
I don't think that you have this level of control. I don't see any reason
why this would be useful either. The memory manager must be properly
encapsulated and should not expose this level of detail. Why do you need
this?

Bruno.

De: "Frank" <google@xemaps.com>
Objet: Forcing a Large Object Heap allocation
Date: Sunday, August 01, 2004 6:44 AM

Does anyone know if it is possible to force a small object to be allocated
on the Large Object Heap (LOH)?

Thanks,
Frank


Frank
8/1/2004 9:10:06 PM
Bruno,

Like you said, perhaps our app is not suitable for a managed environment.

I am assuming the LOH will become fragmented, whether you allocate large
objects or small objects (perhaps more quickly with small objects). But even
if we use an unmanaged environment (e.g., C++ heap) we would still have a
fragmentation problem. In other words, the C++ heap would fragment just as
easily as the C# LOH. So, if we are going to contend with fragmentation
anyway, may as well do it in C# where you also get the benefits of
generational garbage collection.

I think it would be a great feature if .NET would let you specify which heap
to allocate on. If that happened, the LOH should be called the
No-Compact-Heap. It would also be nice if you could specify/inject a custom
garbage collector for an AppDomain.

-Frank

[quoted text, click to view]

Bruno Jouhier [MVP]
8/1/2004 9:55:08 PM
The problem is that the LOH is not designed to handle lots of small objects.
So, you may run into more severe problems (like fragmentation problems) if
you use the LOH for your small object allocations. If the real time
constraints on your app are so severe that you cannot afford the compaction
phase, maybe this means that you app is not suitable for a managed
environment, or that you must manage your memory differently (like
allocating big arrays of structs instead of allocating objects
individually).

BTW our app also has a very large memory footprint (between 500MB and 1GB)
and we see the compaction hit, but we can live with it (this is a web
server, so the user can take a 1-2 second hit once in while (every 10
minutes or less often, depending on the load).

Bruno.


"Frank" <google@xemaps.com> a écrit dans le message de
news:10gq8o3kbhv6fb@corp.supernews.com...
[quoted text, click to view]

Chris Mullins
8/2/2004 9:54:26 AM
[quoted text, click to view]

What type of application are you building? Windows Service / WinForms /
ASP.NET ?

If you're a Windows Service, you might look into the "Server CLR" rather
than the "Workstation CLR". This will (in most cases) greatly improve your
garbage collection performance on multi-processor machines.

--
Chris Mullins

Niall
8/3/2004 12:42:32 PM
As Bruno says, you may have to look at things like pre-allocation. If you
know you will need a lot of instances of SmallObject, it may improve your
performance a lot to allocate roughly the required number at startup. Then,
instead of instantiating new objects when needed, you reuse the old ones. By
allocating at startup, you put the memory at the beginning of the heap, and
hence there is little chance it will have to move during a heap compaction.

Niall

[quoted text, click to view]

AddThis Social Bookmark Button