Measuring sessions for Sitecore 6 sites

I recently had to do some performance and stress tests on a Sitecore 6 website. But no matter what I did, the Perfmon showed 0 sessions.
At first I blamed the built in session handling in Sitecore, where Sitecore persists the Shell users. But the solution was elsewhere.

In order to measure sessions you must add the Session_Start and Session_End functions to the global.asax:

<%@ Import namespace="Sitecore"%>
<%@ Import namespace="Sitecore.Diagnostics"%>
<%@ Application Language='C#'%>
<script runat="server">
  public void Application_Start() { }
  public void Application_End() { }
  public void Application_Error(object sender, EventArgs args) { }
  public void Session_Start(Object sender, EventArgs e) { } // Add this to your global.asax
  public void Session_End(Object Sender, EventArgs e) { }   // Add this to your global.asax

There is no need to fill anything into the functions. They just have to be there. After this I could measure the sessions with Perfmon.

UPDATE: This is actually not a Sitecore 6 issue but a general .NET issue. It is not even a bug but expected behaviour. .NET will not instantiate the session object if no one uses it. This is a pretty clever way of saving memory.
When adding the Session_Start() and Session_End() events in the global.asax, the auto event wireup will automatically force an instantiation of the session object, making the .NET process store session data.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 6 and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.