ASP
  Home arrow ASP arrow Page 3 - When Session Variables Go Bad
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

When Session Variables Go Bad
By: Bruce Johnson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2002-11-28

    Table of Contents:
  • When Session Variables Go Bad
  • The Implementation Details
  • Cap'n. The Resources. They Canna Take It!
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    When Session Variables Go Bad - Cap'n. The Resources. They Canna Take It!


    (Page 3 of 4 )

    Forgetting about the threading issues, there are a number of less esoteric issues that impact the use of Session variables. The strain on server memory can get quite high, depending on the usage of your web site.

    As we mentioned earlier, Session variables are implemented as a collection. Actually, as a collection of Variants. This means that for every session, you not only have the data being stored, but also the implementation of the Add, Remote, Item and Count methods, as well as the IEnum interface. Then, since it is a collection of variants, the collection also needs to implement the IEnumVariant interface. Finally, the values in the collection are tied together using a linked list. So if you add even a small piece of data to the session variables, the memory usage might seem way out of whack.

    Now in the connectionless world of HTTP, there is no way for the application to know when a user is done with their session. So IIS implements a session timeout mechanism. By default, it is twenty minutes, but it can easily be configured by the web site administrator. This value does significantly impact the resource usage of the web server. Let's say that you get 1000 users an hour on your site. That means that, on average, you will have 330 sessions active (okay, 333, but the math is easier if there are zeros). Say each session takes up 4KB of space. That means that 1.3 MB would be constantly allocated on the server. Not a problem, you say? Fine. So long as you keep ratcheting up the server memory as your site becomes more popular.

    Down on the Web Farm
    Our final issue with Session variables arises when your application get scaled out across a number of servers. Typically, when you have multiple servers processing the requests for a single site (a web farm), there is some load balancing hardware or software that determines the lucky server that gets the next request. The most common algorithm used by the load balancer is a simple round robin. You think that you had problems with thread affinity! All of the Session variables are sitting on the server which handled the initial assignment. So if it should happen that the next page request is processed by a different server, all of the session information is lost. Now to be fair, there is software available that will 'pin' all of the page requests from a single session to one server. In fact Microsoft's Load Balancing Service will do that for you. However you are reducing the overall performance of the application. You could easily get the situation where one server is processing four or five sessions while there are other servers sitting idle.

    More ASP Articles
    More By Bruce Johnson


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT