使用多少个 Windows 句柄算“太多”?
据我了解,这个问题的答案可能取决于注册表设置和 Windows 版本,如果内存不足,还可能取决于 RAM 量。 对于这个问题,假设服务器有足够的 RAM (3+ GiB)。
如果一个应用程序(本例中为第三方应用程序)每小时泄漏几百个句柄,那么在其他应用程序遇到麻烦之前,该应用程序总共可以泄漏多少个句柄? 我所说的“问题”是指,例如,无法启动线程、无法打开文件等等。
我见过一些服务器(轻载)使用数万个句柄的进程(通常是数据库进程)运行得很好,因此旧的 10000 个句柄限制显然不是这里的问题。 (无论如何,这是每个进程的限制,所以不会影响我的应用程序,它远低于该点。)
有人可以回答这个问题或向我指出一些资源来解释 Windows 服务器将允许多少个总句柄在你有效地耗尽(句柄或其他系统资源)之前?
I understand that the answer to this question may depend on registry settings and on the version of Windows, and perhaps on the amount of RAM if there is not enough memory. For the sake of this question, assume that the server has plenty of RAM (3+ GiB).
If an application (3rd party application in this case) leaks handles at a few hundred an hour, how many total handles can that application leak before other applications will run into troubles? By "troubles" I mean, for example, fail to start a thread, fail to open a file, and so on.
I've seen some servers (lightly loaded) run just fine with a process (usually a database process) using a few tens of thousands of handles, so the old 10000 handle limit is clearly not the issue here. (And that was a per-process limit anyway, so wouldn't affect my application which is well under that point.)
Can someone either answer the question or point me at some resources that explain about how many total handles a Windows server will allow before you effectively run out (of handles or other system resources)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请参阅Raymond Chen 关于此主题的帖子。 窗口管理器强制每个进程 10K 的限制,并且整个系统的总限制为 32K。 因此,如果它每小时“仅”泄漏 100 个句柄,那么在它开始出现异常之前,您还有几天的正常运行时间。
请注意,并非所有句柄都是相同的。 例如,窗口句柄不是数据库句柄,并且可能遵循不同的规则。 因此,此限制可能不适用,具体取决于程序泄漏的句柄类型。 另请阅读此博文。
See Raymond Chen's post on this topic. The window manager enforces a limit of 10K per process, and has a total limit of 32K across the system. So if it "only" leaks 100 handles per hour, then you have a few days of uptime before it starts misbehaving.
Note that not all handles are equal. Window handles are not DB handles, for example, and may follow different rules. So this restriction might not apply, depending on what sort of handles the program is leaking. Also read this blog post.
桌面堆,这是一个内存池,句柄代表的真正“东西”存在于此。 有时,重要的不是您分配了多少个句柄,而是该句柄下的每个对象使用了多少内存。您可以调试堆这样。 安装起来痛苦。
(这是从我的另一个答案中回收的)
The desktop heap, which is a pool of memory where the real "stuff" the handle represents lives. It's sometimes not so much how many handles you have allocated but how much memory each object under that handle is using. You can debug the heap this way. It is a pain to install.
(this was recycled from another one of my answers)
由于这些值可能会随着新的 Windows 版本而变化,因此您可以使用 SysInternals 工具
TestLimit
/TestLimit64
进行粗略估计。 x64版本可能会运行一段时间,特别是对于内存测试(它可能会使用硬盘(交换文件)来获取更多虚拟内存)。从 http://live.sysinternals.com/WindowsInternals/ 或 http://download.sysinternals.com/files/TestLimit.zip
命令行选项:
Since those values could change with new Windows versions, you can use the SysInternals tool
TestLimit
/TestLimit64
to get a rough estimate. The x64 version may run for a while, especially for the memory test (it might use the hard disk (swap file) to get more virtual memory).Get the tools from http://live.sysinternals.com/WindowsInternals/ or http://download.sysinternals.com/files/TestLimit.zip
Command line options:
根据 此最近的博客文章 Windows 10 中进程的总句柄限制被硬编码为
16*1024*1024
或 16,777,216。作为 Windows 执行官 (另请参阅此处)还存储一些有关句柄的跟踪信息,实际限制对于 64 位 Windows 10 为 16,711,680,对于 32 位 Windows 10 为 16,744,448:
As per this recent blog post the limit of total handles for a process in Windows 10 is hard-coded as
16*1024*1024
or 16,777,216.As the Windows Executive (see also here) also stores some tracking information about handles, the actual limits are 16,711,680 for 64-bit Windows 10 and 16,744,448 for 32-bit Windows 10:
根据此,10000。
According to this, 10000.