home navigator pointer resources navigator pointer asp tips navigator pointer minimise session use
The definitive ASP tips page
tips menu | printable single page version

Note: this is my old ASP tips page and is no longer supported. See the new Visualize web site..

ASP Coding for Performance - Minimise Session Use

Only use sessions where needed. They are essentially glorified "global variables" and as anyone with a background in software engineering will tell you - "globals are bad news". There are a number of reasons for this. Not only do they tightly couple your scripts together, raising all kinds of maintenance issues (we should aim for loosely coupled pages), they also reduce scaleability as they tie a user to that specific server, making the use of web farms and load balancing more difficult. Sessions also require cookies to be enabled on the browser for session id information to be stored. Something we cannot always guarantee. Also, sessions can use a great deal of the server's resources, especially if abused, as a session typically lasts for around 20 minutes (default session timeout), wasting valuable memory, often long after the user has left the site! The worst scenario for this is where objects, recordsets or arrays are stored in a session and are "never" explicitly closed or destroyed. Oh dear... that poor server...

A final thought on this - if you really need to store a recordset or other object in a session (and there are times when this is useful), as a catch all, please ensure that Session_OnEnd() in global.asa has the relevant code to close them and free up memory afterwards. Also, minimise the session timeout to as low a figure as is acceptable, and add the @ENABLESESSIONSTATE=False directive to all pages that do not require session state information (saves web server resources):

 

DISCLAIMER: Note these pages are a free resource for anyone wishing to reference them. Although every care is taken to ensure their correctness, the author takes no responsibility for any errors or problems that may occur through their use, or indeed misuse. These pages are copyight of Dave Clarke, Visualize Software Ltd 1997-2000 (all rights reserved).


 


© Copyright Dave Clarke, 1996-2008