mottosson
mottosson

Reputation: 3763

Does Azure Functions run NPM install on cold starts?

I have an Azure Function set up to handle some logging to a database for me. The only dependency I have in my project is the mssql package and the function is ~70 lines of code and basically just takes the request and maps it to the database.

I'm experiencing extreme response times on some requests, up to 3 minutes! My spontaneous thought is that it's because it has to run npm install every time it starts a new instance of the function (cold starts).

Is this correct? What can I do to reduce the latency? Will it help to bundle mssql using WebPack in a build step and publish the bundled js to Azure?

Server response time

Upvotes: 1

Views: 1429

Answers (2)

suziki
suziki

Reputation: 14088

If you already have the packages, It will not install. If it not available, it will install. I think this is cold start.

Have a look of this doc.

Use app service plan can avoid this.

Also you can also pre-warmed the function to avoid this problem. Have a look of this doc.

Upvotes: 1

Hugo Barona
Hugo Barona

Reputation: 1398

This is a known behavior (called cold start) when you are using the Consumption plan on your functions. An example of the same issue reported here.

What you can do to mitigate this issue, in case you do not want to face the cold start, you can use the Premium Plan (it is still a Pay-as-you-Go pricing model). More info here.

Upvotes: 2

Related Questions