ASP.NET SQL Session cost

From: Ally 6 Aug 2010 16:38
To: ALL1 of 6
A question that I have so far failed to find answer to if anyone (hi, Rendle) has the answer:

We store our site sessions in a database, so that it's accessible across all the web servers. I'm trying to increase performance a little by reducing the number of (normal, non-session) DB calls we make by storing more data in the session.

Now, I don't know how ASP.NET internally queries the session data. For instance, when I do:

C# code:
Session["blahblah"]


does it fire off a query? Or does it load up all the session data in one big gulp before the page load, and store it in memory? I'm assuming it's the latter, but can't find any confirmation on this. If it's the former, then my optimisations are hardly worth doing.
From: Matt 6 Aug 2010 19:12
To: Ally 2 of 6
Can you monitor the database [table] to see the queries being run?
From: Ally 6 Aug 2010 19:15
To: Matt 3 of 6
Unfortunately not- my local dev environment uses in-memory sessions- it doesn't use DB-based sessions until it's on the live server. In any case, I've looked at the session tables before and they're just a deeply confusing mess... I'm sure they're also very efficient, but they confuse the hell out of me.
From: THERE IS NO GOD BUT (RENDLE) 7 Aug 2010 14:26
To: Ally 4 of 6

The SQL session provider loads values as you reference them. But once it's loaded during a request, it is cached in memory for the remainder of that request process.

 

Microsoft are generally quite good at making their things optimal for stuff like this.

From: Ally27 Aug 2010 05:32
To: THERE IS NO GOD BUT (RENDLE) 5 of 6

Sorry, never replied to say thanks for this.

 

Thanks for this!

From: THERE IS NO GOD BUT (RENDLE)28 Aug 2010 14:29
To: Ally 6 of 6
Welcome.