ASP.NET Session vs. Persistence

Today my boss asked me to cut down the performance on a web application that I thought was pretty horrible myself. The first thing I looked at is how to take out trips to the database.

I had a few persistent objects out here based on the session ID which I was collecting from the database every time a page was hit. This seemed terribly inefficient so I started poking on DevExpress’ search engine trying to find out how to take these out.

After a bit of hair pulling, I found the authentication system travels with a session, so session level properties can be stored in it.

I decided to try inheriting their authentication active directory system and use it to store a web session object.

This is the result:

Public Class SessionSecuritySystem
    Inherits ISS.Security.Web.AnonymousSecuritySystem

    Private _mUserSession As CMSUserSession
    Public Property UserSession() As CMSUserSession
        Get
            Return _mUserSession
        End Get
        Set(ByVal Value As CMSUserSession)
            _mUserSession = Value
        End Set
    End Property

    Private Sub SessionSecuritySystem_PlatformDataChanged() Handles Me.PlatformDataChanged
        Dim obsSpace As ObjectSpace
        If CMSModule.XafApplicationInstance IsNot Nothing Then
            obsSpace = CMSModule.XafApplicationInstance.CreateObjectSpace
            Me.UserSession = Activator.CreateInstance(CMSModule.SharedUserSessionType, obsSpace)
        Else
            Me.UserSession = Activator.CreateInstance(CMSModule.SharedUserSessionType)
        End If
    End Sub
End Class

This class gives me the option to store anything for the web session without making a trip to the database.

My web application was a store style website, so needless to say it cut the 100 trips to the database per page call down to 25.

Next I’m going to work on how to improve object performance with the Session.

DevExpress has noted a few times that the session object has a cache which returns back objects and if they have been modified int he database for reload.

I think the next logical path would be to store these commonly used objects and retrieve them only when they are changed. It would be nice if DevExpress worked with database triggers to get notification of object changes.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>