简体   繁体   English

在ASP.NET Core Web API项目中保持控制器的温暖

[英]Keeping controllers warm in ASP.NET Core Web API project

I've noticed that after a period of time my ASP.NET Core Web API services seem to go through the same initialisation process you get when you launch them fresh, ie the initial request is slow, but subsequent requests are fast. 我注意到,经过一段时间后,我的ASP.NET核心Web API服务似乎经历了相同的初始化过程,当您重新启动它们时,即初始请求很慢,但后续请求很快。

Is there a common technique for keeping controllers warm so this doesn't happen? 有没有一种保持控制器温暖的常用技术,所以这不会发生? For reference I'm not using IIS (as far as I'm aware), these services run in Docker using Microsoft's official .NET Core docker images (not Alpine based). 作为参考,我没有使用IIS(据我所知),这些服务使用微软的官方.NET Core docker镜像(不是基于Alpine的)在Docker中运行。

I should also point out that controllers within these services are pre-warmed on launch via a /ready endpoint that's invoked by Kubernetes as a readiness check. 我还应该指出,这些服务中的控制器在启动时通过/ready Kreadynetes调用的/ready端点进行预热,作为准备检查。 The issue is that this doesn't seem to stick particularly long. 问题是,这似乎并没有特别长。

This definitely doesn't sound like a controller issue. 这肯定听起来不像控制器问题。 Controllers are typically a new instance for every request. 控制器通常是每个请求的新实例。 When you mentioned "slow -> 8 seconds, fast -> 300ms" in a comment, this is definitely not Kestrel or controller related. 当你在评论中提到"slow -> 8 seconds, fast -> 300ms"时,这绝对不是Kestrel或控制器相关的。

Your issue could be any number of things, but here's a couple guesses: 你的问题可能是任何问题,但这里有几个猜测:

  • If you are running your app in Windows (like an Azure App Service), then it is running under IIS. 如果您在Windows中运行应用程序(如Azure应用程序服务),则它在IIS下运行。 You may need to check your IIS and hosting settings. 您可能需要检查IIS和托管设置。 Some hosts will pause your web service if it's a "cheap" tier. 如果某个主机是“廉价”层,则会暂停您的Web服务。

  • "slow -> 8 seconds" this honestly sounds like your have an external call that is slow. "slow -> 8 seconds"这老实说听起来像你的外部呼叫很慢。 Perhaps a Db, external API, or something re-authenticating. 也许是Db,外部API或重新验证的东西。

If this experience of yours is in your development box/personal machine, and when you experirence this during everytime you begin debug or run your app, it may. 如果您的开发盒/个人计算机有这种体验,并且每次开始调试或运行应用程序时都经历过这种体验,它可能会。 But in real time, it certainly not going to be the case (except for the very first run or after the app pool is being recycled or the service instance is restarted). 但实时情况肯定不是这样(除了第一次运行或应用程序池被回收或服务实例重新启动之外)。 Even then, in the server, that difference should be very minimal. 即便如此,在服务器中,这种差异应该非常小。 With .net core, it should be even minimal delay experience. 使用.net核心,它应该是最小的延迟体验。

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

相关问题 Asp.net 内核 5.0 Web API 项目上没有控制器菜单项 - No Controllers menu item on the Asp.net core 5.0 Web API project 如何将ASP.NET MVC核心视图和ASP.NET WEB API控制器分离到单独的项目中? - How to seperate ASP.NET MVC core view and ASP.NET WEB API controllers into separate projects? 从另一个项目初始化ASP.NET Core Web API - Initialize ASP.NET Core Web API from another project 如何在 ASP.NET Core Web API 项目中设置 cookie - How to set a cookie in a ASP.NET Core Web API project CORS 在 ASP.NET 核心 Web API 项目中不工作 - CORS not working in ASP.NET core Web API project ASP.NET 核心 Web API - 项目参考中的 ConnectionString - ASP.NET Core Web API - ConnectionString in project reference ASP.NET Core 中 Api 控制器和视图控制器的单独文件夹 - Separate folder for Api controllers and View controllers in ASP.NET Core 使用 API 和 razor 页面启动 ASP.NET Core Web 项目 - Starting an ASP.NET Core web project with API and razor pages asp.net core web api 项目不运行 - asp.net core web api project does not run 将视图和控制器放在与 ASP.NET Core Web 应用程序不同的项目中 - Putting Views and Controllers in a different project than the ASP.NET Core Web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM