Karine bosch caching-spsbe14

Post on 13-May-2015

633 views 2 download

Tags:

description

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.

Transcript of Karine bosch caching-spsbe14

Karine BoschSharePoint MVP

Boosting Performance on Publishing sites

#SPSBE

#SPSBE14

A big thanks to our sponsorsPlatinum Sponsors

Gold Premium Sponsors

Gold Sponsors

Venue Sponsor

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

Agenda

• Introduction

• Caching data

• Techniques to reduce the page load

• Tools to measure performance

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

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

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

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

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

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"/>

Demo

BLOB Cache

IIS Cache

• Files stored in _layouts/images folder of WFE

• Files are cached on local browser cache

• Default invalidation period: 365 days

Demo

IIS Caching

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

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

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

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

• …

Demo

Output Cache

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

Object Cache

• Data is cached based on user rights

• PortalSuperUserAccount

• PortalSuperReaderAccount

• Cache invalidation

• Size: allocate 500KB RAM per site collection

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()

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;

Demo

Object Caching

Tools

• Tools to measure performance and page load

• Firebug

• Yslow

• Developer Dashboard

• SPMonitoredScope

Developer Dashboard

• Disabled by default

• Can be enabled via

• Object Model

• Stsadm

• PowerShell

• Display levels

• On

• Off

• On Demand

SPMonitoredScope

• Included for web parts

• Not included for custom controls

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

{ // your code goes here}

Demo

Developer Dashboard and SPMonitoredScope

Reduce the Page Load

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

• Minimize JavaScript files

• Sprites

• Images

• CSS

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

We need your feedback!

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

Our sponsors: