views:

2409

answers:

7

We are currently thinking of building a cache-system to hold data pulled out of an SQL database and make it available to a couple of other applications (website, webservice, etc). We imagine the cache to be running as a windows service and basically consist of a smart dictionary which holds the cache entries. My question is, is there a limit to the working set of the application (it will be running under windows server 2003)? Or is the amount of physical memory the limit?

A: 

As with any other Windows program, you're limited by address space. That is: on 32-bit, you can have 2GB of address space. On x64, you can have 8TB.

If you don't have 8TB of physical memory, it will start to page.

Roger Lipscombe
And if you don't have 8TB of hard drive space available (I wish) then you'll start to get OutOfMemoryException's. Too bad. It'll be a while before many of us have that size HDD's in our development machines though. :(
Matthew Scharley
+7  A: 

32bit or 64bit? 32bit is 2gb (for a process), 64 bit is 1TB (enterprise edition 2003 server).

However, the maximum size of a CLR Object is 2gb even on 64bit.

Chris S
thanks for the read. it seems, that this post has been written prior to release of .net 2.0. i wonder, if there have been any changes in later versions.
Matthias
It's relevant for version 2.0 of the runtime, but I don't think that it has changed in 3.5. Having a single object of 2gb (unless it's a byte array) is fairly unusual anyway - in your case it would be a list of objects N size so you'd be ok.
Chris S
The restrictions are the same in .NET 4 as well.
280Z28
+1  A: 

On 32bit Windows you can get a bit more memory by booting Windows with the /3gb flag and flagging your app as "large address aware"

Sean
do you have a link to some further reading on this one?
Matthias
It's not that you get more memory in XP (i.e., more of that 4GB of RAM) it's that you can run a process up to 3GB of RAM http://msdn.microsoft.com/en-us/library/ms791558.aspx
Schnapple
Also don't use it with Virtual PC or Virtual Server http://blogs.msdn.com/virtual_pc_guy/archive/2004/12/23/331100.aspx
Schnapple
Anyone know how this works in 2008 server? i am assuming its still the same for the 32bit version.
MikeJ
+1  A: 

Matthias,

Not actually an answer to the direct question, but another way of approaching this problem which will get around some of the big pitfalls, which can be a major headache with caching solutions. (Sorry I don't have any recommended reading on the matter.)

We implemented this in a previous project, and it did create other problems.

For offline access, can you use sql express on the desktops to create a mirror of your database (or just the bit you need to cache)? Then all you need to do is switch which database your application is pointing to. You can even use it store diffs and replay these to the server - although this has other problems. You can alter the permissions on the local copy to make this one read-only if that's how it should be.

The dictionaries you are thinking of creating sound remarkably like Sql indexes. I would rely on sql to do the job for you if you can architect it that way. Why reinvent that wheel? If you do, you will have to think carefully about cache expiration and memory management - particularly if this is a windows service.

Good luck,

Sam

Sam Meldrum
+4  A: 

I have recently been doing extensive profiling around memory limits in .NET on a 32bit process. We all get bombarded by the idea that we can allocate up to 2.4GB (2^31) in a .NET application but unfortuneately this is not true :(. The application process has that much space to use and the operating system does a great job managing it for us, however, .NET itself seems to have its own overhead which accounts for aproximately 600-800MB for typical real world applications that push the memory limit. This means that as soon as you allocate an array of integers that takes about 1.4GB, you should expect to see an OutOfMemoryException().

Obviously in 64bit, this limit occurs way later (let's chat in 5 years :)), but the general size of everything in memory also grows (I am finding it's ~1.7 to ~2 times) because of the increased word size.

What I know for sure is that the Virtual Memory idea from the operating system definitely does NOT give you virtually endless allocation space within one process. It is only there so that the full 2.4GB is addressable to all the (many) applications running at one time.

I hope this insight helps somewhat.

Luke Machowski
+2  A: 

The following table from MSDN is the most precise answer to your query. Note that the IMAGE_FILE_LARGE_ADDRESS_AWARE flag cannot be set directly from the managed compiler, though fortunately it can be set post build via the editbin utility. 4GT refers to the /3gb flag.

alt text

ohadsc
A: 

How do I use my 8GB with C#.NET VS 2008 application? or do I need VS 2010? I tried /LARGEADDRESSAWARE in x64bits, that doesn't seem to do it

thanks for your help

Wil