【问题标题】:Memory leak during SELECT TOPSELECT TOP 期间的内存泄漏
【发布时间】:2016-07-04 01:08:36
【问题描述】:

我有一个非常简单的 .asmx Web 服务,它从 ms sql server 存储过程返回数据集。该过程返回大约 15,000 条记录。当调用 Web 服务时,iis 服务器会被 BSD 锁定。我做诊断的第一件事是通过将 select 语句更改为“select top 1000 ...”来限制返回的记录数。我不断增加数字以确定是什么容量导致它中断。

我发现即使我将它设置为“选择前 20000 名”它也不会崩溃。但是,如果我删除“top x”上限,它每次都会崩溃。我完全无法理解存储过程中的“top x”上限如何防止在返回相同数量的记录时(有或没有上限)发生崩溃。

我也有从同一服务器上的 .net Web 应用程序调用的完全相同的存储过程,如果没有上限,它不会导致这个问题。以下是我认为可能是相对的所有内容:

网络服务代码:

[WebMethod]
    [SoapHeader("soapSecurityCredentialsHeader", Direction = SoapHeaderDirection.In)]
    /* credentials check removed */
    public DataSet ESP_Export_000DS()
    { 
        DataSet dsResults = new DataSet();
        dsResults = syncBLObject.ESP_Export_000();
        return dsResults;
    }

这是存储过程的接口:

        public static DataSet ESP_Export_000()
    {
        DataSet dsResults = new DataSet();

        try
        {
            SqlConnection sqlConn = new SqlConnection(...);
            SqlCommand sc = new SqlCommand("...[ESP_Export_000]");
            sc.CommandType = CommandType.StoredProcedure;
            sc.Connection = sqlConn;
            sc.CommandTimeout = 300;
            using (SqlDataAdapter da = new SqlDataAdapter(sc))
            {
                 da.Fill(dsResults);
            }
        }
        catch(Exception excp)
        {
            throw new Exception(excp.Message, excp.InnerException);
        }

        return dsResults;
    }

存储过程大约需要 2.5 秒才能运行。 Web 服务会在大约 5 秒内返回数据。 IIS 服务器是:2008 R2 Enterprise,iis 6.1,2 gig 内存。 SQL server 为 MS SQL server 2012 Web 版。

【问题讨论】:

  • 题外话:这个throw new Exception(excp.Message, excp.InnerException);对我来说似乎毫无意义。
  • 如果您的服务器正在蓝屏,那么它有更严重的问题,nothing 你可以在 C# 代码中执行的操作应该会导致蓝屏(可能除了一些 P/Invoke'陷入肮脏)。
  • 1.在 Web 应用程序中调用存储过程时是否还指定超时时间? 2.你有蓝屏的停止码吗?
  • 只是一个观察,你没有关闭连接?
  • 您是否尝试过更新统计信息?

标签: c# sql-server web-services stored-procedures asmx


【解决方案1】:

@CodingGorilla 和@NickOtten 都是正确的,因为问题出在服务器而不是代码上。

RackSpace 的优秀人员推荐了这个解决问题的 powershell 脚本。

再次感谢@NickOtten,您确实抓住了问题的核心,并且从一开始就这样做了。

$root = ‘HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}’
$items = Get-ChildItem -Path Registry::$Root -Name

Foreach ($item in $items) {
if ($item -ne “Properties”) {
$path = $root + “\” + $item
$DriverDesc = Get-ItemProperty -Path Registry::$path | Select-Object -expandproperty DriverDesc
if ($DriverDesc -eq “Citrix PV Ethernet Adapter”) {
Set-ItemProperty -path Registry::$path -Name LROIPv4 -Value 0
}
}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 2014-08-16
    • 2015-02-27
    相关资源
    最近更新 更多