Restricting .Net CLR memory usage

2019-05-05 14:15发布

问题:

Ok, so here's the problem. In our production environment (ASP.Net) our servers have a massive amount of memory as well as a massive number of users / sessions. My computer has 8 gigs, and I'm the only user. In production, we're (rarely) getting a System.OutOfMemoryException.

With that background information, here is the question: is it possible to make the CLR think I only have a gig of memory or less? IIRC, there's a command-line option to do this for Java.

Another option is to make some really big objects to fill up memory to simulate low memory conditions. But that requires modifying the assemblies and the huge objects might be cached to disk.

Recommendations? Or other options?

回答1:

One way to simulate a lower-memory/resource system is to create a system virtual machine and allocate the specific amount of memory you want it to have. Both VMWare and MS Virtual Machines have this feature.

Besides a simulation of a lower-resource machine VMs are also a great way to manage your test environments.



回答2:

Whether or not your program recieves an OutOfMemoryException is independent of how much RAM is on your machine. OutOfMemoryException means the process has run out of virtual memory which is the same for every process independent of physical RAM

There are a couple of items which can affect the amount of virtual memory in a process

  • 32 vs 64 bit process
  • Switches like /LargeAddressAware (Documentation)

Best guess is the server is a 64 bit process while the client machine is 32