3 notes &
Don’t trust Modules!
One of the powers of Orchard is a gallery filled with useful modules. Just install them and you’re good to go. But if you want to build a high-performance website with Orchard CMS, you’re gonna have to do more than that. The modules are really generic and that could cost you in performance. Also, they’re contributed by the community, and not everyone has the performance focus you might need.
Output Caching module
The output caching module for instance, does a terrific job at outputcaching. If I had built it myself it wouldn’t be as flexible with a cms module where editors can change the cachetime per route and even invalide specific cache entries. But for my application it can be modified to greatly increase the response times of a cached page.
For each page that is outputcached, the OutputCacheFilter computes a CacheKey that’s unique for this specific url and serversettings by joining the url, tenant, culture and themeid.
private string ComputeCacheKey(ActionExecutingContext filterContext)
{
var keyBuilder = new StringBuilder();
keyBuilder.Append("tenant=").Append(_shellSettings.Name).Append(";");
keyBuilder.Append("url=").Append(filterContext.HttpContext.Request.RawUrl.ToLowerInvariant()).Append(";");
foreach (var pair in filterContext.ActionParameters)
keyBuilder.AppendFormat("{0}={1};", pair.Key, pair.Value);
keyBuilder.Append("culture=").Append(_workContext.CurrentCulture).Append(";");
keyBuilder.Append("theme=").Append(_themeManager.GetRequestTheme(filterContext.RequestContext).Id).Append(";");
return keyBuilder.ToString();
}
In my application each tenant has its own culture. So I don’t need both of them in my cachekey. When I take out the line that includes the CurrentCulture, the page response time drops from 45ms to 5ms!
SecureSocketsLayer module
The SecureSocketsLayer also gets executed for each page request (even the outputcached ones!). In it’s filter is the following code:
var settings = _services.WorkContext.CurrentSite.As<SslSettingsPart>();
This does multiple database queries and costs about 40ms. On an outputcached page that’s a lot of unneccesary overhead!. In my specific application I only needed to do one area over SSL. So I put the setting (EnableSSL) in the AppSettings, and created my own filter with a tiny piece of code.
var wishedPort = 80;
if (UseSsl)
{
var area = filterContext.Controller.ControllerContext.RouteData.Values["area"];
if (area != null && area.ToString() == "Viaselect.Checkout")
wishedPort = 443;
}
Conclusion
When you install a module, take a good look at the code! The developer might have made choices differently than you would have made them. And sometimes it’s a really quick fix to tune a module and benefit from it’s extra’s!