【问题标题】:Why is Application_ResolveRequestCache have a long duration?为什么 Application_ResolveRequestCache 的持续时间很长?
【发布时间】:2014-04-15 00:42:00
【问题描述】:

我有一个带有跟踪(日志)工具的 ASP.NET 应用程序。 它使用 AJAX 检索数据(控件)。 我有这两个跟踪条目:

    protected void Application_ResolveRequestCache(Object sender, EventArgs e)
    {
        Log("Application_ResolveRequestCache", null);
    }

    protected void Application_AcquireRequestState(Object sender, EventArgs e)
    {
        Log("Application_AcquireRequestState");
    }

这两个条目之间的时间差异是Application_ResolveRequestCache 的持续时间(我认为)。方法Log依赖于单例类,写在HttpContext.Current.Trace

示例:用户在页面上执行某项操作,因为该站点向服务器发送 5 个 AJAX 请求(更新 5 个控件)。 每个请求的Application_ResolveRequestCache 的持续时间为(按时间顺序):0.001、1.518、4.556、5.057 和 5.575(以秒为单位)。

在我的 Global.asax 中,我通过过滤器禁用了缓存:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new OutputCacheAttribute
            {
                VaryByParam = "*",
                Duration = 0,
                NoStore = true,
            });
        }

那么,为什么 Application_ResolveRequestCache 需要时间,即使输出缓存被禁用?

注意:当前问题仅适用于 AJAX 请求。

附加信息:

AJAX 查询:

jQuery.ajax({
            url: "/mvcget/ajax/LoadControl/",
            data: properties,
            type: "POST",
            contentType: "application/x-www-form-urlencoded",
            async: true
        });

LoadControl 动作:

        [HttpPost]
        public virtual ActionResult LoadControl()
        {
            var control = CreateControlFromRequest<ITemplatedControl>();
            control.SaveUserValues();
            var content = control.Render();
            return Content(String.IsNullOrEmpty(content) ? " " : content);
        }

【问题讨论】:

  • 只是一个不:为你的个人资料使用这样的显示图片有什么要求它在 SO 中不好
  • 我喜欢它.. 格式也很好的问题,所以不应该'真的很重要。
  • 感谢更改显示图片:)

标签: jquery asp.net ajax performance caching


【解决方案1】:

您的测试代码并未测量仅调用 ResolveRequestCache 所需的时间。相反,它测量的是调用 ResolveRequestCache 和 AcquireRequestState 之间的所有内容所花费的时间。

如果您向服务器发出并行请求并且这些请求包含会话 cookie,则 ASP.NET 运行时将序列化请求。在管道中保存这些请求所花费的时间将显示在 ResolveRequestCache 和 AcquireRequestState 方法调用之间。

有关 AJAX + Session 的更多信息,请参阅 Are AJAX calls processed in serial fashion on server if you use ASP.Net session state?

编辑:我应该提到在 ResolveRequestCache 和 AcquireRequestState 之间发生了一些其他事件(例如路由)。如果你定义了很多路由,或者路由匹配逻辑特别复杂,这也会增加花费的时间。

如果您要在 Web 应用程序中进行准确的性能测量,请查看 http://www.iis.net/configreference/system.webserver/tracing

【讨论】:

猜你喜欢
  • 2020-04-12
  • 2021-10-12
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 2012-01-14
  • 2011-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多