Asp.net 4.0 and Session State compression

Hi,

 

Most of us who creates Web sites work with session. We use sessions to store user specific data, so that it can be retrieved very easily.

 

You can read my earlier posts on sessions here.

 

A few interesting things about session in Asp.Net

Mystries of when does Session_End event fires in Asp.Net

Session and concurrent request

 

By default the session data is stored in the process. But Asp.net Gives you two options to store data outside the process State Server or SQL server.  Depending on various situations you might want to store the session data in any of them. To store the session data Out of the process (worker process), the data needs to be serialized.

 

Depending on the amount of data stored and the number of concurrent session this Serialized data can become very large.

 

With this size problem in mind, Asp.Net 4.0 has come up with a new option for compressing the Session Data when the session is stored out of process. The setting can be made at the Web.config (Exmaple below) level, based on which Asp.net 4.0 will itself compress and decompress the session data using the System.IO.Compression.GZipStream class.

 

<sessionState mode="SqlServer" sqlConnectionString="conn" allowCustomSqlDatabase="true" compressionEnabled="true" />

 

(The extra change required in web.config file has been made Bold)


This compression and Decompression of Session Data not only reduces the Session data for concurrent sessions but also help reducing the size of data being stored and retrieved on every request to the website.

 

But remember this option should only be used in case you are storing lots of data in the session. If you use this option while storing small amount of data in the session then it will give negative effect as even for the small amount of data, the GZip compression (and decompression) will have to run every time.

 

Vikram

1 Comment

  • Great compression is being added!

    Also lookup Velocity as another microsoft provider (still in beta) to storing distributed session state (including ASP.NET providers). I think it is coming with .NET 4?

    It lets you distribute/backup your session between multiple computers without needing to setup clustered SQL server.

    Dave

Comments have been disabled for this content.