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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With