A Workload-Driven Unit of Cache Replacement for Mid-Tier Database Caching
“Caching In” for SharePoint · 2010-06-13 · Object caching Recommendations Be careful with...
Transcript of “Caching In” for SharePoint · 2010-06-13 · Object caching Recommendations Be careful with...
“Caching-In” for SharePoint
Performance
Sean McDonough
Product Manager, SharePoint Products
Idera
Session overview
Caching 101
Understanding each of SharePoint’s
platform caching options
How to leverage and control caching
Warnings and watch-outs
Q&A
Why I care about caching
• Formerly the architect for a Fortune 50’s
publicly facing SharePoint presence
• Highly trafficked environment – ~75,000 page views per hour peak (2009)
– Usually 40 SP-hosted assets per page or more
– Greater than 1000 requests/second into IIS
• Supported with a single farm (4 WFEs)
• Tired of “SharePoint doesn’t scale” claims
Caching 101
Cache: what is it?
Web Part caching
post-cache substitution
Office viewing service cache
virtual memory
disk-based caching
BLOB cache
page-output cache
in-memory cache
object cache
browser cache
edge caching
cacheability headers
buffer fragment caching
CARP
ICP
HTCP
Cache: what is it?
• A temporary storage area where frequently
accessed data can be stored for rapid
access
• Rapid access facilitated in two ways Data is placed on a faster medium
Data is moved closer to point of usage
• Typically used for data that is expensive to
fetch or calculate
Why caching for SharePoint?
Consider a page request from a client Page rendering requires constituent control rendering
w/ merging of file system & DB data
Each page request can generate multiple DB lookups
for content, navigation, security, etc.
Page itself links and references images, CSS,
JavaScript, and other resources
SharePoint request lifecycle is complex
Better performance, better user experience
SharePoint caching: whatcha got?
Of interest to administrators (and what I will
be discussing) Object caching
BLOB caching
Page output caching
Office web applications cache
Of interest but not included Dev-related caching (Web Part cache, ASP.NET cache,
IVaryByCustomHandler implementation, post-cache
substitution, fragment caching, etc.)
Caching in SharePoint
Some plumbing information
Caching activation “Turned on” with (Office)
SharePoint Server
Publishing Infrastructure
Potentially bad news Not part of WSSv3 or
SharePoint Foundation
Some caching can be
used with non-publishing
sites, though
Some plumbing information
How it’s wired-in Supported through the
PublishingHttpModule
HttpModule wired into the
ASP.NET request pipeline
of all SharePoint web apps
Management Through web UI,
STSADM, PowerShell, and web.config changes
Consider a sample page …
Object caching
Speeds access to
frequently referenced
structural, property,
and result data Navigational data
Query results (cross-list
and cross-site)
Site properties
Page layouts
Object caching
Structure and operation A memory-backed cache on each WFE
Only cache that is “on” by default
Cache is assigned per site collection
100MB allocation per site collection by default
Conservative cache durations employed to avoid
displaying or using stale data
Additional control with SharePoint 2010 <ObjectCache> in web.config to govern maximum size
Object caching
Getting to it Via Site Collection
Administration section
on Site Settings page
Site Collection Object
Cache link
Object caching
Configuration
options Object Cache Size
Object Cache Reset
Cross List Query
Cache Changes
Cross List Query
Results Multiplier
Object caching
Recommendations Be careful with the Object Cache Size allocation!
Cross List Query Cache Changes
• Off by default for MOSS, on by default for SharePoint 2010
• Turn off or reduce time if queries are run against volatile data
• Turn on to reduce system loading and increase response time
Cross List Query Results Multiplier
• Increase if per-site and per-list permissions are in use,
especially if per-item permissions are also applied in lists
• Reduce for sites where anonymous access prevails
BLOB caching
Improves efficiency
and speed of serving
BLOB (Binary Large
OBject) data in lists Images and icons
Audio files
Video (including Flash)
Cascading style sheets
Javascript
BLOB caching
Structure and operation Also known as “disk-based caching”
Cache is backed by file system storage on WFEs
Turned “off” by default
Enabled and disabled per IIS web site
Disk allocation, file types cached, and client
cacheability settings are configurable
BLOB caching
Yields performance
improvements through (up to)
two different offloads Once enabled, reduces network traffic
between WFEs and content databases
Can also reduce load on WFEs by
instructing client browsers to cache
New in SharePoint 2010 HTTP byte range support, throttling
BLOB caching
Getting to it Accessed through the
web.config for each IIS site
What can be configured File system cache location
Pattern of files to be cached
Maximum disk space cache
can consume
Client cacheability (max-age)
Some service-related params
BLOB caching
<BlobCache> element in MOSS 2007
<BlobCache> element in SharePoint 2010
max-age attribute Easily added to yield client-side caching of BLOB assets
Client will use local assets without round-trips to server
BLOB caching
Recommendations Turn it on (that is, set enabled=“true”)
Adjust the location attribute to point to a data disk
Ensure enough disk space on WFEs to support sum of
maxSize attribute values (in GB) across web.config files
Do not attempt to manually manage BLOB cache contents.
• Do not delete individual cached files
• Use built-in flushes (2010) or CodePlex add-on (2007)
• If required, cache folder associated with IIS web site can be
deleted, but only when associated app pool is spun-down
If using the max-age attribute, understand the implications
Page output caching
Allows pages that
were rendered for
one user to be
stored and served to
other users
Piggybacks on
ASP.NET’s output
caching mechanism
Page output caching
Structure and operation Pages are rendered and stored in memory by key
• Key is composed of attributes specified by a caching profile
• Users with matching attributes can be served cached page
Cache is enabled per site collection
Page output cache is off by default
Primarily managed through a system of profiles
Additional control in SharePoint 2010 <OutputCacheProfiles> override in web.config file
Page output caching
Profiles specify caching characteristics User equivalence (cache key generation) criteria
How long pages are cached
Whether or not to check for updates on each request
How pages are cached on server and client
Custom caching parameters
Profiles can vary based on access type Authenticated profile assignment
Anonymous profile assignment
Page output caching
Step 1 Review the cache
profiles that are defined
• Via Site Collection
Administration section
on Site Settings menu
• Site Collection Cache
Profiles link
Create your own
profiles if desired
Page output caching
Step 2 Apply caching profiles
for site collection
• Via Site Collection
Administration section
on Site Settings menu
• Site Collection Output
Cache link
Indicate if profiles can
vary by sub-site and
layout page type
Page output caching
Step 3 Optionally apply
different profiles to sub-
sites as needed
• Via each Site
Administration section on
Site Settings menu
• Site Output Cache link
Inheritance model used
Can push down the
hierarchy with checkbox
Page output caching
Step 4 Optionally apply
different profiles per
page layout type
• Via Galleries section on
Site Settings menu
• Master Pages And Page
Layouts link
• Edit properties of target
page layout
• Save and check-in
Page output caching
Step 5 Enable output cache
• Via Site Collection
Administration section
on Site Settings menu
• Site Collection Output
Cache link
Optional debug info
can be written as
HTML comments to
bottom of each page
Page output caching
Recommendations Biggest bang comes in purely anonymous usage scenarios
• Caching becomes less attractive as user equivalence drops
Perform extensive multi-user concurrent testing before
implementing in production
• Test each profile scenario in-use (authenticated/anonymous)
• Test deviation scenarios (per-site/per-layout profile use)
• Failure to tune properly can result in information “leaking” from
one user to another
Debug cache information is your friend
• Helps you understand how page was evaluated and rendered
Office Web Apps Cache
Specific to SharePoint 2010
Office Web Apps Cache
What it is A standard SharePoint site collection (Team Site)
• Relative URL: /sites/Office_Viewing_Service_Cache
Office Web Apps Cache Creation timer job creates it
Houses rendered images and XAML for Office docs
One created per web application
Defaults Allowed to grow to 100GB
Documents live for 30 days until they are removed by the
Office Web Apps Expiration timer job
Office Web Apps Cache
Recommendations Relocate cache to a dedicated database using
Set-OfficeSPWebAppsCache PowerShell cmdlet
• Once in its own DB, it can be excluded from backups
For web apps housing largely static Office docs
• Increase cache expiration period
• Increase cache size
For web apps where Office content is volatile
• Decrease cache expiration period
• Decrease cache size
Warnings and Watch-outs
Object caching
ACTION Cache size reduced (significantly) below 100MB
POTENTIAL RESULT Object cache fills and becomes memory constrained
Resource contention and ejections lead to cache compactions
Under heavy load, nature of compaction process leads to thrashing
SharePoint’s ability to serve pages falls through the floor
WHAT TO WATCH Total Number Of Cache Compactions perf counter
Publishing Cache Hit Ratio perf counter
Page output caching
OBSERVATION User A requests a page. User B requests same page.
User B sees information tied to User A
POTENTIAL CAUSE Page output cache profile isn’t granular enough
WHAT YOU CAN DO Refine the output profile in-use (use additional attributes)
Set caching exclusions by sub-site or page layout type
Use post-cache substitution (donut caching) in custom code
Leverage custom caching handler (IVaryByCustomHandler)
Page output caching
OBSERVATION Memory consumption of ASP.NET worker process
grows significantly; performance may deteriorate
POTENTIAL CAUSE Too many pages being cached (excessive memory load)
WHAT YOU CAN DO Adjust caching profiles if possible to reduce page load
Selectively disable caching for highly varying sub-sites
Adjust cache element values in web.config that control
ASP.NET worker process (e.g.,privateBytesLimit)
BLOB caching
OBSERVATION Path property is set correctly, but images stored in site
collection aren’t being cached in file system
POTENTIAL CAUSE BLOB cache only works with resources that are stored within
list items in lists or document libraries
WHAT YOU CAN DO Leverage built-in libraries such as Site Collection Images
Move resources to a custom list
BLOB caching
OBSERVATION Image is changed on a SharePoint site. Some client
browsers show new image, others show old image.
POTENTIAL CAUSE max-age attribute is in-use with BLOB caching
WHAT YOU CAN DO Instruct clients to clear their browser cache
Avoid using the max-age attribute with web apps serving
site collections housing very volatile BLOB content
This behavior is by design
Questions?
References and Resources
“Caching in Office SharePoint Server 2007” http://technet.microsoft.com/en-us/library/cc298466(office.12).aspx
“Configure cache settings for a Web application
(SharePoint Server 2010)” http://technet.microsoft.com/en-us/library/cc770229.aspx
“Disk-Based Caching for Binary Large Objects” http://msdn.microsoft.com/en-us/library/aa604896.aspx
“Manually Clearing the MOSS 2007 BLOB Cache” http://sharepointinterface.com/2009/10/30/manually-clearing-the-moss-
2007-blob-cache/
References and Resources
MOSS 2007 Farm-Wide BLOB Cache Flushing Solution http://blobcachefarmflush.codeplex.com/
“Manage the Office Web Apps cache” http://technet.microsoft.com/en-us/library/ee837422.aspx
“MOSS Object Cache Memory Tuning is not an Intuitive
Process” http://sharepointinterface.com/2009/08/30/moss-object-cache-memory-
tuning-is-not-an-intuitive-process/
“cache Element for caching (ASP.NET Settings Schema)” http://msdn.microsoft.com/en-us/library/ms228248.aspx
Contact information
Sean McDonough Blog: http://SharePointInterface.com
Email: [email protected]
LinkedIn: http://www.linkedin.com/in/smcdonough
Twitter: @spmcdonough
The SharePoint 2007 Disaster Recovery Guide
http://tinyurl.com/SPDRBook
The SharePoint 2010 Disaster Recovery Guide http://tinyurl.com/SPDRBook2010