Tuesday, November 25, 2014

Increase List items threshold in SharePoint

We think a lot if want to increase the list view items threshold for the web application because it will be applied to all the site collections that running under the same web application. When we work with list there are many question comes in our mind.

1. SharePoint list supports 3 million item in a list but if threshold limit is crossed the the user will not be able perform many operation including OOTB (Additional filter on list view, grouping, adding new filed or updating existing field). How to avoid such situation?

2. How to increase the threshold for a single list or single web(sub site)?

3. Are there any possibilities for viewing all items/ navigating to all items without any trouble?

4. How majorly system performance impacted if list view threshold increase for the total web application? Are there any best practices?

5. Why Server object model not returning all items from a view when fetching items from specific view?

6. Why OOTB view query is overriding custom CAML query when fetching specific view with CAML query?

and there are more question may arise if you dig further on SharePoint list.

But we can increase the List threshold for a specific list using server object mode / PowerShell scripts.

Server Object Model

using(SPSite site = new SPSite(@"http://kmsnet:5050"))
   foreach(SPWeb web in site.AllWebs)
     SPList lst=web.Lists.TryGetList("MyList");
     if(lst != null)


Add-PSSnapin Microsoft.SharePoint.PowerShell #-ErrorAction SilentlyContinue

$site = Get-SPSite -Identity "http://kmsnet:5050/"

foreach($web in $site.AllWebs)
   $web.AllowUnsafeUpdates = $True;
   if($list -ne $null)
        $list.EnableThrottling = $False;
        Write-Host "List Updated in web" $web.Title
   $web.AllowUnsafeUpdates = $False;

Wednesday, November 19, 2014

Caching techniques in SharePoint

SharePoint Server 2010 provides three types of caches that help improve the speed at which Web pages load in the browser.

1.       The BLOB cache.
2.      The Page Output Cache.
3.       The Object Cache.

Page output and object cache require that you activate the ‘SharePoint Server Publishing’ feature located in the site features of your web site.

BLOB cache:

SharePoint Server 2010 provides a disk-based cache that stores files that are used by Web pages to help them load quickly in the browser, and reduces the load on the database server when it uses those files. The BLOB cache is stored directly on the hard disk drive of a front-end Web server computer. By default, the BLOB cache is off and must be enabled to use the functionality it provides. When you enable the BLOB cache on your front-end Web server, you reduce the load on the SharePoint Server 2010 database server created by read requests from Web browsers. You enable the BLOB cache in the Web.config file of the Web application to which you want to apply it. The changes that you make to the Web.config file will be applied to all site collections within the Web application. To configure and Setup BLOB Caching read here.
  1. BLOB cache should be used when pages that are accessed frequently have JavaScript, CSS, images files, and large rich media files that can be cached on the WFEs
  2. It is recommended that you not set the cache size smaller than 10 GB for BLOB Caching. When you set the cache size, make sure to specify a number large enough to provide a buffer at least 20 precent bigger than the estimated size of the content that will be stored in the cache.
  3. For a publishing site for which most of the visitors are anonymous or where most of the files are static content, enable the BLOB cache for as many file types as possible.
  4. For other sites that contain lots of media assets that are read-only, or where only a small percentage of the media assets are updated, enable the BLOB cache for media files only.
  5. Make sure that you put the BLOB cache on a drive that has sufficient disk space available in front-end Web server which to store the cache.
  6. Select a drive that will be used by as few processes as possible so that the BLOB cache process does not encounter conflicts when it tries to access the drive
  7. If there is a high read to write ratio BLOB caching should be used. For instance you would want to cache a site logo that is used on every page request versus a collaboration word document that is actively updated.
  8. BLOB caching is optimized for supporting large files which can significantly reduce bandwidth between the WFEs and SQL Server.
  9. BLOB caching is optimized to support cache control headers so that clients can cache small files which can reduce overall number of hits to the WFEs.
  10. If there is anonymous access, there can be dramatic improvements because permissions do not have to be validated for cache files.
  11. Client applications that use range requests can optimize load times to access large files.

Before you enable the BLOB cache, carefully consider the scenario in which you plan to use it. If your site will be used for heavy collaboration, enabling the BLOB cache might temporarily affect the performance of your site while the files to be cached are first written to the disk. After the files have been stored in the cache, site performance will improve, so take this into consideration when you decide whether or not to enable the cache. Base your decision to enable BLOB caching on the following criteria:
·         For a publishing site for which most of the visitors are anonymous or where most of the files are static content, enable the BLOB cache for as many file types as possible.
·         For other sites that contain lots of media assets that are read-only, or where only a small percentage of the media assets are updated, enable the BLOB cache for media files only.

Page output cache profiles:

The second caching option you have with SharePoint 2010 is ASP.net Output Cache. This is an in-memory cache that saves rendered ASPX pages. Using Output cache improves performance in two ways first it reduces the amount of SQL calls. Second it reduces workload on the WFE because pages do not need to be re-rendered. Along those lines if the pages are anonymous, then no SQL check needs to be done at all present the cached pages. Microsoft testing concluded a ninefold improvement in throughput when compared to having to render the page every time it was rendered. To configure and Setup Output Caching read here.
  1. The only catch for using Output Cache is that it can only be used in conjunction with publishing pages. It cannot be used with a collaboration site.
  2. Some examples of rules that can be capture in a cache profile would be to not cache if the requestor is a user who can edit pages to ensure they see the latest version of content.
  3. The cache profile also specifies rules for when a page is invalidated so that when the next request is made, it comes from the database.
  4. One of the main considerations for Output cache is the memory needed to support it. For each rendered page, 2(size of the page) + 32KB is needed to store the rendered page in memory.
  5. Output Cache should not be used with sites using a low read to write ratio because frequent changes to content make it hard to keep the cache fresh.
  6. On multi-WFE, output caching may affect consistency.

 Object cache

Object cache is the third caching option we have for SharePoint 2010. What Object cache does is stores metadata about SharePoint Server objects (like SPWeb, SPSite, SPList, etc.) on the WFEs. When a page is rendered, if there is data that needs to be retrieved through these objects, the SQL Server will not be hit. Features of SharePoint that uses Object cache are publishing, content query web part, navigation, search query box and metadata navigation. These features are specifically written to use the Object cache API instead of the SharePoint API directly. Developers writing custom functionality can also tap into the Object cache API. To configure and Setup Output Caching read here.
  1. The object cache cannot be disabled, and there is very little that can be configured. None of the out of box settings should have to be changed. Following article was written provides some additional information on this cache: Object Cache.
  2. They are normal ASP.net caching and can be a problem when Server data changes in case of multiple farm.
  3. It is recommended that you not set the cache size smaller than 3 MB.

Overall for caching we should keep in mind that any data where in Read/write ratio is less we should avoid caching. Only things which is static most of the time need to be cached like images etc.
When you flush the BLOB cache, you clear the contents of the BLOB cache for a Web application. This is useful if the BLOB cache becomes out of sync with the content. For example, after you restore a content database, the BLOB cache will be out of sync with the content. To correct that situation, you must flush the BLOB cache. The following procedure describes how to flush the BLOB cache for a Web application.

Important Information on Flushing:
a.       Flushing the BLOB cache for a Web application affects all site collections in the Web application.
b.      You cannot use the user interface to flush the BLOB cache. Instead, you use Windows PowerShell and the SharePoint object model to complete this task.
This is the link which tells you how to flush BLOB cache

Useful links

Configure Cache in SharePoint 2013

Custom Caching Overview

Output caching in SharePoint 2010

SharePoint 2010 developing for performance: caching-in-sharepoint-2010

Common coding issues in SharePoint caching

Machine caching in SharePoint 2010

Best coding practices