【问题标题】:ASP.Net WebApp Performance IssueASP.Net WebApp 性能问题
【发布时间】:2016-02-13 03:04:58
【问题描述】:

我一直在使用 ASP.Net WebApp,它需要很长时间才能加载特定的 ASPX 页面。第一次在浏览器中加载页面后,下次在生产中无法替换此问题。

更新

我添加了一些日志,看起来下面的查询需要 1 分 20 秒才能执行。你能帮我优化一下吗?第一次需要这么长时间的查询实际上有什么问题?

日志:

"11/12/15","22:24:24","ExecuteSql - ---4---- ","9",""

"11/12/15","22:25:44","ExecuteSql - ---5---- ","9",""

查询:

SELECT TOP 1 CONVERT(varchar(15), Period_End_Date, 107) as PDate FROM PBHISTORY..STATEMENT_OF_CHANGE ORDER BY Period_End_Date DESC","7",""

C#代码:

公共字符串 GetDateRangeReportingDate(int reportId) { LogActivityVerbose("GetDateRangeReportingDate - 在 GetReportInfoById 之前"); var 报告 = GetReportInfoById(reportId); LogActivityVerbose("GetDateRangeReportingDate - 在 GetReportInfoById 之后");

        string sql = string.Format(@"SELECT TOP 1 CONVERT(varchar(15), Period_End_Date, 107) as PDate FROM {0}..{1}
                                           ORDER BY Period_End_Date DESC", _historyDatabase, report.SourceTableName);

        LogActivityVerbose("GetDateRangeReportingDate - before ExecuteSql ");
        var data = ExecuteSql(sql);
        LogActivityVerbose("GetDateRangeReportingDate - after ExecuteSql ");
        while (data.Read())
        {
            return data["PDate"].ToString();
        }
        return null;
    }

【问题讨论】:

    标签: c# sql asp.net performance application-pool


    【解决方案1】:
    • 您是在部署调试版本还是发布版本(调试版本不包含编译器优化,并且会加载调试符号)?

    • 您的应用程序池是否经常回收?

    • 您是否在以某种初始化方式启动页面时加载了大量数据?

    • 另外请记住,新的 ASP .net 预编译程序集的初始加载将在启动时进行 Jitted,因此也需要一些时间。

    更多可能性:

    Web site takes unusually long time to start the first time it is accessed, (Up to 68 seconds in total)

    Fixing slow initial load for IIS

    我会先检查这些东西。

    【讨论】:

    • 非常感谢。我放了一些日志,看起来这个问题与基于 Log 的查询有关。下面的方法需要一分钟以上的时间来执行。你能提出一些优化它的建议吗?
    【解决方案2】:

    我找到了上面提到的性能问题的解决方案。问题是表中的索引错误,我通过更改表的索引来解决这个问题,我们从中获取生产中的记录。

    另外,我通过使用 SQL 数据适配器和 using 语句修复了框架级别的实体类。应用程序在生产中运行速度超快。感谢您的帮助。

    私有字符串 ExecuteSqlNew(string sql) { 字符串 connectionString = ConfigurationManager.ConnectionStrings["PBReportCS"].ConnectionString; 字符串 commandTimeOut = ConfigurationManager.AppSettings["PBReportCommandTimeout"].ToString(); 数据集结果 = 新数据集(); 字符串 pDate = "";

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        conn.Open();
                        cmd.CommandTimeout = int.Parse(commandTimeOut);
                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = cmd;
                        adapter.Fill(result);
                        adapter.Dispose();
                        conn.Close();
                        pDate = result.Tables[0].Rows[0]["PDate"].ToString();
                    }
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
            return pDate;
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多