CdnSupport module preview
“A content delivery network or content distribution network (CDN) is a system of computers networked together across the Internet that cooperate transparently to deliver content most often for the purpose of improving performance, scalability, and cost efficiency, to end users.” - Wikipedia
This is the CdnSupport module used in Mats & Peters presentation on the EPiServer Day on client-side performance. It is an unsupported module that you can download in binary form and try yourself, it will probably end up either as an open open-source module or as part of the product.
Offloading the burden of delivering static files from the web server is one way of scaling out your system, its better to have one system optimized for delivering static content and another optimized for delivering dynamic content, right ? Another reason is that you want your static content cached closer to the user, hence making your site more responsive.
How does it work ?
It rewrites URL’s from:
“/image/logo.png”
..to:
“http://mydomain/cdn-1c8211e062cf469/image/logo.png”
The “mydomain“ is your CDN and the strange characters in the middle is the changed date of the file in hexadecimal form.
If you are using a CDN your file may end up cached on a server across the globe and it won’t get evicted until it expires (for example 1 day). That is why the module injects the changed date into the URL, as soon as you change the file the URL changes and you get fresh copies of the file. Simple but effective, thanks Tom Stenius for the idea.
Remember that most cache servers and CDN’s require you to set valid expiration date on your files to actually cache anything, this module will not do that for you.
Do I need a CDN to test this module ?
No, you can point it back to the origin site if you like to test it (or just utilize the fact that a browser limits the number of ports per domain name). You can also use a caching server like Varnish.
What CDN’s are supported ?
This module has been tested with EdgeCast and Akamai but should work with most of them like Limelight Networks etc. There are many others but some such as CacheFly only supports files stored on their servers so make sure they support “customer origin” if you are using this module.
Security
Links that it cannot get the changed date for are ignored. It also does a security check on VPP-files to make sure Everyone has Read access since the CDN will not be able to fetch it otherwise (they normally don’t forward cookies etc). If you are using files protected by some other mechanism this module will not work correctly.
Performance
URL’s are rewritten using the existing infrastructure of events in EPiServer CMS. A custom cache is used to speed up the changed-date lookup since there can be large amounts of resources per page that need to be parsed. The cache stores lookups for 10 minutes and up to 10,000 entries using a LFU-scheme for eviction.
Debugging
You can add “?cdn=off” to the URL to disable rewriting if you a member the Administrators group. You can also add “?cdn-microcache=debug” to see statistics on the custom cache.
Edit mode
This module will not rewrite any URL’s originating from a preview in edit mode or when you supply a version of a page.
TODO
There are three known areas that need more work:
- Need more performance testing on how this module affects the site, I've only done performance testing in unit tests and on Labs.
- There is no way to have different settings for different folders with static files, you can only have different settings for different templates by using the location-element.
- The internal cache will not expire instantly in load balanced scenarios (the changed date in the URL, not the actual file which get updated).
Installation
1. Add config-section (configuration->configSections):
1: <section name="cdnSupport"
2: type="EPiServer.CdnSupport.CdnSupportSection, EPiServer.CdnSupport"
3: allowLocation="true"/>
2. Add the actual config:
1: <cdnSupport enabled="true"
2: url="http://cacheserver"
3: timestamp="true"
4: extensions="*" />
3. Drop the DLL in bin-folder
4. Under Modules add this after the UrlRewriteModule:
1: <add name="CdnSupport"
2: type="EPiServer.CdnSupport.CdnModule, EPiServer.CdnSupport"
3: preCondition="managedHandler"/>
Download: EPiServer.CdnSupport.zip
I must say that this is a piece of art. According to the yahoo performance guidelines 80%-90% of the end-user response time is spent downloading components. This is a fact you should consider if you're looking for a dynamic cdn solution - a solution that probably will be much more expensive and have drawbacks for example regarding personalization.
Very nice indeed! This is great news for sites with global reach! Any plans for adding support for for Amazon CloudFront??
Cheers
/ Flalar
Not really, since CloudFront requires S3 (as far as I know). That would require some kind of syncing or virtual path provider for CMS<->S3. The current implementation assumed you store the files locally and use the CDN as a cache.->
Yupp, have been puzzling on the thought of using S3 as a file store for EPiServer… Might not be demand for such a solution but it sure would be a nice little personal r&d project
It sure sounds like a cool project!