views:

1028

answers:

4

Environment: Windows 2003 Server (32 bit); IIS6, ASP.NET 2.0 (3.5); 4Gb Ram; 1 Worker Process

We have a situation where we have a very large System.XmlDocument is being loaded into memory, and then it heads into a complied XSL transform. What is happening is when a web request comes in the server is sitting in an idle state with 2500Mb of available system memory.

As the XML DOM is populated, the available memory drops approx 500Mb at which point we get a System.OutOfMemoryException event. At this point the system should theoretically still have 2000Mb of available memory available to service the request (according to Perfmon).

The related questions I have are:

1) At what level in the stack is this out of memory limitation being met? OS? IIS? ASP.NET? worker process? Is this a per individual web request limit?

2) Is this limit configurable somewhere?

3) Why can’t this web request access the full available system memory?

A: 

I'm sure there are some bright heads here that can answer your specific questions, but have you asked yourself if there is another way to do what you want? I specifically mean that you probably do not want to process a very large XML document, but you probably more specifically want to return something back to the client. Could you rewrite the code to avoid this XML document altogether, or perhaps not load it all into memory at the same time, and still produce the same end-result?

Lasse V. Karlsen
Yes, I am aware of many better ways to achieve the same results using more efficient architectures.However, this is legacy transform with very complex business rules costing 100’s of man days to re-engineer.It makes more sense to configure our servers to handle this request (if possible).
nick_alot
A: 

1) Dunno. Check your logs.
2) IIS limits memory divvied out to websites/application pools. Check your settings.
3) Servers are all about uptime; if an single app hogs all the resources everybody else suffers. Thats why enterprise apps like IIS limit memory to prevent runaways from taking down the entire server.

Will
It is the CLR running within ASP.NET that is raising System.OutOfMemoryException. My own knowledge and research does not necessarily tell me where is the stack below IIS such a limitation is being hit? Maybe somebody else knows?
nick_alot
+1  A: 

1) I would guess at the worker process but this should be configurable within IIS to the limit of memory that a worker process can use. Another factor is what level of bits does your software use, e.g. 32 bit has a physical limit of 4 GB since this is the total address space.

2) Probably but don't forget that memory fragmentation may play a role in getting to out of memory faster than you think, e.g. if there is a memory request for a contiguous 1000 Mb piece of memory then this may not necessarily be found in the current memory.

3) Have you examined dump data to see what is in the memory when the exception gets thrown? If not, there are ways to get a snapshot of the memory to see what it looks like as this may give you more clues about what is going on.

JB King
We have a 32-Bit machine. From our reading and research, memory fragmentation may well play a big part in puzzle. Thanks for your info.
nick_alot
+1  A: 
  1. You are running in a process. A process can only access 2 gigs of memory. This task is sharing memory with everything else running in this process, so this bit of code does not get the full 2 gig -- even if it is available. There is a 3 gig switch on the os as well. I believe it is a registry setting. But you will have to search MSDN to find that info.

But realistically, you need to do this another way. Possibly by switching to a SAX style xml parser.

Chris Brandsma
Thanks Chris, is SAX an option for XSLT on the .NET framework?
nick_alot