简体   繁体   English

.Net Core API长时间运行的请求

[英].Net Core api long running request

I have a web app calling a .Net Core API for generating PDF documents. 我有一个调用.Net Core API的Web应用程序,用于生成PDF文档。 I'm doing a bunch of HTML to pdf conversion so it takes a while to complete 200 pages document. 我正在做很多HTML到pdf的转换,因此需要一段时间才能完成200页的文档。 I have it working in my local but not my AppService. 我在我的本地服务而不是AppService中使用它。 At first, I was getting "The specified CGI application encountered an error and the server terminated the process." 首先,我得到“指定的CGI应用程序遇到错误,服务器终止了该过程。” if I went over 100 pages (small page sets work). 如果我浏览了100页以上(小页面集工作)。

The code calling my api: 调用我的api的代码:

var httpClient = new HttpClient();
HttpContent content = new StringContent(JsonConvert.SerializeObject(pdfRecipeDto), Encoding.UTF8, "application/json");
httpClient.Timeout = System.TimeSpan.FromMinutes(30);
var pdfFileUrl = httpClient.PostAsync("http://yada-yada.azurewebsites.net/api/pdf/Generate", content)
                 .GetAwaiter()
                 .GetResult()
                 .Content.ReadAsStringAsync().Result; // yes i know this is gross

I found this post and others that said simular. 我发现这篇文章和其他类似的文章。 tried the first answer but after manually modifying my web.config in Kudu (bc i don't know how to set it in my project) 尝试了第一个答案,但在Kudu中手动修改了我的web.config后(不列颠哥伦比亚省,我不知道如何在我的项目中设置它)

<?xml version="1.0" encoding="utf-8"?>
 <configuration>
  <system.webServer>
    <handlers>
     <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore requestTimeout="00:20:00"  processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

the requestTimeout="00:20:00" being the important part. requestTimeout =“ 00:20:00”是重要的部分。

But i get a "500 - The request timed out. The web server failed to respond within the specified time.". 但是我收到“ 500-请求超时。Web服务器无法在指定的时间内响应。”。

i also tried the adding .UseKestrel(...) to my program.cs 我也尝试将.UseKestrel(...)添加到program.cs

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
    .UseApplicationInsights()
            .UseStartup<Startup>()
            .UseKestrel(o =>
            {
                o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
            })
            .Build();;

But that seemed to do nothing. 但这似乎无济于事。

Yes, Azure Load Balancer has a default idle timeout setting of approximately four minutes it's documented in the FAQ here: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-availability-performance-application-issues-faq#why-does-my-request-time-out-after-230-seconds 是的,Azure Load Balancer的默认空闲超时设置大约为四分钟,在此处的常见问题中对此进行了说明: https : //docs.microsoft.com/zh-cn/azure/app-service/app-service-web-availability-性能应用程序问题常见问题#为什么我的请求超时时间是230秒

Q: Why does my request time out after 230 seconds? 问:为什么我的请求在230秒后超时?

Azure Load Balancer has a default idle timeout setting of four minutes. Azure负载平衡器的默认空闲超时设置为四分钟。 This is generally a reasonable response time limit for a web request. 通常,这是Web请求的合理响应时间限制。 If your web app requires background processing, we recommend using Azure WebJobs. 如果您的Web应用程序需要后台处理,则建议使用Azure WebJobs。 The Azure web app can call WebJobs and be notified when background processing is finished. Azure Web应用程序可以调用WebJobs,并在后台处理完成时收到通知。 You can choose from multiple methods for using WebJobs, including queues and triggers. 您可以从多种使用WebJob的方法中进行选择,包括队列和触发器。 WebJobs is designed for background processing. WebJobs专为后台处理而设计。 You can do as much background processing as you want in a WebJob. 您可以在WebJob中进行任意数量的后台处理。 You could use webjob for your task and see how it goes. 您可以将webjob用于您的任务,看看它如何进行。

Further, all Azure Web Apps (as well as Mobile App/Services, WebJobs and Functions) run in a secure environment called a sandbox. 此外,所有Azure Web Apps(以及移动应用程序/服务,WebJob和功能)都在称为沙箱的安全环境中运行。 Each app runs inside its own sandbox, isolating its execution from other instances on the same machine as well as providing an additional degree of security and privacy which would otherwise not be available. 每个应用程序都在其自己的沙箱中运行,从而将其执行与同一台计算机上的其他实例隔离开来,并提供其他程度的安全性和隐私性,否则这些安全性和隐私性将是不可用的。 Checkout the GitHub page https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks , which lists the supported and unsupported PDF generators on Azure App Service. 检出GitHub页面https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks ,其中列出了Azure App Service上受支持和不受支持的PDF生成器。

So turns out Azure App Service have a hardcoded 230 seconds rule for requests. 因此,事实证明Azure App Service对于请求具有硬编码的230秒规则。 even if you make changes to the web.config and/or startup.cs. 即使您更改了web.config和/或startup.cs。

I found the answer here: https://stackoverflow.com/a/38676086/5919289 And https://social.msdn.microsoft.com/Forums/en-US/17305ddc-07b2-436c-881b-286d1744c98f/503-errors-with-large-pdf-file?forum=windowsazurewebsitespreview 我在这里找到了答案: https : //stackoverflow.com/a/38676086/5919289https://social.msdn.microsoft.com/Forums/en-US/17305ddc-07b2-436c-881b-286d1744c98f/503- PDF档案错误?forum = windowsazure网站预览

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 长时间运行的任务 api 从逻辑应用程序调用以避免在.Net Core 3.0 中多次重试后超时错误请求响应 - Long running task api call from logic app to avoid timeout bad request response after many retiries in .Net Core 3.0 .Net Core 中的长时间运行任务 - Long Running Task in .Net Core .Net Core中的长时间运行动作超时 - Long Running Action Timeout in .Net Core 从.net核心WEB API获取500错误以进行长期运行的任务 - Getting 500 error from .net core WEB API for long running task 在.net core web api中异步调用长时间运行进程的最佳方法 - Best way of calling a long running process asynchronously in .net core web api .net 核心 6 api 错误请求 - .net core 6 api bad request 向在 Service Fabric 群集中的特定节点上运行的 ASP.Net Core Web API 发送请求 - Sending request to ASP.Net Core Web API running on a specific node in a Service Fabric Cluster 将 .Net Core API 部署并运行到 FTP 服务器 - Deploying and running .Net Core API to an FTP Server 创建针对Linux Docker容器的长期运行的.NET Core服务 - Create long running .NET Core service targeting Linux Docker container Asp.Net 核心长时间运行/后台任务 - Asp.Net core long running/background task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM