Optimizing performance of MVC sites

This page contains recommendations that can help you optimize the performance of your MVC site.

Optimizing on-line marketing performance

For high-traffic websites that use the Kentico EMS on-line marketing functionality, we strongly recommend following the Best practices for EMS performance in MVC in addition to the recommendations listed below.

On this page

Loading data efficiently

Transferring data between storage spaces and the application can be one of the main performance bottlenecks. When retrieving content from the Kentico database (or other external sources), load only the data that you require in your views or other related code. In most cases, you do not need all data columns available in the source. The less data you retrieve, the faster your pages will be.

When loading data using the Kentico DocumentQuery or ObjectQuery API (for example via generated providers or in custom repositories and services), you can limit which data columns are loaded through the Columns method – specify the names of the required columns as an array of strings.

// Gets article data using a generated provider
IEnumerable<Article> articles = ArticleProvider.GetArticles()
	.Columns("NodeID", "NodeAlias", "NodeSiteID", "ArticleTitle", "ArticleText") // Limits the retrieved data columns
    .Path("/Articles/", PathTypeEnum.Children)

Tip: In custom repositories or services, you may often need to wrap and extend DocumentQuery or ObjectQuery calls from other classes or providers. In these scenarios, use the AddColumns method instead of Columns – this adds to the list of retrieved columns without overriding any columns specified by the previous call.

Caching data and page output

Whenever possible, use caching for retrieved data and the output of controller actions:

  • See Caching on MVC sites for more information.
  • To avoid displaying of outdated content, set up cache dependencies.
  • Use cache keys containing variables to cache different versions of dynamic content (for example different page output for each user).

Scaling out MVC sites

If your site's performance is not satisfactory after you have taken all possible steps to optimize the website's code, you can consider scaling your hosting environment to multiple web farm servers.

With the MVC development model, your MVC application and Kentico application should already be configured to run as servers in an automatic web farm (see Starting with MVC development). The web farm ensures that the MVC application invalidates cache according to content or setting changes made in the Kentico application and vice versa.

Licensing of the web farm servers works automatically for basic scenarios – see Kentico licensing for MVC applications for details.

If you wish to use a web farm to scale the site's performance, you can add further instances of the MVC application. We recommend using the following process:

  1. Develop and test the site in a web farm with two servers (one MVC application, one Kentico application).
  2. Deploy any number of additional instances of the same MVC application. Each instance must connect to the same Kentico database.

The automatic web farm mode automatically registers the new instances as web farm servers and ensures correct synchronization (among all instances of the MVC application and the Kentico application). One way to create a scalable website is to deploy your instance to cloud hosting.

If you need to scale the performance of the Kentico administration interface used to manage the site content and settings, you can also run multiple instances of the Kentico application in the web farm. In this scenario, you need to use one of the servers as the "primary" Kentico instance (for example for holding files shared by the entire web farm, such as locally stored search indexes).

Note: If you scale out to have more than the two basic web farm servers per MVC site (live site + administration), you need to have a license that supports the additional number of web farm servers.

Was this page helpful?