Tuesday, May 26, 2009

Working With the ANTS Profiler to Optimize SharePoint by Shereen Qumsieh


Background

Before I get into any detail about this particular problem and its eventual resolution, it might be helpful to provide a little background information about why we're doing this and how we got here. 
Windows SharePoint Services 3.0 (WSS 3.0) provides a very extensible solution platform for the professional Microsoft .NET developer and is becoming increasingly more popular among companies looking to build collaboration and workflow into their environment.
I have been working on a project for the past couple of weeks that consists of a Windows SharePoint Services 3.0 small server infrastructure and several custom application pages written in ASP.NET C# via the SharePoint Object Model. 
The focus of this post will be a small subset of what has been built to date. We'll call this piece the Master Data List. This Master Data List was created as a standard Custom List in SharePoint with several new columns created for the purposes of collecting data relevant to active projects for this department. It was decided early on that the standard newform.aspxeditform.aspx and dispform.aspx pages that come by default with the instantiation of a new list were not going to be sufficient for the purposes of this list. There were several reasons for this:

  • We wanted to dramatically change the layout of the page, including background colors on specific sections, fonts, hyperlinks etc.

  • We wanted complete controls over the types of validation we were doing

  • The page itself was to consist of some aggregated data, in the form of drop downs and data grids, that was being pulled from several different lists within the same site and presented on the editform.aspxand dispform.aspx pages

Problem

Because of the complexity of these pages and the amount of aggregation we were doing, the average loading time for the edit and display forms was about 30 seconds (give or take a few seconds). The objective of this performance evaluation was to bring down the total time for page load to less than 10 seconds which would be a more reasonable end user experience.

Solution

I did manage to eventually bring down the loading times to under 10 seconds, so a 70% increase in performance, with several different techniques which I will now discuss in some detail.
  1. The first thing I did for both the editform.aspx page and the dispform.aspx page was to remove all <asp:Label> objects and replace them with plain text. If I wasn't planning to manipulate the label object in any way in the code behind, there was no need to create a control of this type. Text was sufficient for these purposes.
  2. The second thing I did was to remove all Telerik textbox and combobox controls except where required and converted them to asp:dropdownlists and asp:textboxes.
  3. The third thing I did and the focus of this article was to leverage ANTS Profiler to find areas in my code that required optimizing. I am going to talk about this in some detail to outline my approach to doing this and how this helped with the performance tuning.

Configuring ANTS Profiler to work with SharePoint

To get started, you'll need to have some sort of development box already in place where your code has been deployed to. In my specific example, I had WSS 3.0 installed in a single server scenario, with all of my custom application pages stored in the _layouts directory.
Download and install the ANTS Profiler from here. They offer a free 14-day trial that will be enough to get you going. I really do recommend that any serious SharePoint developer or .NET developer have this tool in their tool belt.
Once the profiler is installed, RedGate has provided us with a really handy guide for setting up SharePoint to work with the profiler: http://www.red-gate.com/support/Knowledgebase/ANTS_Profiler/AP4SharePoint.pdf
I won't say much more on the installation steps for ANTS Profiler as they're pretty straight forward.
Once everything has been installed and configured, you can launch the ANTS Profiler. The following is a screenshot of what my profiler page looks like initially:
The above configuration was copied directly from the pdf I'd mentioned above. 
If you're comfortable with the settings, click on Start Profiling to get this going. If you encounter an error similar to the screen shot below, make sure the web site on the port you're trying to profile is stopped. ANTS Profiler needs to be able to launch the site on its own, so you can't have it running while attempting to do this. I run into this now and again when I forget to do that.

Working with ANTS Profiler to track down problem areas

Once the profiler has finished loading, you should now have a default window open to the root of your SharePoint web site.
After this page successfully loads, you'll notice that the profiler has already started gathering data on the initial page load of the SharePoint site. What you'll want to do next is navigate to page you're attempting to optimize. In my example, I type the following:
Hit enter, and the profiler will begin to do its job. Typically I wait for my page to load successfully and then I stop the profiler and begin to do the work of analyzing the results.
As you can see in my screenshot above, I have highlighted the region in the profiler that I want to analyze. If you pay attention when your page loads, you'll get a general idea of where you want to highlight in the time window. Looking at my page above, I can see immediately where the HOT regions are. These are the places I need to pay particular attention to immediately.
To show the source code, I click on the method I'm interested in. In my example, since the slowdown was primarily on Page_Load, that's what I want to drill down into. If I click on theASP._layouts_motorola_not_optimized_aspx.Page_Load method, my screen will refresh with a code view of my page:
The really neat thing about the ANTS Profiler is the way that the scroll bar on the right highlights in RED my problem areas so that I can jump to that part of the code quickly. One of the pieces I was able to optimize was myPopulateDropDownLists method that I had written. Using the profiler I noticed the following bit of code was taking over a second to load:
It would appear that the getDDLNames method, another method I had written, was taking a bit longer than it should to run. Further investigation showed that the reason for this came down to calls to theSPSecurity.RunWithElevatedPrivileges method taking on Page_Load 1.5 seconds to run. Since the SPSecurity.RunWithElevatedPrivileges method is a part of the SharePoint Object Model and not something I had written, I really couldn't optimize that method, I had to come up with a better way to limit the affect it had on my performance.
Within the PopulateDropDownLists method, I was populating a total of 8 drop down controls, each making a call do the getDDLNames method. This was resulting in a huge performance hit simply due to the number of times I was calling SPSecurity.RunWithElevatedPrivileges. I was able to improve the performance of this page by eliminating the getDDLNames method entirely and moving the elevation code up to thePopulateDropDownLists method and making a single call for all 8 drop down lists. As you can see, working with a tool like this makes it really easy to see into areas of your code that you might not have otherwise suspected for the slow down.
I also spent a bit of time going through other areas of my code where this elevation call was being made too many times. I consolidated all areas that required elevation into a single elevation block.
I used the profiler in other areas to optimize code that was not dry enough, and to remove methods that could be architected in better ways. I found that by going through the profiler results and comparing to the code optimization practices found in this document: http://msdn.microsoft.com/en-us/library/bb687949.aspx. I was able to find several areas that needed optimizing.
Take a look at the example below:
SPFieldUserValue user = new SPFieldUserValue(web,Convert.ToString(listItem["Employee"]));
            peEmployee.CommaSeparatedAccounts = pmaUser.LookupValue;
If we have a SPFieldUserValue object, calling upon the LookupValue property will return the Name of that user. This is not to be confused with the LoginName property. Assigning that to the CommaSeparatedAccounts property may do the trick and will load that user account into the control but not without a performance hit.
A better approach would be:
SPFieldUserValue user = new SPFieldUserValue(web,Convert.ToString(listItem["Employee"]));
peEmployee.CommaSeparatedAccounts = pmaUser.User.LoginName;
The difference is minor. Instead of using the LookupValue property, we leverage the SPUser object and call upon the LoginName property. In all of my testing, I noticed an improvement in speed when using the LoginNameproperty.
Depending on your environment, the output from either of those properties will differ and that's the heart of the performance issues. In my environment, LoginName and Name outputted the following:
Name - "Joe User"
LoginName - "domain\juser"

Results/Conclusion

Using a combination of all the techniques I've described above, I was able to dramatically reduce the load time of this page and increase performance to the point where users are happy. Going forward, I was able to gain valuable insights into what aspects of the object model take time to load and therefore require careful planning before implementation.
Original Post on Simple-Talk.com 

Tuesday, May 19, 2009

Add Google Analytics to a SharePoint Publishing Site





From weblog of MIKE KNOWLES
Google Analytics is a web traffic and demographics reporting service provided free of charge by Google. Google Analytics functionality can be added to any web site by setting up an account and adding a snippet of JavaScript to every page within the web site. Once configured you can see all types of statistics such as how users were referred to your site, number of hits per page, where your users are located geographically, what types of browsers and OS they are using, and much more.
This post outlines how to add Google Analytics to a SharePoint Publishing site. You must have edit rights for all site Master Pages. Google Analytics can complement the Usage Reports available to Site Collection Administrators and Search Term Reports available to Shared Service Provider Administrators. Analytics can also be used to provide read-only access to users who do not have administrative rights on the SharePoint site but whose job function might benefit from access to detailed site usage data.

Click here to read the rest of the article:
http://mikeknowles.com/blog/2009/05/17/AddGoogleAnalyticsToASharePointPublishingSite.aspx

Sunday, May 17, 2009

All about Sharepoint 2010



All about Sharepoint 2010 from weblog of Vasmi Krishna:


  1. SharePoint 2010 will be 64-bit only.
  2. SharePoint 2010 will require Windows 2008 or Windows 2008 R2
  3. SharePoint 2010 will require 64-bit SQL 2008 or 64-bit SQL 2005
  4. Internet Explorer will not be supported in SharePoint 2010. The Tier 1 browsers will be IE 7, IE 8 and Firefox 3.x on Windows platform

So, what can you do today to get into the best shape for SharePoint Server 2010?
  1. Start by ensuring new hardware is 64-bit.  Deploying 64-bit is our current best practice recommendation for SharePoint 2007.
  2. Deploy Service Pack 2 and take a good look at the SharePoint 2010 Upgrade Checker that's shipped as part of the update.  The Upgrade Checker will scan your SharePoint Server 2007 deployment for many issues that could affect a future upgrade to SharePoint 2010.
  3. Get to know Windows Server 2008 with SharePoint 2007, this post is a great starting point.
  4. Consider your desktop browser strategy if you have large population of Internet Explorer 6 users.
  5. Continue to follow the Best Practices guidance for SharePoint Server 2007.
  6. Keep an eye on this blog for updates and more details in the coming months.

Wednesday, January 14, 2009

Web Site Design and Positioning

During my last workshop class on ASP .NET we had a review on web page design with ASP .NET. One of the most important part of the design is positioning the element inside you web site. What I recommend is to use <div> and <span> element with CSS styles to position your web pages instead of <tables>. If you look at the many professional designed web sites (like yahoo,msn, ...) and check their source code you will be noticed that most of them are using <div> or <span> for their pages. If you want to know why? "Table vs CSS" is are the reasons.





Now let start with learning <div> and CSS positioning. Just like always I recomend W3Schools. The next one is a reall great weblog from Big John, positioniseverything.net. It's nice blog explaining about positioning with CSS and bugs of browsers.

Sunday, December 14, 2008

Microsoft Security Development Lifecycle (SDL) Optimization Model


The Microsoft® Security Development Lifecycle (SDL) Optimization Model is designed to facilitate gradual, consistent, and cost-effective implementation of the SDL by development organizations outside of Microsoft. The model helps those responsible for integrating security and privacy into their organization's software development lifecycle to assess their current state and to gradually move their organizations towards the adoption of the proven Microsoft process for producing more secure software. The SDL Optimization Model enables development managers and IT policy makers to assess the state of security in development. They can then create a vision and road map for reducing customer risk by creating more secure and reliable software in a cost-effective, consistent, and gradual manner. Although achieving security assurance requires long-term commitment, this guide outlines a plan for attaining measureable process improvements, quickly, with realistic budgets and resources.

If you are intereseted in Microsoft Security Development Lifecycle (SDL) here is some links to it:
The Microsoft Security Development Lifecycle (SDL)
Microsoft Security Development Lifecycle (SDL) – Process Guidance

Monday, December 8, 2008

What is Sharepoint?


During last two month I had many phone calls about Microsoft Sharepoint and related subjects, so I have prepared a little document in Persian about what is Sharepoint, features and advantages. You can download it from my personal web site http://www.tabatabaei.info.

If you need any further information/assistance, do not hesitate to contact me.

Download url: http://www.tabatabaei.info/sharepoint.aspx

Wednesday, December 3, 2008

Value of Selected CheckboxList Item in Javascript

Sometimes, you may need to find which item of your CheckboxList is selected and get it's value on client. Normally ASP .NET CheckboxList does not send its item 's value to client. So if you want to have it, you have to added it your self. In this post I 'm going to show you a simple way to get selected checkbox list item 's value.

First I prepared a checkbox list with some items. In this sample I have added some item manually but you can do this using DataBinding.

<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatLayout="Table">
    <asp:ListItem Text="Test" Value="110" />
    <asp:ListItem Text="Test2" Value="220" />
    <asp:ListItem Text="Test3" Value="330" />
    <asp:ListItem Text="Test4" Value="440" />
</asp:CheckBoxList>

Next, I have to add items value as an attribute for the items:

protected void Page_Load(object sender, EventArgs e)
{
     foreach (ListItem li in CheckBoxList1.Items)
         li.Attributes.Add("mainValue", li.Value);
}

Finally, you need to assign a function as click event handler for items. The point is that you can not do it just like the other html element on your page. So I will write a few line of code to add this event handler.

<script>
    function AddHandler()
    {
        var tbl = document.getElementById('<%= CheckBoxList1.UniqueID %>');
        for(var i=0;i<tbl.cells.length;i++)
        {
            var cell = tbl.cells[i];
            cell.childNodes[0].onclick = function ()
            {
                if(window.event.srcElement.checked)
                    alert(window.event.srcElement.parentNode.attributes["mainValue"].value);
            };
        }
    }
    </script>

Notice that I will call this function ("AddHandler") on onload on body.
<body  onload="AddHandler();">

The only thing that you have to be carefull is that this codes will work when you are using CheckboxList with RepeatLayout property is "Table".
Download the sample code from here:
http://www.tabatabaei.info/csharpsamples/EventArgsSample.rar

Tuesday, October 14, 2008

7 Version Control Systems Reviewed

If you've ever collaborated with other people on a project, you know the frustration of constantly swapping files. Some do it by email, some through file upload services and some by other methods. It's a pain in the neck, and every designer and developer knows it. Revision control is an excellent way to combat the problem of sharing files between workers.

Most web-developers have probably worked with some sort of revision control system, but designers may find it a foreign concept. The most obvious benefit of using revision control is the ability to have an unlimited number of people working on the same code base, without having to constantly send files back and forth.

But designers and developers can both benefit from using revision control systems to keep copies of their files and designs. You can instantly browse previous "commits" to your repository and revert to earlier versions if something happens.

This article reviews some of the top open-source version control systems and tools that make setting up a version control system easy.

CVS

CVS is the grandfather of revision control systems. It was first released in 1986, and Google Code still hosts the original Usenet post announcing CVS. CVS is the de facto standard and is installed virtually everywhere. However, the code base isn't as fully featured as SVN or other solutions....

Read the rest of this article on :SmashingMagazine.com

Saturday, September 20, 2008

Persian Calendar for SharePoint 2007

Within last a few months me and two of my friends have started working on implementing Persian Calendar for SharePoint 2007. Now after more than 6, 7 month work on this we have the Persian Calendar implemented in SharePoint 2007.

One of the most important point about this package is that youwil stil have your Hijri calendar while you can use Persian Calendar too. Also it 's possible to develop web parts which can use Sharepoint Persian Calendar.
While Microsoft is not supporting Persian calendar on Sharepoint officialy, Now we are negotiating to transfer this technology, with some of the most active companies which are working on providing SharePoint stuff in Iran and Middle East.
You can find out more news about Sharepoint 2007 Persian Calendar on my web site : http://www.tabatabaei.info/

Sunday, August 24, 2008

Disabling Auto-Complete on ASP.NET Forms

Popular browsers, such as Internet Explorer and Firefox support something called Auto-Complete. You've seen this many times. You go to a online form and as you start to type in fields you get a drop-down showing values you've typed in that field before. This feature can be turned off, but it really is a useful feature and can save you a lot of typing when entering redundant values.

As a web developer, you have to be conscious of the fact that the user's browser will likely have auto-complete turned on and be responsible enough to act accordingly. If you have a form that where the user could possibly enter private or secure values you need to be mindful that if the user is on a public computer that these values will be cached by the browser and seen by other users of that computer. You are able to control if the browser uses AutoComplete for your form or for specific values with just a small & simple tweak.
To turn off auto-complete for your entire form, all you need to do is add an attribute to your form tag, like this:
<form id="Form1" method="post" runat="server"
autocomplete="off">
Easy enough. Now you won't get the auto complete on any of the controls on the form, works for any browser that supports auto-complete. The HTML INPUT tags also support the use of autocomplete=off and since the control renders as INPUT tags then you can use it to set it on a control by control basis. Just add it to the TextBox at design-time (but note that VS.NET will underline it with a squiggly saying that textbox does not have an attribute for autocomplete - but it will still work):
<asp:TextBox Runat="server" ID="Textbox1"
autocomplete="off"><!--asp:TextBox>
or at runtime:
Textbox1.Attributes.Add("autocomplete", "off");

From Ryan Farley 's weblog. See the original post on his blog : http://ryanfarley.com/blog/archive/2005/02/23/1739.aspx.