![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
Latency is the enemy of nimble apps, and cold starts — the extra time it might take for a function that hasn’t been used recently to respond to an event — are just one cause of it. No matter when your functions were last called, you want lightning-fast triggers and no lag time while a function warms up.
Measuring and improving cold starts in the platform and optimizing your functions are important to improving application performance and mitigating latency. Fortunately, there are things you can do to prevent a cold start from chilling your app’s performance. Before I share some tips, I’ll explain how Microsoft has approached the problem in Azure Functions.
Since launching in 2016, Azure Functions has helped many customers efficiently develop highly scalable, event-driven logic using their programming language of choice. It is built for scale and developer productivity, and the function runtime can run anywhere, even on your own machine. That’s the beauty of serverless functions.
However, one execution per instance isn’t the most efficient model for running functions, so Azure Functions provides concurrency options per instance (if your workload supports it). The benefit is not only better performance but also a drastic reduction of cold starts since new instances won’t start until the concurrency threshold is met.
The first step to improving performance is measuring it. To measure Azure Functions’ performance, we prioritize the cold start of synchronous HTTP triggers in the consumption model. That means looking at what the platform and the Azure Functions host must do to execute the first HTTP trigger function on a new virtual machine (VM) instance. Then we improve it. We are also working on improving cold starts for asynchronous scenarios.
To assess our progress, we run sample HTTP trigger function apps that measure cold start latencies for all supported versions of Azure Functions, in all languages, for both Windows and Linux consumption. We deploy these sample apps in all Azure regions and subregions where Azure Functions runs. Our test function calls these sample apps every few hours to trigger a true cold start, and currently, it generates about 85,000 cold start samples daily.
In tests, we aim for the cold start to be a few hundred milliseconds at the 50th percentile and well below one second for the 99th percentile, across all regions and for all supported languages and platforms. We built a massive infrastructure to conduct these tests.
In the past 18 months, we’ve reduced cold start latency by approximately 53% across all regions and for all supported languages and platforms.
If any of the tracked metrics start to regress, we’re immediately notified and start investigating. Daily emails, alerts and historical dashboards provide the end-to-end cold start latencies across various percentiles. We also perform specific analyses and trigger alerts if our 50th, 99th or maximum latency numbers regress.
We also collect detailed PerfView profiles of the sample apps deployed in select regions. The breakdown includes full call stacks (user mode and kernel mode) for every millisecond spent during the cold start. The profiles reveal CPU usage and call stacks, context switches, disk reads, HTTP calls, memory hard faults, common language runtime (CLR) just-in-time (JIT) compilers, garbage collectors (GC), type loads and many other details about .NET internals. We report all these details in our logging pipelines and receive alerts if metrics regress. And we’re always looking for ways to make improvements based on these profiles.
Developers sometimes ask why it takes so long to improve performance. We aim high and optimize for 99th percentile latency — a challenging feat of detection and engineering. We delve into cold start scenarios at the millisecond level and continually fine-tune the algorithms that allocate capacity. Our main focus areas are:
We’ve learned a lot from our trials that has minimized the impact of cold starts on app performance. Here are a few strategies you can try to analyze and further improve cold starts for your apps:
WEBSITE_RUN_FROM_PACKAGE=1 app setting. If your app uses Azure Storage to store content, deploy Azure Storage in the same region as your Azure Functions app and consider using premium storage for a faster cold start.If your Azure Functions app still doesn’t perform as well as you’d like: