简体   繁体   English

单个.NET进程是否有内存限制

[英]Is there a memory limit for a single .NET process

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). 当前,我们正在考虑构建一个缓存系统,以保存从SQL数据库中提取的数据,并将其提供给其他几个应用程序(网站,Web服务等)使用。 We imagine the cache to be running as a windows service and basically consist of a smart dictionary which holds the cache entries. 我们假设缓存将作为Windows服务运行,并且基本上由一个智能字典组成,该字典保存了缓存条目。 My question is, is there a limit to the working set of the application (it will be running under windows server 2003)? 我的问题是,应用程序的工作集是否有限制(它将在Windows Server 2003下运行)? Or is the amount of physical memory the limit? 还是物理内存量是限制?

32bit or 64bit? 32位还是64位? 32bit is 2gb (for a process), 64 bit is 1TB (enterprise edition 2003 server) . 32位是2gb(用于一个进程),64位是1TB(企业版2003服务器)

However, the maximum size of a CLR Object is 2gb even on 64bit. 但是,即使在64位上, CLR对象的最大大小也为2gb

Update: the information above was correct in 2008. See Ohad's answer for more recent information. 更新:上面的信息在2008年是正确的。有关更多最新信息,请参见Ohad的答案 Windows 2016 server can have a maximum of 24TB . Windows 2016服务器最多可具有24TB的存储空间

I have recently been doing extensive profiling around memory limits in .NET on a 32bit process. 我最近在32位进程中围绕.NET中的内存限制进行了广泛的性能分析。 We all get bombarded by the idea that we can allocate up to 2.4GB (2^31) in a .NET application but unfortunately 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 approximately 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(). 我们都可以在一个.NET应用程序中分配多达2.4GB(2 ^ 31)的想法而感到震惊,但是不幸的是,这不是真的:(。应用程序进程有足够的空间要使用,并且操作系统做得很好但是,.NET本身似乎有自己的开销,对于典型的实际应用程序来说,这会增加内存限制,大约需要600-800MB的开销。这意味着,一旦分配一个整数数组,大约需要1.4GB,您应该期望看到一个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. 显然,在64位中,此限制发生的时间较晚(让我们在5年内聊天:)),但是由于单词大小的增加,内存中所有内容的一般大小也会增加(我发现是其大约1.7到2倍)。

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. 只有这样,完整的2.4GB内存才能同时运行所有(许多)应用程序。

The following table from MSDN is the most precise answer to your query. MSDN的下表是您查询的最精确答案。 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 . 请注意,尽管可以通过buildbin实用程序在生成后进行设置,但不能直接从托管编译器设置IMAGE_FILE_LARGE_ADDRESS_AWARE标志。 4GT refers to the /3gb flag. 4GT是指/ 3gb标志。

替代文字

在32位Windows上,通过使用/ 3gb标志引导Windows并将您的应用程序标记为“可识别大地址”,您可以获得更多的内存。

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)? 对于脱机访问,是否可以在桌面上使用sql express创建数据库镜像(或仅需要缓存的位)? 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. 您正在考虑创建声音的字典非常类似于Sql索引。 I would rely on sql to do the job for you if you can architect it that way. 如果可以采用这种方式,我将依靠sql为您完成这项工作。 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. 如果这样做,则必须仔细考虑缓存过期和内存管理-特别是如果这是Windows服务。

Good luck, 祝好运,

Sam 山姆

As with any other Windows program, you're limited by address space. 与任何其他Windows程序一样,您受地址空间的限制。 That is: on 32-bit, you can have 2GB of address space. 也就是说:在3​​2位上,您可以拥有2GB的地址空间。 On x64, you can have 8TB. 在x64上,您可以拥有8TB。

If you don't have 8TB of physical memory, it will start to page. 如果您没有8TB的物理内存,它将开始分页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM