SlideShare a Scribd company logo
1 of 58
Supercharge your Umbraco
The need for speed
Chris Gaskell
@CGaskell
chris@detangled-digital.com
The Web is a Demanding Place
The Need for Speed
In computing a cache is a component that
transparently stores data so that future
requests for that data can be served faster.
The data that is stored within a cache may be
values that have been computed earlier or
duplicates of original values that are stored
elsewhere.
http://en.wikipedia.org/wiki/Cache_(computing)
Who Caches Already?
Umbraco's Cache is Always Running
Need More?
Umbraco
• Macro Caching
• Partial View Caching
.NET
• Output caching
• Donut caching
Infrastructure
• Varnish
Good Old Fashioned Optimisation
• JS & CSS minification & combination
• Image resizing
• Sprite sheets
• Client side caching
• GZIP
Macro Caching
Macro Caching
The original way to reuse blocks of functionality.
How to:
1. Define macro in back office
2. Add cache policy
3. Call macro from within view
Macro Caching Demo
Macro Caching
The Good
• Quick and easy to setup with instant results
• No .NET
• Easy to retro fit or fine tune on an existing install
• Cache clears on CMS publish
• Support for querystring parameters so long as they’re passed to the macro as parameters
• @Umbraco.RenderMacro("pageList", new { addSleep = "[@addsleep]"
The Bad
• Difficult to turn off in dev (Macro cache disabler package doesn’t look to be compatible
with 6+)
• With MVC logic is moved into the view as there’s no chance to hijack the route
Cached Partials
Cached Partials
You don't normally need to cache the output of Partial views but there are
times when this is necessary. Just like with macro caching you can cache the
output of partial views.
This is done simply by using an HtmlHelper extension method:
@Html.CachedPartial("MyPartialName", new MyModel(), 3600)
The above will cache the output of your partial view for one hour (3600
seconds)
http://our.umbraco.org/documentation/Reference/Mvc/partial-views
Cached Partials Demo
Cached Partials
The Good
• Quick and easy to setup with instant results
• Easy to retro fit or fine tune on an existing MVC codebase
• As the cache duration is passed this could be taken from a configuration setting
and set to easily in dev to 0 secs
• Cache clears on CMS publish
The Bad
• MVC logic is moved into the view as there’s no chance to hijack the route
• If your view data changes the same cached output will be returned.
Please be aware: if you have a different model or view data for any page request,
the result will be the cached result of the first execution
Output Caching
Output Caching
Output caching is a full page cache.
Output caching is part of the .NET framework and can be easily used
with MVC or web forms applications.
In MVC output caching is implemented using an action filter attribute
which can be applied to controller actions.
Output Cache Demo
Output Caching
The Good
• Available ‘out of the box’ with ASP.NET – there’s nothing to install
• Easy and quick to implement
• Fast and robust
• Easy to share common cache ‘profiles’ across the app from config
The Bad
• Difficult to clear on a publish
• The entire page is cached making personalisation and dynamic content difficult to
manage
• Requires good management in development to ensure developers aren’t seeing
cached content
Donut Caching
Donut Caching
Donut caching is one form of output caching that is conspicuously absent
from ASP.NET MVC and is greatly missed by many developers.
To implement donut caching the concept is fairly simple:
1. Cache the page output and return it from the cache on subsequent
requests
2. Identify the areas that you do not want to cache (the donut holes). These
areas are marked so that when the page is retrieved from cache these
areas are replaced with non-cached versions before returning the page
Donut Cache Demo
Donut Caching
The Good
• Gives the huge benefit of having portions of the page render for each
request while the surrounding mark-up comes from cache
• Installs quickly (via nuget is best)
• Easy to add into a well architected MVC solution
• Has a cache manager allowing easy coupling to publishing for purging the
cache
The Bad
• Requires good management in development to ensure developers aren’t
seeing cached content
• Does need some extra code to ensure the cache is purged on publish
But what if you need to go even
faster?
Varnish
Story Time
Dresses
Give me
dresses
Here’s
some dress
data
I’ll make it
look nice
Oooo
some dresses
Hats
Has this
already been
requested?
No
Hats please
Here’s
some dataMake it
look nice
I’ll store this
for the next
request
Oooo
Hats!
Hats
Has this
already been
requested?
Yes
Oooo
Hats!
Zzzzzz
Zzzzzz
Varnish Cache is a web application accelerator also known as a caching
reverse HTTP proxy
You install it in front of any server that speaks HTTP and configure it to
cache the contents
Varnish Cache is really, really fast. It typically speeds up delivery with a
factor of 300 - 1000x, depending on your architecture
@bsdphk we have a new record on web
infrastructure reduction: From 46 to 5
servers!! @varnishcache rocks!
€0.00
Infrastructure
RAM is what counts to allow the cache to scale. How much RAM
depends on your requirements.
• With varnish you configure the size of the cache
• Varnish also needs memory to do other things, so you'll see a fixed
couple of hundred extra megs.
• Varnish has a overhead of about 1k per object.
• Each thread (e.g., worker) will allocate its own memory, including a
stack. This memory usage will scale and contract as load spawns and
reaps threads.
Installation on Ubuntu
To use the varnish-cache.org repository, do the following:
1. curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-
key add -
2. echo "deb http://repo.varnish-cache.org/ubuntu/ precise varnish-
3.0" | sudo tee -a /etc/apt/sources.list
3. sudo apt-get update
4. sudo apt-get install varnish
Installing on Windows?
“Remember that Varnish on Cygwin Windows is not recommended
for productions sites and it is only a proof-of-concept that can be
used to test application on Windows or for checking you VCL while in
that platform.”
https://www.varnish-cache.org/trac/wiki/VarnishOnCygwinWindows
Inside Varnish
When a web page or content is requested:
Check if the content is cacheable
If content is in cache
Return cached content
Else
Fetch content from Web server
Put the content in the cache
Return content
Else
Return by fetching from Web server
/etc/varnish/default.vcl
/etc/varnish/default.vcl
backend default {
.host = "umbracocaches.detangled-digital.com";
.port = "80";
}
sub vcl_recv {
set req.http.host = "umbracocaches.detangled-digital.com";
if (req.request == "GET" || req.request == "HEAD") {
return (lookup);
}
}
sub vcl_fetch {
# Remove Expires from backend, it's not long enough
unset beresp.http.expires;
# Set the clients TTL on this object
set beresp.http.cache-control = "max-age=900";
Varnish Demo
Grab your internet enabled device and
navigate to
http://bit.ly/1ozG165
Refresh the page and watch the timestamp
jump
http://bit.ly/1ozG165
Now have a look at the same page through
Varnish
http://bit.ly/1hjTPCK
All well and good, but what happens when I
publish content changes?
Cache Invalidation
• purge; removes all variants of an object from cache, freeing up
memory
• ban(); can be used to invalidate objects based on regular expressions,
but does not necessarily free up memory any time soon
/etc/varnish/default.vcl
backend default {
.host = "umbracocaches.detangled-digital.com";
.port = "80";
}
sub vcl_recv {
set req.http.host = "umbracocaches.detangled-digital.com";
if (req.request == "PURGE") {
return (lookup);
}
if (req.request == "GET" || req.request == "HEAD") {
return (lookup);
}
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
Purge on Publish
public class VarnishCachePurger : ApplicationEventHandler
{
private const string VarnishHost = "varnish.umbracocaches.detangled-digital.com";
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication,
ApplicationContext applicationContext)
{
ContentService.Published += ContentServiceOnPublished;
ContentService.Deleted += ContentServiceOnDeleted;
ContentService.Moved += ContentServiceOnMoved;
}
private static void ContentServiceOnPublished(IPublishingStrategy sender, PublishEventArgs<IContent>
{
foreach (IContent item in e.PublishedEntities)
{
PurgeUrl(library.NiceUrl(item.Id));
}
}
private static void ContentServiceOnDeleted(IContentService sender, DeleteEventArgs<IContent> e)
Real Life Umbraco VCLs
/etc/varnish/default.vcl
backend default {
.host = "detangled-digital.com";
.probe = {
.timeout = 10s;
.interval = 20s;
.threshold = 2; }
}
# --------------------------------------------------------------------------------
# vcl_recv
# --------------------------------------------------------------------------------
sub vcl_recv {
# Set the port and host header on requests so that the correct back-end website is targeted
set req.http.Host = regsub(req.http.Host, ".varnish.dev$", ".dd.dev"); # Dev
set req.http.Host = regsub(req.http.Host, ":d+$", ""); # Staging
# Handle ban request
if (req.request == "BAN") {
if (!req.http.X-Ban-Key ~ "6e035c2b-6109-4fed-9b44-7fec75cfe3f8") {
error 405 "Not allowed";
Load Testing
Load Testing the Demo
Without Varnish With Varnish
What Else
• Load Balancing
• Can be configured as round-robin or random
• Probing
• This accesses the heath of the application servers and can take servers in and out of
the balancing pool
• Serving stale cache
• Should the application server go down Varnish can serve a ‘stale’ cache
• A Large set of monitoring and logging commands
• https://www.varnish-cache.org/docs/4.0/reference/index.html
Thanks to Mike Gregson
@mpgregson
Get the sample code
https://bitbucket.org/chrisgaskell/umbraco-caches
See it integrated into a V7 example
https://bitbucket.org/chrisgaskell/gemscafe
Chris Gaskell
@CGaskell
chris@detangled-digital.com

More Related Content

Recently uploaded

Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 

Recently uploaded (20)

Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Supercharge your umbraco

  • 3. The Web is a Demanding Place
  • 4. The Need for Speed
  • 5. In computing a cache is a component that transparently stores data so that future requests for that data can be served faster. The data that is stored within a cache may be values that have been computed earlier or duplicates of original values that are stored elsewhere. http://en.wikipedia.org/wiki/Cache_(computing)
  • 7. Umbraco's Cache is Always Running
  • 8. Need More? Umbraco • Macro Caching • Partial View Caching .NET • Output caching • Donut caching Infrastructure • Varnish
  • 9. Good Old Fashioned Optimisation • JS & CSS minification & combination • Image resizing • Sprite sheets • Client side caching • GZIP
  • 10.
  • 11.
  • 13. Macro Caching The original way to reuse blocks of functionality. How to: 1. Define macro in back office 2. Add cache policy 3. Call macro from within view
  • 15. Macro Caching The Good • Quick and easy to setup with instant results • No .NET • Easy to retro fit or fine tune on an existing install • Cache clears on CMS publish • Support for querystring parameters so long as they’re passed to the macro as parameters • @Umbraco.RenderMacro("pageList", new { addSleep = "[@addsleep]" The Bad • Difficult to turn off in dev (Macro cache disabler package doesn’t look to be compatible with 6+) • With MVC logic is moved into the view as there’s no chance to hijack the route
  • 17. Cached Partials You don't normally need to cache the output of Partial views but there are times when this is necessary. Just like with macro caching you can cache the output of partial views. This is done simply by using an HtmlHelper extension method: @Html.CachedPartial("MyPartialName", new MyModel(), 3600) The above will cache the output of your partial view for one hour (3600 seconds) http://our.umbraco.org/documentation/Reference/Mvc/partial-views
  • 19. Cached Partials The Good • Quick and easy to setup with instant results • Easy to retro fit or fine tune on an existing MVC codebase • As the cache duration is passed this could be taken from a configuration setting and set to easily in dev to 0 secs • Cache clears on CMS publish The Bad • MVC logic is moved into the view as there’s no chance to hijack the route • If your view data changes the same cached output will be returned. Please be aware: if you have a different model or view data for any page request, the result will be the cached result of the first execution
  • 21. Output Caching Output caching is a full page cache. Output caching is part of the .NET framework and can be easily used with MVC or web forms applications. In MVC output caching is implemented using an action filter attribute which can be applied to controller actions.
  • 23. Output Caching The Good • Available ‘out of the box’ with ASP.NET – there’s nothing to install • Easy and quick to implement • Fast and robust • Easy to share common cache ‘profiles’ across the app from config The Bad • Difficult to clear on a publish • The entire page is cached making personalisation and dynamic content difficult to manage • Requires good management in development to ensure developers aren’t seeing cached content
  • 25. Donut Caching Donut caching is one form of output caching that is conspicuously absent from ASP.NET MVC and is greatly missed by many developers. To implement donut caching the concept is fairly simple: 1. Cache the page output and return it from the cache on subsequent requests 2. Identify the areas that you do not want to cache (the donut holes). These areas are marked so that when the page is retrieved from cache these areas are replaced with non-cached versions before returning the page
  • 26.
  • 28. Donut Caching The Good • Gives the huge benefit of having portions of the page render for each request while the surrounding mark-up comes from cache • Installs quickly (via nuget is best) • Easy to add into a well architected MVC solution • Has a cache manager allowing easy coupling to publishing for purging the cache The Bad • Requires good management in development to ensure developers aren’t seeing cached content • Does need some extra code to ensure the cache is purged on publish
  • 29. But what if you need to go even faster?
  • 32. Dresses Give me dresses Here’s some dress data I’ll make it look nice Oooo some dresses
  • 33. Hats Has this already been requested? No Hats please Here’s some dataMake it look nice I’ll store this for the next request Oooo Hats!
  • 35. Varnish Cache is a web application accelerator also known as a caching reverse HTTP proxy You install it in front of any server that speaks HTTP and configure it to cache the contents Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture
  • 36. @bsdphk we have a new record on web infrastructure reduction: From 46 to 5 servers!! @varnishcache rocks!
  • 38. Infrastructure RAM is what counts to allow the cache to scale. How much RAM depends on your requirements. • With varnish you configure the size of the cache • Varnish also needs memory to do other things, so you'll see a fixed couple of hundred extra megs. • Varnish has a overhead of about 1k per object. • Each thread (e.g., worker) will allocate its own memory, including a stack. This memory usage will scale and contract as load spawns and reaps threads.
  • 39. Installation on Ubuntu To use the varnish-cache.org repository, do the following: 1. curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt- key add - 2. echo "deb http://repo.varnish-cache.org/ubuntu/ precise varnish- 3.0" | sudo tee -a /etc/apt/sources.list 3. sudo apt-get update 4. sudo apt-get install varnish
  • 40. Installing on Windows? “Remember that Varnish on Cygwin Windows is not recommended for productions sites and it is only a proof-of-concept that can be used to test application on Windows or for checking you VCL while in that platform.” https://www.varnish-cache.org/trac/wiki/VarnishOnCygwinWindows
  • 41. Inside Varnish When a web page or content is requested: Check if the content is cacheable If content is in cache Return cached content Else Fetch content from Web server Put the content in the cache Return content Else Return by fetching from Web server
  • 43. /etc/varnish/default.vcl backend default { .host = "umbracocaches.detangled-digital.com"; .port = "80"; } sub vcl_recv { set req.http.host = "umbracocaches.detangled-digital.com"; if (req.request == "GET" || req.request == "HEAD") { return (lookup); } } sub vcl_fetch { # Remove Expires from backend, it's not long enough unset beresp.http.expires; # Set the clients TTL on this object set beresp.http.cache-control = "max-age=900";
  • 45. Grab your internet enabled device and navigate to http://bit.ly/1ozG165
  • 46. Refresh the page and watch the timestamp jump http://bit.ly/1ozG165
  • 47. Now have a look at the same page through Varnish http://bit.ly/1hjTPCK
  • 48. All well and good, but what happens when I publish content changes?
  • 49. Cache Invalidation • purge; removes all variants of an object from cache, freeing up memory • ban(); can be used to invalidate objects based on regular expressions, but does not necessarily free up memory any time soon
  • 50. /etc/varnish/default.vcl backend default { .host = "umbracocaches.detangled-digital.com"; .port = "80"; } sub vcl_recv { set req.http.host = "umbracocaches.detangled-digital.com"; if (req.request == "PURGE") { return (lookup); } if (req.request == "GET" || req.request == "HEAD") { return (lookup); } } sub vcl_hit { if (req.request == "PURGE") { purge;
  • 51. Purge on Publish public class VarnishCachePurger : ApplicationEventHandler { private const string VarnishHost = "varnish.umbracocaches.detangled-digital.com"; protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ContentService.Published += ContentServiceOnPublished; ContentService.Deleted += ContentServiceOnDeleted; ContentService.Moved += ContentServiceOnMoved; } private static void ContentServiceOnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> { foreach (IContent item in e.PublishedEntities) { PurgeUrl(library.NiceUrl(item.Id)); } } private static void ContentServiceOnDeleted(IContentService sender, DeleteEventArgs<IContent> e)
  • 53. /etc/varnish/default.vcl backend default { .host = "detangled-digital.com"; .probe = { .timeout = 10s; .interval = 20s; .threshold = 2; } } # -------------------------------------------------------------------------------- # vcl_recv # -------------------------------------------------------------------------------- sub vcl_recv { # Set the port and host header on requests so that the correct back-end website is targeted set req.http.Host = regsub(req.http.Host, ".varnish.dev$", ".dd.dev"); # Dev set req.http.Host = regsub(req.http.Host, ":d+$", ""); # Staging # Handle ban request if (req.request == "BAN") { if (!req.http.X-Ban-Key ~ "6e035c2b-6109-4fed-9b44-7fec75cfe3f8") { error 405 "Not allowed";
  • 55. Load Testing the Demo Without Varnish With Varnish
  • 56. What Else • Load Balancing • Can be configured as round-robin or random • Probing • This accesses the heath of the application servers and can take servers in and out of the balancing pool • Serving stale cache • Should the application server go down Varnish can serve a ‘stale’ cache • A Large set of monitoring and logging commands • https://www.varnish-cache.org/docs/4.0/reference/index.html
  • 57. Thanks to Mike Gregson @mpgregson
  • 58. Get the sample code https://bitbucket.org/chrisgaskell/umbraco-caches See it integrated into a V7 example https://bitbucket.org/chrisgaskell/gemscafe Chris Gaskell @CGaskell chris@detangled-digital.com

Editor's Notes

  1. Freelance .NET Web Developer chris@detangled-digital.com Developing with .net since 2001, using ASP3 and VB6 beforehand Organise the Manchester Umbraco Meetup Working mostly with digital agencies around Manchester
  2. Complex web applications Adapting or responding to a wealth of devices Real time integration Availability Content management
  3. People want web pages fast – really fast Mobile devices are often on slow connections and webpages are becoming increasingly complex, speed is important.
  4. Who in the audience already caches? Umbraco caches .NET Caches Infrastructure caches
  5. Don’t go mental! Umbraco has many caches over the data layers and request pipeline. XML Cache Content types Document types Domains Languages
  6. There are a number of ways we can bolster Umbraco installs by leveraging caches. Some are from the web, some from Umbraco a number from .NET and the rest by means of infrastructure
  7. Before I get started with fancy caches don’t forget about…. Most will already consider the above Not to mention how page speed helps with SEO
  8. Let me introduce you to.. Rather than constantly trying to memorise datetime stamps welcome to the supercharger-o-meter Powered by a HTTP module timing from OnBegingRequest to the end of the request. It shows a percentage of 8seconds and the actual loadtime in ms [Show the code]
  9. I’m going for zero demo fail, but this is caching! All the demo code is available on bitbucket, url at the end The caching demos are Umbraco, MVC and linux based – what could possibly go wrong?
  10. First up macro caching
  11. Partial is a reusable MVC component, it’s like just having the HTML part of a usercontrol. The HTML helper method is what’s important…
  12. Starting to move away from Umbraco…. Anyone used output caching with Umbraco? We’re going to take a look att he MVC variant of the output cache.
  13. When the action is executed for the first time, the OutputCacheAttribute intercepts the ActionResult before the output is returned to the client and stores this output for a configurable period of time. Then on subsequent requests the output is returned from the cache rather than executing the controller action.
  14. Clearing on publish can be difficult. Two options Set a short duration say 10 seconds Use the varybycustom and insert a static identifier. Update the identifier on publish.
  15. Moving towards a more customised version of output caching
  16. Available as a nuget package Built on top of output cachine
  17. This should give you an idea. The donut is static (cached) the whole is new each time. Or maybe this picture just made you hungry?
  18. Cache manager allows management and clearing of cached items
  19. But what if you want to go even faster? Cant change the codebase Concerned with cache overhead on your application server You’re proxying content from other sites You have embedded feeds You need some extra redundancy You don’t want to load balance…
  20. But what if you want to go even faster?
  21. Here’s a typical web request, there’s no varnish here and lets imagine the developer hasn’t implemented any output type caches. My wife’s called Gem and she likes dresses: So Gem askes a website for some dresses The webserver asks the database for some dresses The database finds some dresses and gives them to the webserver The webserver creates some HTML based on the data The HTML goes back to Gem
  22. Here we’ve added varnish Gem also likes hats: So she askes a website for some hats She hits varnish, but no one has ever asked for hats So varnish asks the webserver The webserver asks the database for hats The database finds some hats and gives them to the webserver The webserver creates some HTML based on the data The HTML goes back to varnish which will store it for the next request Varnish passed the HTML to Gem, who was a little tired of waiting.
  23. An hour later Gem has found my credit card and wants the hat So she askes a website for the same hats She hits varnish Varnish realises it’s already been asked for this So Varnish passes the HTML to Gem, who’s amazed with the speed The others servers haven’t done anything and are happily having a rest
  24. A real world implementations here 46 to 5 servers! And how much does this all cost….
  25. Varnish is free software licensed under a two-clause BSD licence, also known as the FreeBSD licence.
  26. RAM is what really counts for bigger sites Gigabit networking. Varnish can easily saturate 100mb networks
  27. Typical installation on a Ubuntu server
  28. Varnish can be executed on Windows using  Cygwin DLL. It’s not for production, but handy for testing and developing.
  29. Here’s a brief overview of a request going through varnish We can add code to each of the ‘methods’ shown in the path. The extra configuration code we add to the file is executed before the
  30. The VCL language is a small domain-specific language designed to be used to describe request handling and document caching policies for Varnish Cache. The basic syntax of VCL is reasonably straight forward. It is inspired mainly by C and Perl The functions of VCL are not true functions in the sense that they accept variables and return values. To send data inside of VCL, you will have to hide it inside of HTTP headers Your VCL code is executed before the standard Varnish VCL. So you are simply adding to the built in configuration rather than starting from scratch
  31. So you can get up and running easily with the base configuration
  32. DEMO – Stop the site on the amazon VPS
  33. Demo publish event
  34. Purge and ban are the two cache clearing options Call Varnish with the ‘PURGE’ verb by convention
  35. Show how purge is handled Purge is not implemented out of the box
  36. To purge a URL the convention is to call Varnish with the PURGE verb. We can then hook this up onto the CMS publish event. You may want to do this differently, say by calling PURGE from a scheduled task or similar – depends on your solution
  37. Of course for a ‘real’ application things are a little more complex. There are things to think about such as cookies and security on purges