【问题标题】:ServiceStack request processing delay before PreRequestFiltersPreRequestFilters 之前的 ServiceStack 请求处理延迟
【发布时间】:2016-01-08 12:34:07
【问题描述】:

我们使用

HostContext.RawHttpHandlers.Add(action)

开始时间测量和

m_appHost.PreRequestFilters.Insert(0, action) // we want to be the first filter executed

停止时间测量。我们按顺序向服务器发送请求(使用 IIS Express 开发服务器在 localhost 上运行)并观察这两个操作之间的时间。有时它低至几毫秒,但通常会上升到几百毫秒。轻量级 GET 请求也会发生这种情况。

根据https://github.com/ServiceStack/ServiceStack/wiki/Order-of-Operations

  1. HostContext.RawHttpHandlers 在执行任何其他操作之前执行,即返回任何 ASP.NET IHttpHandler 完全绕过 ServiceStack 并改为处理您的自定义 IHttpHandler。
  2. 如果请求与任何现有路由都不匹配,它将在 IAppHost.CatchAllHandlers 中搜索匹配项
  3. IAppHost.PreRequestFilters 在 Request DTO 被反序列化之前被执行

我们还挂钩到 CatchAllHandlers 以确保它不会被调用:

m_appHost.CatchAllHandlers.Insert(0, action)

我们使用如下属性在 AppHost 中注册路由:

typeof(HelloRequestDTO).AddAttributes(new RouteAttribute("/hello/{Name}", "GET"));

知道什么会在 RawHttpHandler 之后和 PreRequestFilters 之前导致这种延迟吗?

ServiceStack 版本是 4.0.50。

【问题讨论】:

    标签: c# asp.net request servicestack delay


    【解决方案1】:

    时间测量是错误的。

    (DateTime.Now - lastDateTime).TotalMilliseconds
    

    返回 50 到 1000 毫秒之间的随机值。

    使用 System.Diagnostics.Stopwatch 和

    watch.ElapsedMilliseconds - lastMillisecondTime
    

    产生 1 - 5 毫秒持续时间的预期值

    HostContext.RawHttpHandlers
    

    m_appHost.PreRequestFilters
    

    我不认为 DateTime 的不精确性如此之高。我永远不会再使用它进行毫秒计时。

    【讨论】:

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