design and development performance considerations
DESCRIPTION
TRANSCRIPT
N E W Z E A L A N DSHAREPOINTCONFERENCEM A R C H 1 6 + 1 7 2 0 1 1
DESIGN AND DEVELOPMENT PERFORMANCE CONSIDERATIONS
Elaine van Bergen
ELAINE VAN BERGENARCHITECT OBS MELBOURNE
• SharePoint MVP
• Microsoft Virtual Technical Solutions Professional
• Co-organiser of Melbourne’s MOSSIG (Microsoft Office Special Interest Group) and SharePoint Saturday Melbourne
• @laneyvb on Twitter
• Blog at http://laneyvb.blogspot.com/
Dash Cache Log Dispose Querying Throttling
AGENDA
• Developer Dashboard
• Caching
• Logging
• Object Disposal
• Querying
• Throttling
Dash Cache Log Dispose Querying Throttling
HOW TO ENABLE
• Object Model
• PowerShell
• STSADM
Dash Cache Log Dispose Querying Throttling
MASTERPAGE PLACEMENT<Sharepoint:DeveloperDashboardLauncher
ID="DeveloperDashboardLauncher"
NavigateUrl="javascript:ToggleDeveloperDashboard()"
runat="server"
ImageUrl="/_layouts/images/fgimg.png"
Text="<%$Resources:wss,multipages_launchdevdashalt_text%>"
OffsetX=0
OffsetY=78
Height=16
Width=16 />
<div id="DeveloperDashboard" class="ms-developerdashboard" />
<SharePoint:DeveloperDashboard runat="server" />Dash Cache Log Dispose Querying Throttling
SPMONITORED SCOPEusing (SPMonitoredScope monitoredScope = new SPMonitoredScope("Monitor My Code"))
{ LongRunningCall(); }
SPCriticalTraceCounter.AddDataToScope(99, "What happened ?", 15, "Add additional info here");
1 Critical
4 Exception (Watson)
6 Assert
8 Warning
10 Unexpected
15 MonitorableDash Cache Log Dispose Querying Throttling
SHOW YOU SOMETHING COOLDEV DASHBOARD
DevDashVis
• http://devdashvis.
codeplex.com
Dash Cache Log Dispose Querying Throttling
TYPES OF CACHE
• Output – Generated HTML for future requests
• Object – Common objects and query results
• BLOB – Commonly requested files put on WFE disk
http://download.microsoft.com/download/7/F/0/7F069D0B-B6BD-4692-868B-E8555BB72445/SharePointServerCachesPerformance.docx
Dash Cache Log Dispose Querying Throttling
CACHING
OUTPUT
• Stores rendered aspx pages
• Enable output cache at site collection
• Time to live vs. Check for Changes
• Each page uses 2x+32 KB of memory
• Highly flexible with Cache Profiles
Dash Cache Log Dispose Querying Throttling
PROFILE OPTIONS
• Perform ACL Check
• Enabled
• Duration
• Check for changes
• Vary by custom , http header ,query string ,user rights
• Cachability
• Safe for authenticated use
• Allow writers to view cached contentDash Cache Log Dispose Querying Throttling
PROFILE OPTIONS ADVANCED
• Per page layout
• Cache profile overrides for host header site collections avavilable for:• varyByHeader
• varyByParam
• varyByCustom
• varyByRights
• cacheForEditRights
Dash Cache Log Dispose Querying Throttling
OBJECT
• Used by publishing, content by query web part, navigation, search query box, and metadata navigation
• Via code e.g. PortalSiteMapProvider
• Draft vs published = PortalSuperUserAccount and PortalSuperReaderAccount
Dash Cache Log Dispose Querying Throttling
CONFIGURING OUTPUT ACCOUNTS
• Super Reader = web policy read
• Super User = web policy full
• Not run as system
• Dedicated accounts not app pool or login
Dash Cache Log Dispose Querying Throttling
CACHE MULTIPLIER
Dash Cache Log Dispose Querying Throttling
1-10Visible with
edit permissions
11-20 Visible to
members of group x
21-30Visible to everyone
31-40Visible to everyone
Visible to super-user
Visible to super-readerVisible to super-user
Visible to super-reader
BLOB
• On disk on each WFE
• Best for infrequently changed css, js and images or large video
• Video is normally buffered from SQL on WFE adding latency, BLOB cache is nearly equivalent of IIS direct
• Adds http range support
Dash Cache Log Dispose Querying Throttling
BLOB
• Configured per web application
• Extended web app has it’s own blob cache
• Long url’s can break blob cache (server relative > 160 characters)
• Can affect and be corrupted by IIS recycle if large
• Optimised for anonymous
Dash Cache Log Dispose Querying Throttling
BLOB CACHE INVALIDATING
• Edit, Delete cached file = file removed
• Delete file not cached, delete folder, rename/delete list, change permissions, title, description, add/remove content type = all files in list removed
• Rename/delete web, add/remove permissions, change inheritance, add/update/delete roles = all files in web removed
• Delete site collection = all files in site collection removed
• Change user policy at web application = entire cache abandoned
Dash Cache Log Dispose Querying Throttling
CONFIGURING
• <BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="false"/>
• Max-Age is optional , defaults to 86400 seconds (1 day)
• Also tune the IIS app pool startup and shutdown to > 300 seconds
Dash Cache Log Dispose Querying Throttling
BRANDING STORAGE LOCATION
• SharePoint Library• User Centric
• Blob Cache can help
• Different libraries may have varied results for anonymous
• _Layouts• Default SharePoint Max Age
• Custom Virtual Directory or dedicated web app
Dash Cache Log Dispose Querying Throttling
CACHING DESIGN FOR IMAGES/CSS AND VIDEO
• MAX AGE determines when to reload
• Authors want it to change asap
• Version CSS/Image to ensure reload
• For examples Myfile1.1.css
Dash Cache Log Dispose Querying Throttling
CACHING OBJECTS VIA CODE
• Consider if object is thread safe
• SPWEB is not therefore any item with embedded web like SPSListItemCollection can cause issues
• Lock and cache to object such as datatable
Dash Cache Log Dispose Querying Throttling
private static object _lock = new object();
public void CacheData() {
DataTable oDataTable;
SPListItemCollection oListItems;
lock(_lock) {
oDataTable = (DataTable)Cache["ListItemCacheName"]; If(oDataTable == null)
{
oListItems = DoQueryToReturnItems();
oDataTable = oListItems.GetDataTable(); Cache.Add("ListItemCacheName", oDataTable, ..);
}
}
} Dash Cache Log Dispose Querying Throttling
SHOW YOU SOMETHING COOLCACHE
LOGGING
Dash Cache Log Dispose Querying Throttling
DISPOSE
• It’s complicated !
• 64 bit helps hide the problem for longer
• Not just memory, SPRequest = 1:1 SQL connection
• http://blogs.msdn.com/b/rogerla
Dash Cache Log Dispose Querying Throttling
DO NOT DISPOSESPContext.Current.Site
SPContext.Current.Web
SPContext.Site
SPContext.Web
SPControl.GetContextWeb(..)
SPControl.GetContextSite(..)
SPFeatureReceiverProperties.Feature.Parent
SPItemEventProperties.ListItem.Web
SPList.BreakRoleInheritance() Do not call list.ParentWeb.Dispose()
SPListEventProperties.Web
SPListEventProperties.List.Web
SPSite.RootWeb Problems may occur when SPContext.Web has equality to the SPContext.Web.. make sure you dispose of SPSite and it will cleanup sub webs automatically
SPSite.LockIssue
SPSite.Owner
SPSite.SecondaryContact
SPWeb.ParentWeb
SPWebEventProperties.Web
Dash Cache Log Dispose Querying Throttling
SHAREPOINT 2010 CHANGES
• Microsoft.SharePoint.WebControls.SiteAdminsitrationSelector.CurrentItem 2007 must dispose, 2010 don’t
• Event Recievers• Properties.OpenWeb() – 2007 dispose of SPWeb
• SPItemEventProperties.Web instead and no dispose
Dash Cache Log Dispose Querying Throttling
DISPOSE MONITORING
• SPDisposeCheck
• ULS Logs
• Memory Internals
• SQL Server Connections
Dash Cache Log Dispose Querying Throttling
QUERYING METHODS
• Search Object model solid performed but delayed data
• PortalSitemapProvidor if data is low and relatively static
• SPListItems GetDataTable and SPQuery for list data retrieval
• For each is the last option
http://office.microsoft.com/download/afile.aspx?AssetID=AM102377231033
Dash Cache Log Dispose Querying Throttling
CONTENT ITERATORSPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name=\"MyIndexedField\"/><Value Type=\"Text\">FieldValue</Value></Eq></Where>" + ContentIterator.ItemEnumerationOrderByNVPField;
ContentIterator ci = new ContentIterator();
ci.MaxItemsPerQuery = 500;
ci.ProcessItemsInList(query,
delegate(SPListItem item)
{
// Work on each item.
},
delegate(SPListItem item, Exception e)
{
// Handle an exception that was thrown while iterating. // Return true so that ContentIterator rethrows the exception. } );
Dash Cache Log Dispose Querying Throttling
THROTTLING TYPES
• List Throttling
• Row and Column Throttling
• Http Request
• Unique Permissions
• You can add your own
Dash Cache Log Dispose Querying Throttling
LIST THROTTLING
• Any operation that impacts x amount of items is throttled
• Default is 5000 items, beware of table locks if you change
• Overrides for auditors and administrators only in OM
• Machine admin overrides all throttle limits
• Happy hour(s)
Dash Cache Log Dispose Querying Throttling
COMMON OPERATIONS THAT ARE THROTTLED
• Create, remove, delete an indexed field
• Add, Modify indexing on field
• Delete list
• Save list as template
• Sort , Filter by non-indexed field
• Delete site
• Change field uniqueness
• Show totals
• Change list relationship state on field
• Enable disable attachments
LIST THROTTLING WITH METADATA NAV
• Retry Query with different indexed fields
• Fallback query for subset of data
• Enabled for all lists in the web once metadata navigation feature is enabled
• Just via the UI not the OM
Dash Cache Log Dispose Querying Throttling
LIST THROTTLING VIA CODE
using (SPSite site = new SPSite (“http://site”))
{
using (SPWeb web = theSite.RootWeb)
{
SPList list = web.Lists[“Listname”];
SPQuery query = new SPQuery();
query.QueryThrottleMode = SPQueryThrottleOption.Override;
//setup query here
SPListItemCollection collection = list.GetItems(query);
//do something with your data here
} Dash Cache Log Dispose Querying Throttling
HEALTH SCORE
• Health score is given back as part of the http headers X-SharePointHealthScore
• 0 is healthiest, 10 is the worst
• Office applications such as workspace use adaptive sync based on health score
• Consider use if performing high load operations remotely
Dash Cache Log Dispose Querying Throttling
HEALTH SCORE
Dash Cache Log Dispose Querying Throttling
AGENDA RECAP
• Developer Dashboard
• Caching
• Logging
• Object Disposal
• Querying
• Throttling
Dash Cache Log Dispose Querying Throttling
Questions ?
Gold Sponsors
Silver Sponsors
Bronze Sponsors