Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variables

Status
Not open for further replies.

crystalized

Programmer
Jul 10, 2000
390
CA
I am wondering about the use of session variables.&nbsp;&nbsp;I have read a couple of things saying the use of session variables will not work over multiple servers and that a busy site could easily crash the server dealing with Session variables.<br><br>What I had seen is that Session variables are the only way to have persistant data between pages for an individuals session, but then I saw another item that said using Database Session Management in it's place is a better idea.&nbsp;&nbsp;I have to admit I have no idea how I would do that.&nbsp;&nbsp;<br><br>I want to design this app right the first time so I don't have to go back and fix everything later if it becomes bigger than expected.&nbsp;&nbsp;Or for that matter if someone else is stuck with the job of fixing problems I have inadvertantly created.<br><br>Thanks in advance<br><br><br> <p>Crystal<br><a href=mailto:crystals@genesis.sk.ca>crystals@genesis.sk.ca</a><br><a href= > </a><br>--------------------------------------------------<br>
Experience is one thing you can't get for nothing.<br>
-Oscar Wilde<br>

 
you can use sessions on the same server, with no prob, once the connection been offline for that user the session is cleared out. I havent heard of it crashing, but as for the multiple server deal, to be safe, I would recomend appending the parameters right on the URL, or submiting a form to the page on the next server and have it sessions there, and use forms or direct URL parameters when switching servers. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Hi Crystal,<br><br>This is a fairly large issue because there are so many variables. In early versions of IIS the servers management of session memory was not nearly as optimized as it is now. <br><br>It's not really the number of session variables as it is the total memory required for them. You wouldn't want to 500 visitor on your site at one time to take up 100 megs of memory for the session variables.<br><br>The database session concept is actually very simple. You design a schema in your database to house your session information and set up the relationships so that you can retrieve all the data by the users session ID. Now the IIS server only has to house the session ID's in memory and the database can house all the rest. The session ID is created by IIS and you can get it from one of the intrinsic objects like Server or Request or something.<br><br>So a simple single table session would look like this<br>varchar session_id<br>varchar zip_code<br>varchar dogs_name<br><br>So you have an ASP routine that looks up the row by session_id and if it doesn't exist it creates a new row with the session_id<br><br>***************<br>A different technique is to use hidden form variables to keep the session data in the users browser. The code becomes complex when a lot of data is involved.<br><br>***************<br>A separate issue is that IIS allows you to create session at the ASP Application level. So if only part of your site needs to maintain session then the session memory can be smaller by dividing your site into separate ASP applications like this:<br><br>Main Entry<br>&nbsp;- Company Information<br>&nbsp;- Services<br>&nbsp;- Partners<br>&nbsp;- Order Products (this application needs session)<br>&nbsp;- Product Information<br>&nbsp;- Human Resources (this application needs session)<br><br><br>So only the visitors in the site within the 'Order Products' and 'Human REsources' are taking up session memory.<br><br>There is more yet but that's enough to get you thinking.<br><br>Hope this helps<br>-pete
 
Oh, right I forgot about this:<br><br>&gt; session variables will not work over multiple servers <br><br>That is refering to a server Farm. In a farm the session variable gets created on the first server that the visitor is sent to. Then when they request the next page maybe that server is busy and the load balancing sends the request to a different server in the farm. Now that server doesn't have the SessionID it only exists on the first server. There are articles about this and how to set up session when using farms at msdn.microsoft.com<br><br>-pete
 
Thanks again Palbano<br><br>You really have been a big help to me already.&nbsp;&nbsp;I hope that you don't mind answering my questions.<br><br>The idea for the database session and your explanation make it sound like exactly what I need.&nbsp;&nbsp;My only concern is that it seems like it would add to my servers load, having to query that &quot;Session Schema&quot; all the time.<br><br>I just have so many questions that the books I have do not seem to answer, so I keep posting them here.&nbsp;&nbsp;I am also trying to read a lot of articles and other discussion forums.&nbsp;&nbsp;So if you know of any more books or sites etc that might provide a little more help on the beginner end of things I would appreciate it.&nbsp;&nbsp;I understand a lot of the programming concepts, but some of this syntax that I see in examples just baffles me.&nbsp;&nbsp;I have done <u>some</u> programming in several languages but the whole world of ASP scripting is new to me.<br> <p>Crystal<br><a href=mailto:crystals@genesis.sk.ca>crystals@genesis.sk.ca</a><br><a href= > </a><br>--------------------------------------------------<br>
Experience is one thing you can't get for nothing.<br>
-Oscar Wilde<br>
 
Crystal,<br><br>The Web application architecture is much more complex in terms of the number of components that can effect performance. Since this industry is still relatively new, right and wrong are still being discovered on a daily basis. So in some cases you may not be able to find a definitive solution.<br><br>&gt; would add to my servers load, having to query that &quot;Session Schema&quot; all the time.<br><br>SQL Server is going to cache that table and then you should build a stored procedure rather than embedding SQL statements into your ASP pages. I don't know how much data you intend to store for the session but in a small to medium sized table ( row size) this should be very fast. <br><br>Also in your session_end routine you will delete the row for the current session so the table should not get very large.<br><br>One last thing check out WCAT from microsoft. It's free and it's an ASP application load stressing testing program. Then if the load stressing finds performance problems you can use the Visual Studio profiler/analyzer to locate the component(s) that are using the most processor time.<br><br>It doesn't do any good to optimize a component that is only using 1% of your applications processing time. Use tools to verify that there is a performance problem and then to pin point where the problem is located. <br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top