Arrow icon
Back to Insights

A tale of performance in Orchard CMS

October 23, 2012
Arra Derderian

This entry is about a two week battle I had to get a production Orchard CMS site able to handle a load of about 3,500 unique users a day and 250,000 hits a day. Originally, the site only had a few visitors a day and was built on Orchard 1.4. with a SQL Compact backend. The site itself has many content items and content types being pulled in on each page so there was a lot of database activity. Site traffic began to increase slowly and I first noticed the production issues when pages began taking more than 5 seconds to load and the CMS itself was taking upwards of 5 minutes to start-up from a cold start. The site was being pinned down by users hitting the site while the pages loaded and every page load was taking a long time to cycle back information from the database with each hit.

Some Basic Configuration Options

  1. Make sure the debug flag in the web.config is set to false. We all know this one right!
  2. Decide if your application can run in Full Trust. Sometimes you are OK with letting your application run in Full Trust as opposed to Medium Trust. This will give the application a little boost in speed.
  3. Build a precompiled version of your site so you can turn off dynamic compilation. This one is something I did not realize I could do. Basically, you will want to build the Orchard source code using the "build /t:precompile" flag. You need to add all your modules to the Orchard solution so they get built as well. Once you perform this build, you will have a new folder under build/MsDeploy. You will notice all of your modules have their dll's built in their bin folders. The final step is to rename the SampleHostComponents.config to HostComponents.config inside the Orchard/Config folder of the website folder. This tells Orchard to stop looking to dynamically compile the modules. This should shave some processing time off of your site.
  4. Turn off unused modules. This will make sure you are not executing code you don't need to.
  5. Be mindful of the amount of widgets/layers you are using. Always look to keep this as simple as possible.

After making these changes I noticed a change in my site's general page load time by about 500ms, but it was not something that was noticeable by a user who was navigating through a bunch of pages on my site. I needed to make more changes.

Some Larger Changes

  1. Install the MiniProfiler module and see where your site is actually taking the longest to respond. I installed this module and saw that my application was making a bunch of calls on the homepage for recent blog posts, navigation, recent press releases, and news articles. I needed a way to reduce these round trips to the database.
  2. Install the Contrib.Cache module. This module saved me because it allowed a page to be cached in memory using ASP.NET's output cache feature. This meant that once a page was cached it would be served out of memory and it did not need to fetch the data from the database anymore. This module also has an option to set a maxAge setting on the content so the pages will be served directly out of IIS and not even need to touch the application at all. If you have a generally static site this is good option. In my situation I could not utilize the maxAge setting because I had a multi-lingual site and the homepage of my site has the same URL in all different languages. I think there is a way around this, but I could not put in anymore time on it. The caching option was helping my site by offloading a lot of the traffic to the cache, but when a new user requested a different page it would slow everything down still.

The Crucial Change

  1. My site was struggling with the new load and I could not understand why. Once exception I was seeing a lot of was "Too Many Sessions To The Database" and also the high memory usage of the site was making me thinking the database was a bottleneck. As I said, I was using SQL Compact and I started to think it was time to swap out to full blown SQL Server. I spoke with the Orchard team and they said with the amount of traffic I was getting I really should be using SQL Server. I started to look into it, and I saw some blog posts indicating I could use WebMatrix to convert my SQLCE database to a SQL Server database.
  2. I first opened up Webmatrix and browsed to my Orchard site in the file system.
  3. I was then able to select the database in the user interface and choose "Migrate".
  4. You then select the target server for your database and click go. I only had one issue and that was a table (Syzmd.Navigation Module) was named too long. I basically renamed the table before the migration, and then named it back after.

After migrating to SQL Server my site experienced a great performance gain. 3-4 second page load times went down to 1.5s. I was able to navigate the site very smoothly and there was no more page timeouts. During time of high traffic the site stood strong and did not get bogged down at all. The high memory statistics I saw went away and the startup time for the site went back down to 20-30sec from five minutes.

Startup Improvements

  1. You can also install the Warmup Module from the gallery so that your startup times are deferred. This works by occasionaly saving a version of certain pages of your site and saves them off as static html. Then when your site is starting these static pages will be served to the user.

Orchard 1.6 Has Datbase Level Caching!

  1. Last, but certainly not least is the new SysCache module coming in 1.6! Install this module and it will automatically begin caching database calls. You can then have queries to the database reduced which is great. After all this you should see great improvements in your sites speed and load capability.

About the Author:

Arra Derderian serves as the President and as a Lead Technical Architect for Cloud Construct. As a founder at Cloud Construct, Arra is involved in all levels of the business from new project engagements, project planning, and development.

He also serves as the founder of the Boston Orchard CMS User Group and is a member of the Windows Azure Insiders group.

Arra graduated from Northeastern University School with a Bachelor of Science degree in Computer Science.

Author Photo
Arra Derderian
Founder & Chairman
Arrow icon
Back to Insights

Let's talk about your project

Drop us a note
Arrow
Or call us at:  
1.617.903.7604

Let's talk about
your project

Drop us a note
Arrow
Or call us at:
1.617.903.7604

Let's talk about your project

Drop us a note
Arrow
Or call us at:  
1.617.903.7604