使用多少个 Windows 句柄算“太多”?

发布于 2024-07-23 08:33:04 字数 392 浏览 7 评论 0原文

据我了解,这个问题的答案可能取决于注册表设置和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

莫多说 2024-07-30 08:33:04

请参阅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.

掩耳倾听 2024-07-30 08:33:04

桌面堆,这是一个内存池,句柄代表的真正“东西”存在于此。 有时,重要的不是您分配了多少个句柄,而是该句柄下的每个对象使用了多少内存。您可以调试堆这样。 安装起来痛苦

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

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)

红墙和绿瓦 2024-07-30 08:33:04

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

http://live.sysinternals.com/WindowsInternals/http://download.sysinternals.com/files/TestLimit.zip

命令行选项:

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

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:

-p check process limit
-t check thread limit
-h check handle limit
-u check user handle limit
来日方长 2024-07-30 08:33:04

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

作为 Windows 执行官 (另请参阅此处)还存储一些有关句柄的跟踪信息,实际限制对于 64 位 Windows 10 为 16,711,680,对于 32 位 Windows 10 为 16,744,448

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

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.

柠栀 2024-07-30 08:33:04

根据,10000。

According to this, 10000.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文