How to optimize Umbraco 8 performance

How to optimize Umbraco 8 performance

This site runs Umbraco 8, using a Microsoft SQL Server database back-end.

Out of the box, Umbraco is a well built and pretty fast content management system. However, it is important you perform some steps to further optimize Umbraco's performance and loading speed. On Sysadmins of the North, I wrote about 11+ tips to optimize Umbraco CMS, and in this post I write about implementing them. On a just installed and running website.

ImageProcessor cache folders

A lot of nested cache folders are created by ImageProcessor, making it a bit non performing. It takes time for the server to locate the right folder and file to display an image. To decrease the number of read/writes, and to decrease the number of folders .NET has to plow through, it's important you configure a folder depth.

Open up the ~/Config/imageprocessor/cache.config file and look up the cache node, add folderDepth="2" to limit the maximum number of subfolders to two:

<cache trimCache="false" name="DiskCache" type="ImageProcessor.Web.Caching.DiskCache, ImageProcessor.Web" maxDays="365" browserMaxDays="7" folderDepth="2">

Save and upload the file, remove the contents of ~/App_Data/cache, and recycle your web application.

But wait for more tips!

trimCache and maxDays

Another option to decrease disk read/writes for IIS/.NET is to decrease the total number of cached image files. You can configure this using the trimCache option in the same cache key in ~/Config/imageprocessor/cache.config. But this one may come back to haunt you:

The way trimCache setting works, is every time an image is saved, the rest of the cache is purged of old images. this prevents the cache continually increasing in size, but depending on the size of your media, can cause load on the server at inconvenient times.

You can set trimCache to true and configure maxDays, so stale cached image files are purged after the configured number of days. Test this thoroughly!

Serilog log file creation

I wrote about configuring Log4Net in Umbraco in my Sysadmins of the North post I mentioned earlier. Nowadays, log4net has been replaced in Umbraco by Serilog as the default log engine. If you are not using logging or the logs Umbraco creates it's important you configure Serilog to log as less as possible. This improves disk read/writes (I/O) too.

Serilog's configuration is held in two files:

  • ~/Config/serilog.config
  • ~/Config/serilog.user.config

You'll first want the edit the last file: serilog.user.config. Change the key "serilog:minimum-level" from Information to either Warning, Error or Fatal:

<add key="serilog:minimum-level" value="Error" />

Once again, save the changes to the file, upload and recycle your application.

NumRecompilesBeforeAppRestart

Umbraco configures the value for NumRecompilesBeforeAppRestart attribute in the web.config file's compilation key. It defaults to 50 for Umbraco, and this value indicates the number of dynamic recompiles of resources that can occur before the application restarts.

Increasing this number to 150 or 200 decreases the number of application restarts. To do this, you need to edit the ~/web.config file:

<compilation defaultLanguage="c#" debug="false" batch="true" targetFramework="4.7.2" numRecompilesBeforeAppRestart="200" />

Save, upload and recycle.

But hey, there's more!

Compilation tempDirectory

On a shared hosting web server, you probably share your ASP.NET compilation temporary directory with other users. Its default location is C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files. This folder may even be on a different volume than your website data, making slower reads and writes.

If your hosting provider allows for this folder to be changed, add the following attribute to your web.config's compilation key:

tempDirectory="z:\shared\sites\example.com\temp"

Substitute z:\shared\sites\example.com\temp with the appropriate folder path for your site, make sure temp exists and is writeable. If, for some reason, your systems administrator doesn't allow you to change this setting, either contact them or transfer your website to Vevida.

Do I have more? Yes, I have more tips for you.

Some miscellaneous tips in a nutshell

In this last chapter I'll sum up some miscellaneous tips for you to further optimize Umbraco.

First tip is to always use SQLServer sessionState. Doing so enables your site to use more than one worker process ("web garden"), or even a load balanced web server farm (more than one web server for your site). Imagine that!

If possible, also configure a load balanced or mirroring set up for your SQL Server. Be sure to configure your SQL connection string accordingly using a Failover Partner:

Server=sql-a.example.com;
    Failover Partner=sql-b.example.com;
    Database=examplecom;
    User Id=examplecom;
    Password=my-password;"

Enable TLS/SSL encryption in your connection string, add Encrypt=True and TrustServerCertificate=True, like:

Encrypt=True;TrustServerCertificate=True;

Secondly, disable Umbraco's keepAlive feature. It's not necessary in these days. You find this setting in ~/Config/umbracoSettings.config, look for the key keepAlive and its attribute disableKeepAliveTask (defaults to false, set it to true).

Third, the use of HTTP Expires headers is explained in my earlier mentioned Saotn.org post.

Conclusion

In this small post, I provided you with a number of great tips to improve and optimize Umbraco 8's performance and loading speed. I hope you enjoyed reading this article.