应用程序池不遵守内存限制

luc*_*uma 8 iis application-pools process iis-7.5 kill-process

我正在处理具有内存泄漏的旧版 .NET 应用程序。为了尝试缓解内存溢出情况,我将应用程序池内存限制设置为 500KB 到 500000KB (500MB) 之间的任何位置,但是应用程序池似乎不尊重设置,因为我可以登录并查看物理内存(5GB 及以上,无论值如何)。这个应用程序正在杀死服务器,我似乎无法确定如何调整应用程序池。为了确保此应用程序池不超过大约 500 MB 的内存,您建议进行哪些设置。

这是一个示例,应用程序池正在使用 3.5GB 的

进程列表

应用程序池

因此,服务器再次崩溃,原因如下:

在此处输入图片说明

具有低内存限制的相同应用程序池,1000 个回收请求,每两到三分钟会导致一个回收事件,但有时它会跑掉。

我也对任何可以监视此过程的工具持开放态度(作为任务或服务每 30 秒运行一次),并且可以在超过某个限制时将其终止。

Nik*_*Nik 2

我发现这篇文章是因为我正在努力回答类似的问题,其中限制不受限制。请参阅未遵守 IIS WebLimits

不过,我可以解决你的问题。尝试下面的 C# 代码。您可以使用 powershell 执行相同的操作。您需要以管理员权限运行它。

 static void Main(string[] args)
    {

        string appPoolName = args[0];
        int memLimitMegs = Int32.Parse(args[1]);
        var regex = new System.Text.RegularExpressions.Regex(".*w3wp.exe \\-ap \"(.*?)\".*");

        //find w3wp procs....
        foreach (var p in Process.GetProcessesByName("w3wp"))
        {

            string thisAppPoolName = null;

            try
            {
                //Have to use WMI objects to get the command line params...
                using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + p.Id))
                {
                    StringBuilder commandLine = new StringBuilder();
                    foreach (ManagementObject @object in searcher.Get())
                    {
                        commandLine.Append(@object["CommandLine"] + " ");
                    }

                    //extract the app pool name from those.
                    var r = regex.Match(commandLine.ToString());
                    if (r.Success)
                    {
                        thisAppPoolName = r.Groups[1].Value;
                    }

                    if (thisAppPoolName == appPoolName)
                    {
                        //Found the one we're looking for. 
                        if (p.PrivateMemorySize64 > memLimitMegs*1024*1024)
                        {

                            //it exceeds limit, recycle it using appcmd. 

                            Process.Start(Path.Combine(System.Environment.SystemDirectory , "inetsrv", "appcmd.exe"), "recycle apppool /apppool.name:" + appPoolName);

                            Console.WriteLine("Recycled:" + appPoolName);
                        }
                    }
                }
            }
            catch (Win32Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)