Tuesday 2 March 2010

Asp.Net 4.0 - Session State Compression

Using sessions sometimes may cause performance problems. To prevent these we usually split the IIS and State machine server. Additionally we would store session in SQL server. One of the new future in ASP.net 4 will definetly be our pain killer on this subject. It is very simple configuraation. When we configure the sessionstate in web.config, we will simply set compressionEnabled as true. Then ASP.NET will compress (and decompress) serialized session state by using the .NET Framework System.IO.Compression.GZipStream class. You can simply give it a go and see the difference via configuring SQL DB as a sessionstate server and checking the size of SessionItemLong field in ASPStatesTempSessions table. On text values we can see incredible difference, but if it is an image file the difference will not be that incredible.

mode="SqlServer"
sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate"
allowCustomSqlDatabase="true"
compressionEnabled="true"
/>

2 comments:

  1. Very nice article. Short but very clear. I have also written a similar article in my blog post:
    http://blogs.msdn.com/b/amb/archive/2011/02/23/enabling-session-compression-in-asp-net-4-0.aspx

    I will update my post and point a link here as a reference as soon as possible.

    Thanks,
    AMB

    ReplyDelete
  2. This is a nice article..
    Its easy to understand ..
    And this article is using to learn something about it..

    c#, dot.net, php tutorial, Ms sql server

    Thanks a lot..!
    ri80

    ReplyDelete