Top Banner
Karine Bosch SharePoint MVP Boosting Performance on Publishing sites #SPSBE #SPSBE14
30

Karine bosch caching-spsbe14

May 13, 2015

Download

Technology

BIWUG

You can build very attractive sites but if your pages don't render within the second, you will be out of visitors in no time. Highly performing SharePoint sites can be a true challenge.
In this session I will explain how the different caching mechanism can highly improve the performance of your SharePoint Publishing site.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Karine bosch caching-spsbe14

Karine BoschSharePoint MVP

Boosting Performance on Publishing sites

#SPSBE

#SPSBE14

Page 2: Karine bosch caching-spsbe14

A big thanks to our sponsorsPlatinum Sponsors

Gold Premium Sponsors

Gold Sponsors

Venue Sponsor

Page 3: Karine bosch caching-spsbe14

About me

• SharePoint MVP since 2008

• Technical assistent of Patrick Tisseghem till September 2008

• Developer of the U2U CAML Builder

• Technical Lead SharePoint Competence Center @ ING

• Blog: http://karinebosch.wordpress.com

• Twitter: kbosie

Page 4: Karine bosch caching-spsbe14

Agenda

• Introduction

• Caching data

• Techniques to reduce the page load

• Tools to measure performance

Page 5: Karine bosch caching-spsbe14

Introduction

• Data is stored in SQL Server database

• User requests require data

• No caching limits scalability

• SharePoint caches run on the WFE(s)

• Caches maintain copies of data locally on WFE

• User requests are served from cache on WFE

No Caching

1. HTTP GET

2. SQL Get Data

3. Data Returned

4. HTTP Response

Page 6: Karine bosch caching-spsbe14

Types of Caching

• Caching data

• BLOB Cache => caches files stored in the content database

• IIS Cache => caches files stored in the _layouts folder

• Output Cache => caches .aspx pages

• Object Cache => caches data objects

• Require addintional system resources

Page 7: Karine bosch caching-spsbe14

BLOB Cache

• BLOB = Binary Large Object

• BLOB cache is configured on Web Application level in web.config

• BLOB cache stores files from content database on a local directory of each WFE

• Images, CSS files, JavaScript files

• Second request serves file from disk

• Tradeoff:

• Extra roundtrips to SQL Server to fetch file

• Cache Invalidation

Page 8: Karine bosch caching-spsbe14

BLOB Cache

• BLOB Cache is highly optimized to serve anonymous requests

• Images and SiteCollectionImages library have AllowEveryoneViewItems property set to True.

• No SQL Server roundtrip to check user ACLs

• Adds cache control headers to HTTP Responses to save file in user’s browser cache

Page 9: Karine bosch caching-spsbe14

BLOB Cache

• BLOB Caching is useful when

• Resources are frequently accessed

• Rich media is used (videos, etc)

• BLOB Caching is less useful when

• Resources are not frequently accessed

• Files are modified frequently

Page 10: Karine bosch caching-spsbe14

Configuring BLOB Cache

• BLOB Cache is configured in web.config of WFE

• Local directory on WFE

• Files with specific extensions

• List of extensions can be configured

• Size limit

<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" max-age="86400"

enabled="true"/>

Page 11: Karine bosch caching-spsbe14

Demo

BLOB Cache

Page 12: Karine bosch caching-spsbe14

IIS Cache

• Files stored in _layouts/images folder of WFE

• Files are cached on local browser cache

• Default invalidation period: 365 days

Page 13: Karine bosch caching-spsbe14

Demo

IIS Caching

Page 14: Karine bosch caching-spsbe14

Output Cache

• SharePoint Server uses ASP.NET output cache

• In-memory cache that stores rendered ASPX pages per ASP.NET application

• Reduces CPU load and SQL Server roundtrips

• In SharePoint Server only Publishing pages can be cached

• Publishing Feature fetches page layout and then content of the page

• Configured per site collection

• Output Cache is highly optimized for anonymous access

• Memory requirements:

• (2 x page size) + 32 KB of memory per rendered copy of a page

Page 15: Karine bosch caching-spsbe14

Output Cache Profiles

• Configuration of Cache profiles

• Specify the different variants of a page that can be stored in cache

• Vary By

• Default cache profiles

• Organaized by

• user access rights

• Browser type

Page 16: Karine bosch caching-spsbe14

Configuring Output Cache

• Following features must be enabled:

• Publishing Infrastructure site collection feature

• Publishing site feature

• Site collection settings

> Site collection output cache

• Enable output cache check box

Page 17: Karine bosch caching-spsbe14

Configuring Cache Profiles

• Cache Profiles specify the different variants of a page that can be stored in cache

• Site collection settings > Site collection cache profiles

• Fields that can be configured

• Enabled

• Duration

• Check for Changes

• Vary By Parameter

• Perform ACL check

• …

Page 18: Karine bosch caching-spsbe14

Demo

Output Cache

Page 19: Karine bosch caching-spsbe14

Object Cache

• Stores data objects in-memory on WFEs

• Publishing features must be activated

• Some SharePoint artifacts use object cache mechanism by design:

• Cross-list Query Cache

• Content By Query Web Part

• PortalSiteMapProvider API

• Search Query Box

• Metadata navigation

• HttpRuntime.Cache

Page 20: Karine bosch caching-spsbe14

Object Cache

• Data is cached based on user rights

• PortalSuperUserAccount

• PortalSuperReaderAccount

• Cache invalidation

• Size: allocate 500KB RAM per site collection

Page 21: Karine bosch caching-spsbe14

Configuring Object Cache

• Set up Portal Super Accounts

• Site collection settings > Site collection object cache

• Tuning options

• Max size

• Flushing

• Cache Invalidation

$wa = Get-SPWebApplication -Identity "<WebApplication>"$wa.Properties["portalsuperuseraccount"] = "<SuperUser>"$wa.Properties["portalsuperreaderaccount"] = "<SuperReader>"$wa.Update()

Page 22: Karine bosch caching-spsbe14

HttpRuntime.Cache Code Sample

• ASP.NET cache class

• Cache key

• Lock before retrieving data from database

• Insert object(s) in cache for a certain period of time

string cacheKey = "BeersOfTheWeek";List<Beer> beerList = null;

// check the cacheobject o = HttpRuntime.Cache.Get(cacheKey);

if (o == null){ object lockHandle = new object(); lock (lockHandle) { // check again if cache is not filled again o = HttpRuntime.Cache.Get(cacheKey); if (o == null) { beerList = RetrieveWithQuery(); if (beerList != null) { // add the list to the cache HttpRuntime.Cache.Insert(cacheKey, beerList, null, DateTime.Now.AddMinutes(15.0), TimeSpan.Zero); } } else

beerList = (List<Beer>)o; }}else beerList = (List<Beer>)o;

Page 23: Karine bosch caching-spsbe14

Demo

Object Caching

Page 24: Karine bosch caching-spsbe14

Tools

• Tools to measure performance and page load

• Firebug

• Yslow

• Developer Dashboard

• SPMonitoredScope

Page 25: Karine bosch caching-spsbe14

Developer Dashboard

• Disabled by default

• Can be enabled via

• Object Model

• Stsadm

• PowerShell

• Display levels

• On

• Off

• On Demand

Page 26: Karine bosch caching-spsbe14

SPMonitoredScope

• Included for web parts

• Not included for custom controls

using (SPMonitoredScope breweryBannerScope = new SPMonitoredScope(“Brewery Banner control”)

{ // your code goes here}

Page 27: Karine bosch caching-spsbe14

Demo

Developer Dashboard and SPMonitoredScope

Page 28: Karine bosch caching-spsbe14

Reduce the Page Load

• Suppress JavaScript files and CSS files that are not used in anonymous mode

• Minimize JavaScript files

• Sprites

• Images

• CSS

Page 29: Karine bosch caching-spsbe14

Conclusion

• Improve performance using caching mechanisms:

• BLOB cache => files in document libraries

• IIS cache => files in _layouts folder

• Output cache => publishing pages

• Object cache => data objects

• Caching takes place on:

• Web front ends

• Client browser

Page 30: Karine bosch caching-spsbe14

We need your feedback!

Scan this QR code or visit http://svy.mk/sps2012be

Our sponsors: