Azure provides a highly scalable, elastic pool of resources that can help you to create super-performant applications. Azure provides obvious things that can help you with performance, like (auto)scaling. It also provides some not-so-obvious services and features that can help your application to perform well.
This article will reveal some of the best services and features in Azure that can help your application to perform:
Tip 1: Avoid latency by working in the same geographical region
But still, we are bound by the speed of light. Data travels at the speed of light through wires under the oceans, above land, through routers, to and from datacenters. And that takes time. This takes more time when data needs to travel over long distances. It’s physics.
The time that data takes to travel over distances is called latency. This is the one thing that we can’t really battle (yet). This really influences the performance of applications. This is because it makes requests take longer. And it does this for each request. To load a single page of a website, the webbrowser sometimes has to perform more than 20 requests. When you have a high latency, all of the 20 requests will take longer, which is really noticeable in your application.
Try to avoid latency in your application. In Azure you deploy your application, services and data in a datacenter, somewhere in the world. You should take care that all of your services are as geographically close together as they can be, preferably in the same Azure region (like Central US). You can find out which Azure datacenter is closest to you by using the Azure Speed Test website.
Tip 2: Avoid latency by using Azure Traffic Manager
Besides making sure that your services have minimal latency when they talk to each other, you should make sure that there is minimal latency between your users and your application.
Suppose that you have a web application deployed in West Europe. Someone that uses it from Australia will have a high latency, and therefore, a slow experience.
You can deploy the web application in another Web App, closer to the user, for instance, in Australia East. But how would you route the user to that Web App? You can do that with Azure Traffic Manager. This is an Azure Service that acts as a global load-balancer that can load-balance based on geographic performance (which is latency).
You couple the domain name of the web application to Traffic Manager, so that users go to Traffic Manager, instead of the Web App. Traffic Manager than determines to which Web App the user should be routed and routes them there.
Tip 3: Offload traffic from your application by using Azure CDN
To use this, you create an Azure CDN profile and choose a provider (Azure works with Verizon and Akamai). Next, you couple an Azure Storage account to the profile, in which you put all of your static content. The CDN profile will than automatically copy all of this content to many Points Of Presence, all around the world, ensuring that the content is always close to the user. In your application, you change the reference to the static content to point to the Azure CDN Profile. A simple, yet very powerful improvement.
Tip 4: Avoid roundtrips to the database by using Azure Redis Cache
Almost every application works with data. Usually, this data lives in a database of some sort, like an Azure SQL Database or a Document DB. Reading or writing data from or to a database takes time. This is usually because the database needs to gather data by forming relations or traversing indexes and then read or write the data from or to a disk. Your application is better off if it can avoid calls to the database as much as possible.
In Azure, you can do this by using an Azure Redis Cache. This is a cache that can (amongst other things) store data in the form of key/value pairs. The advantage of using this instead of a database is that Azure Redis Cache is fast! That is because the data in the cache is in memory and usually in the format that you want, so it doesn’t require complex queries to be executed.
Usually, you can’t put all of your data in a cache. You should put data in there that doesn’t change often, like lookup tables. By doing that, you avoid database calls for this data and speed up your application.
Tip 5: Avoid JIT compilation in App Services
When you run a .NET application in an Azure App Services, it will be recycled at some point. By default, each application will be terminated every 1740 minutes (29 hours), which is called a periodic restart timeout. Also by default, applications will be recycled when they are unused for 20 minutes, which is called an idle timeout.
These are side effects from the IIS implementation within Azure App Services. When one of these things happens, your application is ‘restarted’ and will recompile (using Just In Time (JIT) compilation) whenever it is first used. This means that the first users will have to wait a couple of seconds for your app to load.
To avoid this, you can enable the setting Always On in an App Service. This will keep your application ‘alive’ by occasionally hitting it with a request in the root of the application. You do have to run your application in the Basic pricing tier or higher to use this feature.
You can find the setting in the Application Settings of your App Service.
Tip 6: Speed up database trips by using Azure SQL In-Memory OLTP
Instead of avoiding database trips, you could also optimize them. Azure SQL has a killer feature that makes it lightning fast: In-Memory OLTP (Online Transactional Processing). According to Microsoft, using In-Memory OLTP can make database operations 5 to 99 times faster, depending on the type of operation.
Normally, data would be loaded from disk, cached in memory and then processed and eventually written to disk again. The In-Memory feature of Azure SQL does something similar, but processes data operations completely different. They are optimized to work with data in-memory, which makes them, much, much faster. If you think that databases are slow, try this feature and let me know if you’ve changed your mind.
You do need to do optimized to work with data in-memory" target="_blank">a bit of work and use a the Azure SQL Premium pricing tier.
Tip 7: General tip – follow the Azure Advisor Performance Recommendations
Azure Advisor is an Azure service that provides you with information about your Azure services. This is information that can help you to improve security, reduce costs, keep applications highly available and improve performance.
Basically, the Azure Advisor gathers advisory messages from all of your services and bundles them together in a neat overview from which you can take action. These actions usually take you to the individual ‘advisor’ of the service. For instance, Azure SQL Database advises me to create a new index to improve a query that is taking a long time.
Follow these recommendations. Usually, they make sense and will improve the performance of your application.
Tip 8: Measure – Improve – Repeat
Improving the performance of your application is great, but how do you know what you should improve and if it worked?
You need to monitor the performance of your application to find out how it is doing and where the bottlenecks are. You can do this with tools like Application Insights.
Besides monitoring your production environment, you should also test any changes and monitor them, to see if they impact your performance. App Services provides the Performance Test feature, which lets you test your application by having a bunch of ‘virtual users’ use your application.
Under the hood, the feature uses Visual Studio Team Services to run the test. From there, you can run more complex tests if you want.
If you monitor your application well, you can determine if a new feature positively or negatively impacts your performance and if so, where the impact exactly is in your application.
Remember, measure everything!