How many session variables are too many?

# Thread: How many session variables are too many?

1. Senior Member
Join Date
Dec 1969
Posts
195

## How many session variables are too many?

&nbsp;<BR>I currently use any where from 5-20 per user because I don&#039;t want to request info from the recordset every page view.<BR><BR>They are along the lines of this:<BR><BR>Session("userID") = 1001<BR>Session("userAlias") = "Bob The Goon"<BR>Session("userLevel") = 1<BR>Session("userName") = "Robert Smith"<BR>Session("userScore") = 902<BR>Session("userRank") = 12<BR>Session("groupName") = "The Web Goons"<BR>Session("groupID") = 387<BR>Session("groupScore") = 12092<BR>Session("currentTitle") = "King of the Web"<BR>Session("recordWins") = 68<BR>Session("recordLosses") = 14<BR>Session("recordDraws") = 2<BR><BR><BR>Now, what if the site define these for, let&#039;s say, 650 registered users at one time?<BR><BR>I haven&#039;t really had to do a project yet that required me to show extensive profile info on every page, so is this an unusual amount of session variables to define?<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
2,225

## RE: How many session variables are too many?

Read this:<BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=145<BR><BR>and then do the math to figure out how much memory that many visitors will consume. Then see how much RAM you have on your server.

3. Senior Member
Join Date
Dec 1969
Posts
195

## RE: How many session variables are too many?

&nbsp;<BR>WHEW...If that did anything, it confused me even more.<BR><BR>Now I&#039;m learning that I&#039;m not supposed to be using "EVIL" session variables.<BR><BR>No session variables?!?<BR><BR>How in the world do you transport 20 items of user profile information to every page the user is on? QueryStrings are stupid-sloppy looking and can be manipulated to an extent.<BR><BR>Let me ask you this then:<BR><BR>What if I took all of the user&#039;s info, created a small temp HTML file using the FileSystemObject and then SS-included that file into the space the info needed to be located at.<BR><BR>I could probably get away with using a single &#060;% Session("userID") = ### %&#062; variable - using that to load the appropriate profile include.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Do the math...

20 items. How big are they? I&#039;m going to assume that they average 30 characters each (and that they are all strings).<BR><BR>And I&#039;ll assume that the *names* of these session variables (which are really just the keys into key/value pairs in a hash table) average 10 characters.<BR><BR>2 bytes per character --&#062;&#062; 10*2 + 30*2 --&#062;&#062; 80 bytes.<BR><BR>Plus there are 16 bytes of overhead (the VARIANT from that FAQ) per string. 80 + 32 --&#062;&#062; 112 (call it 120 for simplicity)<BR><BR>Times 20: 20 * 120 --&#062;&#062; 2400 bytes<BR><BR>Plus there is the overhead of the hashtable itself, etc., etc.<BR><BR>Let&#039;s round it up and call it 4K bytes per user for session variables.<BR><BR>Okay, now let&#039;s say your site has 2,000 visitors per hour, and the average visitor stays 10 minutes. And nobody ever logs out so you just have to wait for Session_onEnd to clear out the session variables. Then, on average, you will have 1,000 sessions running at any given time.<BR><BR>1000 time 4KB is 4 megabytes. You need to go out and spend about 80 cents and add 4MB of memory to your system, it sounds like.<BR><BR>20,000 visitors per hour? 40MB. Pish and tosh. Who cares.<BR><BR>200,000 visitors per hour? 400MB. Okay, now we&#039;re getting serious. Might have to put a GB of memory in the old beast. If you have to yank out the old cards to do that, it might even cost \$200 or a bit more. [But it&#039;s not practical, anyway, for other reasons. Besides, 200,000 visitors per hour would probably be straining other resources...like the DB.]<BR><BR>So...do the math. Then decide.<BR><BR>And if you have under a couple of thousand visitors per hour, who cares?<BR><BR>[Note: If you are running on a *shared* host, then remember it&#039;s the number of visitors to all sites on that shared host that *can* impact things.]<BR><BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
195

## RE: Do the math...

&nbsp;<BR>Thanks for "dumbing" that down for me, Bill.<BR><BR>I always underestimate the power of todays technology and how much information it can process and store.<BR><BR>I guess with a small site like mine, I don&#039;t really have to worry about session vars as long as I don&#039;t go ape. However, and ESPN.com would definitely have to be more resource conscience.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## ASP is old technology of course...

It&#039;s vintage 1996-97 design.<BR><BR>And a lot of the dire warnings about session variables chewing up resources come from then. Heck, I remember running ASP on a 486DX with 48MB of memory (I think...might have been 64MB).<BR><BR>And at that time 4MB *was* a huge chunk of memory, to be used only after serious consideration. But even my home machine has 640MB in it now (and this beast has 1GB). The game has changed.<BR><BR>Unfortunately, there are tons of sites out there that were created in 1998 and 1999 that still keep the same old warnings. Shoot, they aren&#039;t even in the right century, are they?<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
195

## RE: ASP is old technology of course...

&nbsp;<BR>But, but, but... I read it HERE! ;) D&#039;OH!<BR><BR>http://www.4guysfromrolla.com/webtech/101999-1.shtml<BR><BR>"Unfortunately, there are tons of sites out there that were created in 1998 and 1999 that still keep the same old warnings. Shoot, they aren&#039;t even in the right century, are they?" - Bill W.<BR><BR>:P<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## And look at the date!!!!

http://www.4guysfromrolla.com/webtech/[hl="yellow"]101999[/hl]-1.shtml<BR><BR>That&#039;s October, 1999. Like I said. Out of date.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Grumble...

h t t p : / / w w w.4guysfromrolla.com/webtech/[hl="yellow"]101999[/hl]-1.shtml<BR><BR>That&#039;s October, 1999. Like I said. Out of date.<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•