Question about session variables

Results 1 to 2 of 2

Thread: Question about session variables

  1. #1
    Join Date
    Dec 1969

    Default Question about session variables

    I am writing an application which currently only uses session variables to store the users login id. At the top of virtually every page there is a select element listing choices specific to each user (generated from a database using login id in where clause). My question is would I be better off generating this select element once for each user and storing it in a session variable or re-generating it from the database each time. I am using IIS 5 and SQL Server 2000. I have found many articles and faqs on the subject of session variables but none of them specifically say how much is too much to store in them. In my situation I expect to have a maximum of 60 concurrent users and each select element would be 200 to 300 characters on average.<BR><BR>Any comments would be appreciated!

  2. #2
    Join Date
    Dec 1969

    Default Do the math...

    A session variable eats up about 64 bytes of overhead plus the name of the variable times two plus (if the value is a string) the number of characters in the value times two.<BR><BR>Let&#039;s go whole hog:<BR><BR>300 characters, 30 character variable name. 660 bytes for the strings. Plus 64 bytes. Call it 750 bytes. No, let&#039;s be *really* conservative and call it 1K bytes.<BR><BR>60 concurrent users. I don&#039;t believe you. I&#039;m going to assume you might have 1000 users who are still stuck in the sessions because of the 20 minute session timeout.<BR><BR>Okay 1000 times 1KB is.... 1MB. One megabyte. Hmmm...nowadays 256MB goes for what...$40? So 1MB costs roughly 16 cents. Can you afford to spend that much?<BR><BR>Of course, all my numbers were purposely way inflated (well, I wanted to get up to that 1MB number). In reality... Maybe 4 cents worth of memory? Maybe?<BR><BR>Most of those people who talk about how bad session variables are tend to be discussing sites that have hundreds of thousands of hits per hour. Don&#039;t believe everything you read. DO the math yourself.<BR><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