Lucas Vieira
Lucas Vieira

Reputation: 41

.NET Core Web Api on AWS Lambda is slow upon first request

I'm deploying my .net core 2.1 application on AWS Lambda, I'm using AspNetCoreServer Package for proxy routing to my controllers, and I found the problema on this solution, in my first request lambda is very slow for executing the action controller, but in anothers requests is fast, I look in CloudWatch logs for understand whats is happen and i saw in logs that the longest time is in ControllerActionInvoker: Route Match to invoke my action, I would to know if i did anything wrong or is .net core is slow for aws lambda.

My logs evidencies:

Here is my first request log: Here is my first request log

And my second request log: second request log

Thank you

Upvotes: 3

Views: 2096

Answers (2)

Hayha
Hayha

Reputation: 2230

In fact the first slow request is not only caused by the lambda cold start. With .Net Core in lambda you have 2 cold start : the cold start of the lambda itself and the cold start of .net core itself. In order to avoid these 2 cold start you have to :

  • Lambda cold start : Warm your lambda by calling it every 5 min
  • .Net Core cold start : Warm your .Net Core api by calling all your endpoint at startup

refer to this github issue to know more on the first slow request in .Net Core (still hope this problem will be fixed or better managed in next dotnet core releases, but right now you don't have better option)

Upvotes: 4

Roman Patutin
Roman Patutin

Reputation: 2210

Cold start (first lambda invocation) is not the specific problem of .Net Core. You can find a timing comparison for different languages in this article.

Upvotes: 1

Related Questions