gpt4 book ai didi

windows - 如何增加 Windows 服务可以生成的最大子进程数——桌面堆限制

转载 作者:可可西里 更新时间:2023-11-01 12:30:33 29 4
gpt4 key购买 nike

问:我有一个生成很多子进程的 Windows 服务。似乎有一些限制,大约 100 个,无法启动该过程。 CreateProcess() 调用返回一个 pid,但随后进程就无法实现。如果我将我们的服务器作为控制台应用程序运行,这个限制就会消失。此外,如果我设置 DETACHED_PROCESS 标志,则此限制会增加一倍以上。但是,如果我设置 DETACHED_PROCESS 并调用 CreateProcesssWithLogonW(),我会失败。

最佳答案

这是一个“桌面堆”问题。可以在这里找到一个很好的讨论:

Desktop Heap OverviewDesktop Heap, Part 2

请注意,这适用于作为服务运行的程序,因为服务的默认桌面堆大小远小于应用程序。

在我们的案例中,我们能够在资源耗尽之前启动大约 100 个子进程而无需更改。随着变化,这个数字可以大大增加。

这是我们在知识库中为最终用户提供的答案:

WARNING: this affects the desktop heap of all services! Do not make it larger than necessary or you will push the system to consume more resource and you may bump up against problems in the total available desktop heap size.

If you find that you cannot open more than about 100 total projects, even on a very large RAM server, you may have run into a limit of the Windows "desktop heap size".

The problem is that service sessions under windows (where the services run) have less of this "desktop heap" space available for creating windows.

The short version is:

  • Services get smaller desktop heaps than interactive sessions.

  • Desktop heap size limits the number of windows

  • Each sub-server creates one or more “windows” even if we can’t see them.

Solution:

  1. Backup your registry before making any changes!

  2. Run regedit.exe as administrator

  3. Edit the registry value:

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows
  4. You will see a string like:

    %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=winsrv:ConServerDllInitialization,2 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

The critical bit is:

SharedSection=1024,20480,768

The second number (20480) is the size for interactive sessions. The third number (768) is the size of non-interactive (services) sessions. Note how the third number is 26x smaller than the second. Experimentally, we found that changing this to:

SharedSection=1024,20480,2048

Increased the project limit from 106 to 270, almost perfectly scaling with the heap size. Pick a value that reflects the maximum number of projects that you expect to be opened simultaneously by all users on the system. Do not make this value larger than necessary, and no larger than 8192, as each service in your system will consume more of a precious resource.

您需要重新启动才能使这些新设置生效。

关于windows - 如何增加 Windows 服务可以生成的最大子进程数——桌面堆限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17472389/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com