Profiling High CPU and Memory in Azure JavaScript Functions
When dealing with High CPU/Memory scenarios in Azure Functions, the best recommendation is to profile your app in your local environment, but sometimes it is hard to reproduce the issue specially not having the same request load or environment. For those scenarios you can configure a Node.js profiler for your application. These profilers can be divided in two main categories: Built-in profilers and Third-Party Profilers. You can find information for CPU and Memory in the sections below.
These links applies for Azure App Service Linux/Windows but you can implement those in Azure Functions adding App Settings or using adding third-party libraries in code.
Windows
Linux
- High CPU
- High Memory
Profiling in local dev environment vs Azure
-
If you are profiling locally in your computer, then open
local.settings.json
and add this line"languageWorkers__node__arguments": "<value>"
inside Values array, as an example:{ "IsEncrypted": false, "Values": { "FUNCTIONS_WORKER_RUNTIME": "node", "AzureWebJobsStorage": "UseDevelopmentStorage=true", "languageWorkers__node__arguments": "--cpu-prof" } }
-
If you are profiling in Azure App Service Windows, add this app setting
languageWorkers:node:arguments
with any argument described in the references above as--cpu-prof
. -
If you are profiling in Azure App Service Linux, add this app setting
languageWorkers__node__arguments
with any argument described in the references above as--cpu-prof-dir "/home/LogFiles/" --cpu-prof
.