LinkedIn

Tuesday, December 10, 2013

Developing for performance in our SharePoint 2010

Some key concepts when it comes to developing for performance in our SharePoint 2010 applications.
SharePoint 2010 Developer Dashboard
The developer dashboard is a perfect tool for anyone who wants a quick way to access information about what goes on while rendering a page in SharePoint. It contains information about Web Parts, events, DB calls and a whole lot of nifty information.
Activating the Developer Dashboard
Developer Dashboard is a utility that is available in all SharePoint 2010 versions, and can be enabled in a few different ways:
PowerShell
STSADM.exe
SharePoint Object Model (API’s)
SPMonitoredScope to track performance in your applications
The monitored scope (SPMonitoredScope) is a class you can use to monitor performance and resource usage in your applications by using it in a simple code block.
The pros about using the monitored scopes are of course that you can easily track down and find bottlenecks as well as do some initial performance monitoring while doing your development.
Using SPMonitoredScope
In order to use the SPMonitoredScope you’ll need to add a using statement for Microsoft.SharePoint.Utilities and then wrap your code in a statement like this:
using (new SPMonitoredScope("CallMethod1 Monitored Scope"))
{
    Controls.Add(new Literal {Text = "Awesomeness
"});
}
You don’t need to add any more code than this in order for it to be hooked up.
Some caching techniques in SharePoint 2010

In SharePoint 2010, there’s a few different ways to cache data. In this section you can read about a few of those approaches. Most of the caching techniques I use regularly as a developer derives from or is a direct usage of the capabilities of the .NET framework.
Output Caching (Configurable)
The concept of Output Caching is something that natively comes with SharePoint 2010, as it builds on and relies on ASP.NET caching techniques. This means that you can configure your SharePoint 2010 site to cache the Pages it outputs. The reasoning behind caching a page is obviously that it takes time to generate the content on any page, and on a heavily accessed site it would be a performance impact to generate a new page on every request – that’s where Output Caching comes in handy.
BLOB cache overview
The disk-based BLOB cache controls the caching for binary large objects (BLOBs), such as frequently used image, audio, and video files, and other files that are used to display web pages, such as .css and .js files. The BLOB cache is enabled on a front-end web server and improves performance by retrieving BLOB files from the database and storing them in a directory on the front-end web end server where they are served to users. This reduces the network traffic to and load on the database server.
For example, if you have an Internet-facing portal with read-only files such as .doc or .pdf files, you can specify that those files be cached so that they are displayed more quickly to users. If you have a collaboration site that contains files that are frequently updated, and also media assets, you can specify that the cache is to store only audio or video types by including only file name extensions for those files in the cache settings.

Enable the BLOB cache

The BLOB cache is configured in the web.config file for each Web application and, by default, is not enabled. You must specifically enable the BLOB cache in order to get the performance advantage it provides.

Specify the size of the BLOB cache

When you decide how large to make the BLOB cache, you must consider the number and size of the files to determine the total size of the data to be stored in the cache. By default, the BLOB cache is set to 10 gigabytes (GB). Allow at least 20 percent more space on the drive than the size of the cache. For example, if you have 10 GB of content, set the size of the cache to 12 GB on a drive that has at least 15 GB of space. If the BLOB cache is too small, serving files to users slows, reducing the performance of your site.

Bit Rate Throttling
This section contains information about Bit Rate Throttling, describes when you should use it with the SharePoint solution, and explains how to enable it.

Bit Rate Throttling overview

Bit Rate Throttling is an IIS 7.0 extension that meters the download speeds of media file types and data between a server and a client computer. The encoded bit rates of media file types such as Windows Media Video (WMV), MPEG-4 (MP4), and Adobe Flash Video, are automatically detected, and the rate at which those files are delivered to the client over HTTP are controlled according to the Bit Rate Throttling configuration.

Decide to use Bit Rate Throttling

If you will make long-playing video assets available to users in SharePoint Server 2010, enable Bit Rate Throttling in IIS. Without Bit Rate Throttling, IIS will serve video files by using as much bandwidth as it can, which will result in increased network performance

Maximum upload file size

This section describes the upload file size limitation, tells how to decide what the maximum upload file size limit should be, and how to configure it.

Maximum upload file size overview

The maximum upload file size is a setting that is used by the SharePoint Server 2010 Web application that specifies the maximum size of a file that a user can upload to the server. When a new Web application is created, SharePoint Server 2010 sets the default maximum upload size to 50 MB.

Caching in code (Programmable)

While we know that there’s pre-configurable caching available in SharePoint 2010 (like the Output Cache and BLOB Cache), there’s obviously still a need to create custom caching routines in your applications.
In order for your custom applications to run efficiently and save on server load, you need to consider the importance of using proper caching in your applications.
For instance, if you’ve created an application that is (on every request) fetching information from a database or a SharePoint list (SPList), do you really need that data to be fetched directly from the source – or could you live with having it cached for a few minutes? If it’s not super-important data we’re dealing with that doesn’t need to be up to date every second and every request – please consider building some caching mechanisms in your applications

Developer Dashboard is a utility that is available in all SharePoint 2010 versions, and can be enabled in a few different ways:
a)     PowerShell
b)     STSADM.exe
c)      SharePoint Object Model (API’s)
SharePoint 2010 and CSS Sprites

CSS sprites is a technique used to reduce the number of requests for images on a site when visiting it. Take a bunch of separate images and smack them together to one single file. Voila, you’ll only need to request one file from the server. CSS sprites are a natural part of a normal SharePoint 2010 installation. By default, there’s CSS sprite techniques used to render and display images in (for example) the Ribbon menu. CSS sprites are that you can develop web applications that can reduce the page load and enhance the performance of your sites and make them load quicker and be more responsive

1 comment: