正在使用的 Windows 句柄有多少是“太多”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/951419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:27:29  来源:igfitidea点击:

How many Windows handles in use is "too many"?

windowsperformancehandle

提问by Eddie

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).

我知道这个问题的答案可能取决于注册表设置和 Windows 版本,如果内存不足,可能还取决于 RAM 量。对于这个问题,假设服务器有足够的 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.

如果一个应用程序(在这种情况下是第 3 方应用程序)每小时泄漏数百个句柄,那么在其他应用程序遇到麻烦之前,该应用程序总共可以泄漏多少个句柄?我所说的“麻烦”是指,例如,无法启动线程,无法打开文件,等等。

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.)

我已经看到一些服务器(轻载)与使用数万个句柄的进程(通常是数据库进程)一起运行得很好,所以旧的 10000 个句柄限制显然不是这里的问题。(无论如何,这是每个进程的限制,所以不会影响我的应用程序,它远远低于那个点。)

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)?

有人可以回答这个问题或向我指出一些资源,以解释在您有效地用完(句柄或其他系统资源)之前,Windows 服务器将允许的总句柄数?

回答by JSB????

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.

请参阅Raymond Chen 关于此主题的帖子。窗口管理器对每个进程强制执行 10K 的限制,并且整个系统的总限制为 32K。因此,如果它“仅”每小时泄漏 100 个句柄,那么在它开始出现异常行为之前,您有几天的正常运行时间。

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.

请注意,并非所有句柄都是相同的。例如,窗口句柄不是 DB 句柄,并且可能遵循不同的规则。因此,此限制可能不适用,具体取决于程序泄漏的句柄类型。另请阅读此博客文章。

回答by Aardvark

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 objectunder that handle is using.You can debug the heap this way. It is a painto install.

桌面堆,这是一个内存池,在那里真正的“东西”把手代表生命。有时与其说分配了多少句柄,不如说是该句柄下的每个对象使用了多少内存。您可以通过这种方式调试堆。安装起来很痛苦

(this was recycled from another one of my answers)

(这是从我的另一个答案中回收的)

回答by Thomas Weller

Since those values could change with new Windows versions, you can use the SysInternals tool TestLimit/ TestLimit64to 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).

由于这些值可能会随着新的 Windows 版本而改变,您可以使用 SysInternals 工具TestLimit/TestLimit64来粗略估计。x64 版本可能会运行一段时间,尤其是内存测试(它可能会使用硬盘(交换文件)来获得更多的虚拟内存)。

Get the tools from http://live.sysinternals.com/WindowsInternals/or http://download.sysinternals.com/files/TestLimit.zip

http://live.sysinternals.com/WindowsInternals/http://download.sysinternals.com/files/TestLimit.zip获取工具

Command line options:

命令行选项:

-p check process limit
-t check thread limit
-h check handle limit
-u check user handle limit

回答by abcalphabet

As per this recent blog postthe limit of total handles for a process in Windows 10 is hard-coded as 16*1024*1024or 16,777,216.

根据最近的这篇博客文章,Windows 10 中进程的总句柄限制被硬编码为16*1024*102416,777,216

As the Windows Executive(see also here) also stores some tracking information about handles, the actual limits are 16,711,680for 64-bit Windows 10 and 16,744,448for 32-bit Windows 10:

随着视窗执行见也在这里)还存储处理一些跟踪信息,实际限制是16711680的64位Windows 10和16744448的32位Windows 10:

The Executive allocates handle tables on demand in page-sized blocks that it divides into handle table entries. That means a page, which is 4096 bytes on both x86 and x64, can store 512 entries on 32-bit Windows and 256 entries on 64-bit Windows. The Executive determines the maximum number of pages to allocate for handle entries by dividing the hard-coded maximum,16,777,216, by the number of handle entries in a page, which results on 32-bit Windows to 32,768 and on 64-bit Windows to 65,536. Because the Executive uses the first entry of each page for its own tracking information, the number of handles available to a process is actually 16,777,216 minus those numbers, which explains the results obtained by Testlimit: 16,777,216-65,536 is 16,711,680 and 16,777,216-65,536-32,768 is 16,744,448.

执行程序根据需要在页面大小的块中分配句柄表,并将其划分为句柄表条目。这意味着一个页面,在 x86 和 x64 上都是 4096 字节,在 32 位 Windows 上可以存储 512 个条目,在 64 位 Windows 上可以存储 256 个条目。执行程序通过将硬编码的最大值 16,777,216 除以页面中的句柄条目数来确定为句柄条目分配的最大页数,结果在 32 位 Windows 上为 32,768,在 64 位 Windows 上为 65,536 . 因为Executive使用每个页面的第一个条目作为它自己的跟踪信息,一个进程可用的句柄数实际上是16,777,216减去这些数字,这就解释了Testlimit得到的结果:16,777,216-65,536是16,711,680和16,777,216-832,65是 16,744,448。

回答by Otávio Décio

According to this, 10000.

根据,10000。