Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 预请求筛选器之前的ServiceStack请求处理延迟_C#_Asp.net_Request_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack_Delay - Fatal编程技术网 servicestack,delay,C#,Asp.net,Request,servicestack,Delay" /> servicestack,delay,C#,Asp.net,Request,servicestack,Delay" />

C# 预请求筛选器之前的ServiceStack请求处理延迟

C# 预请求筛选器之前的ServiceStack请求处理延迟,c#,asp.net,request,servicestack,delay,C#,Asp.net,Request,servicestack,Delay,我们使用 开始时间测量和 HostContext.RawHttpHandlers.Add(action) 停止时间测量。我们依次向服务器发送请求(使用IIS Express开发服务器在本地主机上运行),并观察这两个操作之间的时间间隔。有时低至几毫秒,但通常高达几百毫秒。轻量级GET请求也会发生这种情况 据 HostContext.rawHttpHandler在执行任何其他操作之前执行,即返回任何ASP.NET IHttpHandler将完全通过ServiceStack并处理自定义IHttpHa

我们使用

开始时间测量和

HostContext.RawHttpHandlers.Add(action)
停止时间测量。我们依次向服务器发送请求(使用IIS Express开发服务器在本地主机上运行),并观察这两个操作之间的时间间隔。有时低至几毫秒,但通常高达几百毫秒。轻量级GET请求也会发生这种情况

  • HostContext.rawHttpHandler在执行任何其他操作之前执行,即返回任何ASP.NET IHttpHandler将完全通过ServiceStack并处理自定义IHttpHandler
  • 如果请求与任何现有路由不匹配,它将搜索IAppHost.CatchAllHandlers以查找匹配项
  • 在反序列化请求DTO之前执行IAppHost.PreRequestFilters
  • 我们还连接到CatchAllHandler以确保不调用它:

    m_appHost.PreRequestFilters.Insert(0, action) // we want to be the first filter executed
    
    我们使用如下属性在AppHost Ctor中注册路由:

    m_appHost.CatchAllHandlers.Insert(0, action)
    
    知道是什么导致了在RawHttpHandler之后和PreRequestFilters之前的延迟吗


    ServiceStack的版本是4.0.50。

    时间测量是错误的

    typeof(HelloRequestDTO).AddAttributes(new RouteAttribute("/hello/{Name}", "GET"));
    
    返回50到1000毫秒之间的随机值

    使用System.Diagnostics.Stopwatch和

    (DateTime.Now - lastDateTime).TotalMilliseconds
    

    watch.ElapsedMilliseconds - lastMillisecondTime
    

    HostContext.RawHttpHandlers
    
    我没想到日期时间的不精确性这么高。我再也不会用它来计时毫秒了

    m_appHost.PreRequestFilters