Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, i.e. the initial request is slow, but subsequent requests are fast.

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).

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. The issue is that this doesn't seem to stick particularly long.

like image 756
lyptt Avatar asked Jun 20 '18 09:06

lyptt


1 Answers

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.

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. You may need to check your IIS and hosting settings. Some hosts will pause your web service if it's a "cheap" tier.

  • "slow -> 8 seconds" this honestly sounds like your have an external call that is slow. Perhaps a Db, external API, or something re-authenticating.

like image 164
ermish Avatar answered Oct 30 '22 14:10

ermish