Improving Sharepoint Performance: Caching, Indexing, And Tuning Recommendations

Accelerating SharePoint with Caching

Caching is a technique that stores previously retrieved or computed data for future requests. By serving cached data instead of dynamically generating content, web applications like SharePoint can significantly improve response times and throughput. This section provides an overview of caching capabilities in SharePoint and recommendations for enabling and configuring caching to accelerate page loads, asset delivery, and object queries.

Overview of Caching in SharePoint

SharePoint 2013 and later versions have various cached data stores that optimize different workloads:

  • Output cache – Caches full page output and fragments for anonymous web server requests
  • Object cache – Caches objects like site maps and global navigation state
  • Blob cache – Caches byte arrays and file content
  • Metadata cache – Caches CDS metadata for knowledge management
  • Security token cache – Caches security tokens for authentication

These cached data objects skip expensive database queries and business logic processing. SharePoint also supports distributed caching configurations for multi-server farms.

Enabling Output Caching for Pages and Site Assets

Output caching is very effective for accelerating anonymous page views. This is configured in the SharePoint GUI:

  1. Navigate to a site, library, list, or page
  2. Click the Settings gear icon and choose Site Settings or Library/List Settings
  3. Under Site Administration or Library/List Administration, select Output Cache
  4. Check the box for Enable Output Caching, specify cache duration
  5. Select cache profiles and security trimming options

This will cache all anonymous page requests for the configured duration. Authenticated user requests are not cached by default. Caching duration depends on content volatility.

Configuring Object Cache Settings for Better Performance

The Object Cache provides storage for frequently used site structure data:

  • Site maps – Cache site URLs, structure, and metadata
  • Navigation settings – Cache global and current navigation states
  • Page widgets – Cache configured web part instances

The Object Cache is enabled by default. The following PowerShell commands configure its behavior:

# Get current cache configuration
Get-SPSite | Select -ExpandProperty ObjectCacheSettings 

# Set cache duration 
Set-SPSite -Identity "" -ObjectCacheEnabled:$true -ObjectCacheTTLInSeconds 3600

This caches site structure data for faster rendering of pages and navigation elements.

Example Configuration for Distributed Caching

SharePoint farms can leverage distributed caching to one or more dedicated cache host servers:

# Enable MinRole feature 
Enable-SharePointFeature -Identity Id_MinRoles

# Define cache hosts 
$cacheHosts = @("CacheHost1","CacheHost2")

# Enable cache role and assign hosts
Set-SPCacheHostConfig -CachesizeInMB 2048 -ServiceInstance CacheCluster1 -Server $cacheHosts

# Point sites to cache cluster  
Get-SPSite | Set-SPSite -Zone CacheCluster1 -CachePortNum 22233

This distributes cached data across a cache cluster to avoid storage limits and bottlenecks on application servers. The effect is multiplied with more cache hosts.

Indexing Content for Faster Queries

Search indexing crawls SharePoint content on a schedule to collect metadata used for fast query responses. Managing the search index and customizing crawl scopes, priorities, and frequencies can optimize search performance.

How Search Indexing Works in SharePoint

The main components that power SharePoint search are:

  • Search service application – Manages the search topology and components
  • Index partitions – Shards that store the indexed search corpus
  • Content sources – Defines roots and scopes of content to crawl
  • Crawl rules – Filters and transforms crawled properties
  • Crawl schedules – Sets frequencies and priorities for crawls

Optimizing these configurations focuses crawls on important content and builds a right-sized index for responsive search queries.

Best Practices for Managing Search Index

Follow these best practices around sizing, monitoring, and maintaining the search index:

  • 10-15 million total items per index partition
  • Monitor index partitions for growth trends
  • Rebalance partitions before they reach 30 million items
  • Set failover and backup indexes for high availability
  • Follow a “Continuous Crawl” methodology

This keeps index size in check and avoids costly full crawls. Failing over keeps search running if an index goes offline.

Tuning Crawl Schedules and Priorities

Customize the following configurations to focus crawls:

  • Content sources – Only index relevant sites and libraries
  • Crawl schedules – Frequent crawls for important sources
  • Crawl priorities – Higher priority for key sites
  • Crawl rules – Filter unwanted content types
  • Custom scopes – Combined rules that fine-tune crawls

Continuous crawls will keep frequently changing content fresh in the index for better search results.

Example Code for Custom Indexing

SharePoint’s API provides events and methods to build custom indexing solutions:

function onItemUpdated(item) {

  // Add custom metadata properties  
  item.Properties["ReviewStatus"] = "Pending";
  
  // Index item immediately
  var indexer = new Search()
  .indexContent(item);

}

This indexes additional metadata not set by default crawls. Custom logic can respond to events and keep data synchronized with search.

Fine-Tuning Performance with Configuration Changes

SharePoint provides adjustable configurations that directly control request throughput, concurrency, timeouts, bottlenecks, and resource usage. Tuning these settings appropriately prevents slowdowns from emerging under load.

Adjusting Throttling Settings

The throttling settings protect SharePoint from excessive usage spikes. The PowerShell snippet below increases thresholds by 2-3x their defaults:

$farm = Get-SPFarm 

$farm.RequestThrottlingSettings.UserCodeMaximum = 3000
$farm.RequestThrottlingSettings.TotalTimeoutMinutes = 5
$farm.RequestThrottlingSettings.ReleaseTimerInterval = 120

$farm.Update()

Monitoring usage over time allows appropriately sizing limits for user activities and background operations.

Optimizing SharePoint Timer Jobs

Timer jobs handle maintenance tasks like search crawls, version clean up, and analytics processing. The following configures lighter touches:

$farm = Get-SPFarm

$job = $farm.TimerService.Instances | ? {$_.Name -like "*search*"}
$job.WorkloadManagementSettings.PeakUserModeMaxThreads = 15
$job.Update()

Too many concurrent threads can overload servers. Reducing thread counts for non-essential jobs prevents resource contention when utilization is high.

Monitoring Site Collections for Heavy Usage

Site collections delegate resources across end users and groups. The example PowerShell reports top contributors:

Get-SPSite | ForEach { 

  $usage = $_.Usage

  $report = "" | Select Site, Storage, Hits
  $report.Site = $_.Url
  $report.Storage = "$([math]::round($usage.Storage/1MB,2)) MB"  
  $report.Hits = $usage.Hits

  $report

} | Sort Hits -Descending | Select -First 10

These metrics help identify candidate sites for archival or transition to dedicated infrastructure.

Examples of PowerShell Scripts for Analysis

SharePoint provides detailed usage reports through its reporting APIs:

# Storage breakdowns
Get-SPWebApplication | Get-SPSite | Get-SPWeb | Select Title, {@{Name="SizeInMB";Expression={[int]($_.Usage.Storage/1MB)}}} | Export-Csv storage.csv

# Traffic and latency  
Get-SPSite | ForEach {New-Object PSObject -Property @{Url = $_.Url; Hits = $_.Usage.Hits; Latency = $_.Usage.AveragePageLatency}} | Export-Csv perf.csv 

These reports help identify usage trends across various SharePoint tiers over time.

Getting More Speed with Code Optimization

Custom SharePoint solutions can avoid inefficient patterns that tax resources. Applying caching, optimizing data access, monitoring performance, and using asynchronous logic improves customization code speed and scalability.

Techniques for Efficient SharePoint Development

Follow these best practices for performant custom code:

  • Retrieve only needed fields in queries
  • Minimize round trips with batched operations
  • Re-use common object instances
  • Wrap database calls in one retry logic
  • Use ExecuteQuery in batches within thresholds

Small tweaks compound gains over thousands of daily requests. Measure often with logs and debug data.

Using Caching for Custom Solutions

Cache expensive query results, service calls, and computations locally then serve from memory:

// In-memory cache
var cache = new Dictionary>();

// Wrap storage calls  
function getItems(listId) {

  if(cache.ContainsKey(listId)) {
    return cache[listId]; 
  }

  var items = storage.fetchListItems(listId);
  
  cache[listId] = items;

  return items;

}

This avoids redundant lookups by key. Cache expiration handles data staleness.

Asynchronous Operations for Better Responsiveness

I/O bound operations can use async/await to prevent blocking:

async function getItemDetails(itemId) {

  var cacheKey = `item_${itemId}`;
  
  if(cache[cacheKey]) {
    return cache[cacheKey]; 
  } 

  var result = await longRunningQuery(itemId);

  cache[cacheKey] = result;
  
  return result;

}

This delegates slow operations to background threads so the main app stays responsive.

Example of Async Calls in SharePoint Add-ins

SharePoint add-in code can safely use async POSTs and GETs:

function asyncGetListItems(webUrl, listName) {

  return new Promise(resolve => {

    $.ajax({
      url: `${webUrl}/_api/web/lists/getbytitle('${listName}')/items`, 
      type: "GET",
      headers: { "Accept": "application/json;odata=verbose" },
      success: resolve,
      error: resolve
    });

  });

}

Chaining these async operations prevents blocking the main JavaScript thread. Appropriate use removes delays in add-in responsiveness.

Leave a Reply

Your email address will not be published. Required fields are marked *