Do you have no idea to deal with the performance of your SharePoint product?
Your SharePoint product executes very slowly! But what’s the reason? You are crazy to fix the issue position. If you know which method you have written that caused the performance issue, maybe it is easy to resolve the performance issue.
What happens today?
For SharePoint 2010, the developer dashboard is a wonderful approach to monitor the performance. You can see the result on the page which contains your product. First, turn on the developer dashboard (See section “About developer dashboard”). Second, click the developer dashboard switch on the top right corner of the page
. The developer dashboard view is as following:
Now you should add the monitor to all the method, what a hard work! But don’t worry, you can use the AOP interceptor the cover all the method (See section “About AOP”). The world is so nice! Is it?
About AOP:
The AOP framework can be used in security, handle exception, log and whatever the aspect scenario you can think of.
The following is the Spring.Net AOP framework custom interceptor example for SharePoint developing:
using System; using AopAlliance.Intercept; using Microsoft.SharePoint.Utilities; using BoostSolutions.PermissionTracking.Core.Exceptions; namespace BoostSolutions.PermissionTracking.Core.Aop.Interceptor { public class TimeConsumingInterceptor : IMethodInterceptor { #region IMethodInterceptor Members public object Invoke(IMethodInvocation invocation) { object returnValue = null; try { using ( var monitoredScope = new SPMonitoredScope(String.Format("[{0}: {1}]AOP for performance scope", invocation.TargetType.FullName, invocation.Method.Name))) { returnValue = invocation.Proceed(); } } catch (Exception exception) { throw new AOPWeavingException(exception); } return returnValue; } #endregion } }
You can see that the SPMonitoredScope wrapped the method block. The AOP framework generate the proxy class instance which intercept the real class instance by the custom interceptor. For more AOP information, please see the http://www.springframework.net/. Now all the method is under the monitoring!
The following is the AopProxyWrapper example:
public class AopProxyWrapper { public static ILog Log { private get; set; } public static TR GetProxy(T t) { return GetProxy(t, false, true); }
public static TR GetProxy(T t, bool isElevatePrivilege, bool isTimeConsuming) { if (Log == null) { throw new LogNullException(); } TR proxyObject = default(TR); ProxyFactory proxyFactory = new ProxyFactory(t); proxyFactory.AddAdvice(new SPDoesNotCatchAccessDeniedExceptionInterceptor()); proxyFactory.AddAdvice(new NotThrowExceptionInterceptor()); LogExceptionInterceptor logExceptionInterceptor = new LogExceptionInterceptor(); logExceptionInterceptor.Log = Log; proxyFactory.AddAdvice(logExceptionInterceptor); if (isElevatePrivilege) { proxyFactory.AddAdvice(new ElevatePrivilegeInterceptor()); } if (isTimeConsuming) { proxyFactory.AddAdvice(new TimeConsumingInterceptor()); } proxyObject = (TR)proxyFactory.GetProxy(); return proxyObject; } }
About developer dashboard:
Command Line to turn on or turn off the developer dashboard:
Location “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN”
Type the command and execute “STSADM -o setproperty – pn developer – dashboard – pv Ondemand (or “Ondemand” or “Offdemand”)”.
View the result:
Execute the product and then you can see the performance report in the developer dashboard!
The report shows that the “BoostSolutions.PermissionTracking.BLL.ScopeModule.ScopeManager: GetNodeInfo” method costs 114.87ms, the “BoostSolutions.PermissionTracking.BLL.ScopeModule.ScopeManager: GetCheckAccountChildNodeInfos” method costs 1211.75ms, the “BoostSolutions.PermissionTracking.BLL.PermissionLevelModule.PermissionLevelManager: GetAllPermissionLevels” method costs 20.36ms, the “BoostSolutions.PermissionTracking.BLL.RelationshipReportModule.TwoScopeRelationshipReportManager: GetRelationshipReport” method costs 965.10ms. And we can know the performance bottleneck are “GetCheckAccountChildNodeInfos” and “GetRelationshipReport” method.
You can monitoring the method performance now, and optimize the code method which cost the most time. Your customers will be very happy that you help them to save much time.