Before we dive into the details, let’s clarify what a cold start is. Cold start refers to a problem where a system or its part was created or restarted and is not working at its normal operation[1].
I’m going to talk about how quickly a web application can handle a request from the cold. It’s important to understand that some of the legacy applications have to deal with cold start depending on the server that’s hosted. In this example, let’s take IIS. You may be thinking, why on earth are you using IIS? But the truth is most of the well-established .NET Framework-based web applications still use IIS.
There are a few things you can do in IIS to do things faster. Before talking about that, let’s see why things start slowly.
First, take a closer look at the startup. There can be many things there, from dependency injection to creating resources such as pub sub-topics and subscriptions. Strangely, there could be some compilation processes in there, creating artifacts that can be consumed later. None of these approaches may be wrong at the time of implementation. However, money-making applications have a tendency to grow rapidly in terms of features as well as users. Eventually, you will start having scaling and performance issues.
How can we resolve some of the issues?
- Use an application performance monitor and analyse the startup process end to end. Most tools will provide the processing time of each method.
- Identify the methods that take too long to process. How long is too long depends on the KPIs.
- Introduce solutions that can cut down the time. In my experience, some of the logic in the startup doesn’t need to happen in the startup anymore. Some of those requirements may have changed, or the part of the functionality is never being used.
- Think about implementing lazy loading and distributed caching.
- Make sure the dependency services have a relatively quick startup time. If not, work on them as well as the current service.
There are quick wins you can get by fine-tuning the IIS.
- Set the application pool setting Start Mode to Always Running – This feature will make the app pool keep running without letting it go cold.
- Set the application pool setting Recycling Regular time interval to 0 – This will disable the periodic recycling. Make sure to keep an eye on the memory use of the app. This can lead to memory leaks if the app doesn’t have good memory management.
- Change the app pool recycling times to make sure your customers are not affected.
- Enable Application Initialisation feature[2] – This will proactively perform initialisation tasks. When the IIS restarts, this will warm up the sites.
These setting changes will help to give a little boost to the cold start time while you are focusing on the code improvements.
Always test the changes in the downstream environments, such as QA or UAT before making changes in production workloads. This includes the IIS changes. With legacy applications, it’s hard sometimes to predict how the application behave to the changes.
Leave a Reply