上载大文件时处理慢的Kestrel请求

时间:2019-11-14 23:45:20

标签: performance asp.net-core iis virtual-machine kestrel

我有一个.NET Core 2.1 Web API,具有文件上传服务方法,并托管在带有v2.1.9 .NET Core运行时的Google Cloud Compute Engine虚拟机上的IIS 10.0 / Kestrel上。该服务已设置属性[RequestFormLimits(MultipartBodyLengthLimit = 30000000)]以限制大于30MB的文件。当我尝试上传60MB的文件时,该服务大约需要25到50秒的时间来回应有关文件大小限制的错误消息。类似的请求在本地和Windows服务器计算机上的处理时间不到4秒,但在由Google Cloud vm托管的生产环境中则需要25秒以上的时间。我已启用日志并看到以下输出,任何人都可以提供一些输入吗? Google云虚拟机具有2个虚拟处理器,足够的内存和较低的CPU使用率。还可以通过Ben Diagnostics阻止检测功能来启用Api,以检查是否有线程池不足,我在下面确实收到警告,不确定如何解决。

dbug: Microsoft.AspNetCore.Server.Kestrel[25]
      Connection id "0HLR94OJKUP5M", Request id "0HLR94OJKUP5M:00000003": started reading request body.
trce: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Resource Filter: Before executing OnResourceExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.SaveTempDataFilter.
trce: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
      Resource Filter: After executing OnResourceExecuted on filter Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.SaveTempDataFilter.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action Test.Api.Controllers.TesController.UploadFile (Test.Api) in 31077.652ms
dbug: Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector[11]
      List of registered output formatters, in the following order: Microsoft.AspNetCore.Mvc.Formatters.HttpNoContentOutputFormatter, Microsoft.AspNetCore.Mvc.Formatters.StringOutputFormatter, Microsoft.AspNetCore.Mvc.Formatters.StreamOutputFormatter, Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter
dbug: Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector[6]
      Attempting to select an output formatter based on Accept header 'application/json'.
dbug: Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector[2]
      Selected output formatter 'Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter' and content type 'application/json' to write the response.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
      Executing ObjectResult, writing value of type '<>f__AnonymousType0`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
dbug: Microsoft.AspNetCore.Server.Kestrel[9]
      Connection id "0HLR94OJKUP5M" completed keep alive response.
warn: Ben.Diagnostics.BlockingMonitor[6]
      Blocking method has been invoked and blocked, this can lead to threadpool starvation.
         at System.IO.FileStream.FlushWriteBuffer(Boolean calledFromFinalizer)
         at System.IO.FileStream.Dispose(Boolean disposing)
         at System.IO.Stream.Close()
         at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.Dispose(Boolean disposing)
         at System.IO.Stream.Close()
         at Microsoft.AspNetCore.Http.HttpResponse.<>c.<.cctor>b__30_1(Object disposable)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FireOnCompletedAwaited(Stack`1 onCompleted)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FireOnCompletedAwaited(Stack`1 onCompleted)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FireOnCompleted()
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
         at System.Runtime.CompilerServices.TaskAwaiter.<>c.<OutputWaitEtwEvents>b__12_0(Action innerContinuation, Task innerTask)
         at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(Action action, Boolean allowInlining)
         at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
         at System.Threading.Tasks.Task`1.TrySetResult(TResult result)
         at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetExistingTaskResult(TResult result)
         at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
         at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
         at System.Runtime.CompilerServices.TaskAwaiter.<>c.<OutputWaitEtwEvents>b__12_0(Action innerContinuation, Task innerTask)
         at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(Action action, Boolean allowInlining)
         at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
         at System.Threading.Tasks.Task`1.TrySetResult(TResult result)
         at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetExistingTaskResult(TResult result)
         at Ben.Diagnostics.BlockingDetectionMiddleware.Invoke(HttpContext httpContext)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
         at System.Runtime.CompilerServices.TaskAwaiter.<>c.<OutputWaitEtwEvents>b__12_0(Action innerContinuation, Task innerTask)
         at System.Threading.QueueUserWorkItemCallback`1.<>c.<.cctor>b__6_0(Object state)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.QueueUserWorkItemCallback`1.ExecuteWorkItem()
         at System.Threading.ThreadPoolWorkQueue.Dispatch()

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 31145.2073ms 500 application/json; charset=utf-8
info: Microsoft.AspNetCore.Server.Kestrel[32]
      Connection id "0HLR94OJKUP5M", Request id "0HLR94OJKUP5M:00000003": the application completed without reading the entire request body.
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
      Connection id "0HLR94OJKUP5M" sending FIN.
dbug: Microsoft.AspNetCore.Server.Kestrel[10]
      Connection id "0HLR94OJKUP5M" disconnecting.
dbug: Microsoft.AspNetCore.Server.Kestrel[26]
      Connection id "0HLR94OJKUP5M", Request id "0HLR94OJKUP5M:00000003": done reading request body.
info: Microsoft.AspNetCore.Server.Kestrel[33]
      Connection id "0HLR94OJKUP5M", Request id "0HLR94OJKUP5M:00000003": automatic draining of the request body timed out after taking over 5 seconds.
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
      Connection id "0HLR94OJKUP5M" stopped.

0 个答案:

没有答案