Brent Arias
Brent Arias

Reputation: 30215

ASP.NET "Re-establish Session" Performance Hit

After a user has initially established session with ASP.NET, with each subsequent HTTP request how much of StateServer session objects are immediately and automatically fetched and deserialized? For example:

  1. Are ALL session objects fetched the moment the request is received and session re-established, or...
  2. After session is re-established are session objects fetched and deserialized individually as each request to HttpContext.Session["..."] is made?

The answer has a HUGE impact on how I can use session. For example, if I have pre-fetched a significant amount of user data into session, and the StateServer session is completely deserialized upon each HTTP request, then I will experience a noticeable performance hit. If however the pre-fetched user data is only deserialized when I request specific session keys, then for me there is no worry.

UPDATE After marking an answer to this question, I discovered that ASP.NET with AppFabric Server 1.1 has an option to have session restored on-demand rather than all-at-once. This is controlled by useBlobMode in your web.config.

Upvotes: 3

Views: 131

Answers (1)

Frazell Thomas
Frazell Thomas

Reputation: 6111

Session loads all of the user Session information when the page is first loaded. It then persists the users Session information back to the store after the page is done processing.

You can get a better understanding via MSDN on custom state store implementations.

This is a major reason that you're supposed to use Session as rarely as possible because it is expensive to deal with (both in the transporting to and from the data store and the holding of the data in memory for the lifetime of the page request).

Upvotes: 1

Related Questions