ASP.net session state
Author
Discussion

Bonce

Original Poster:

4,339 posts

303 months

Monday 2nd August 2004
quotequote all
Currently working on a project that includes a couple of forms that may take end users (who must be logged on) quite a long time to complete. The catch is that their session may timeout if they take too long entering stuff into the form without saving. The customer is asking if we can increase the timeout from 20 to 60 minutes, but I'm not sure that's a good idea because

a) When the site takes off we could have several hundred people online at any moment
b) From my googling, I was able to glean the the .net session state is unreliable beyond 20 mins.

We are only explicitly storing a few short strings (prolly 100 bytes tops) per logged on user so even if there were 2000 sessions in memory that would only be ~200Kb of server memory used for session state, which sounds OK to me. Or is there a much larger impact for every session that a webserver creates?

Does anybody have any experience or thoughts on this? Any stats to show impact on server performance?

Cheers!

Don

28,378 posts

308 months

Monday 2nd August 2004
quotequote all
Dunno about .NET but we have Session state in ASP apps to be bad news.

Basically its best to make your site completely Sessionless and pass around the info you need.

wimdows

108 posts

276 months

Monday 2nd August 2004
quotequote all
Bonce,

The options to preserve session state in ASP.NET are much more flexible than classic ASP.

You could use SQL Server or even an out of process dedicated state server to avoid issues when your site moves to a clustered web server environment.

It sounds though as if you could simply use the HttpContext.Items collection, which doesn't carry a memory or database overhead (in case you use SqlServer state) on the server. The only thing you then need to do is to use Server.Transfer to send the user to a different page, where you request the HttpContext Items again.

Here's an example:

// Page 1
private void Page_Load(object sender, System.EventArgs e)
{
ArrayList list = new ArrayList();
list.Add("string 1");
list.Add("something else");

this.Context.Items["list"] = list;
// make sure to use Server.Transfer to preserve the context collection
Server.Transfer("webform2.aspx");
}

And then in page 2

private void Page_Load(object sender, System.EventArgs e)
{
ArrayList list = this.Context.Items["list"] as ArrayList;

// do something with the collection, or add more items, and Transfer to another page again.
if(list!=null)
{
foreach(string s in list)
{
// do something
}
}
}

Hope that makes sense.

Just shout in case you got any queries.

Cheers,
Wim

P.S. Sorry about the lack of indentation - the PH forums aren't made to display code blocks!

>> Edited by wimdows on Monday 2nd August 16:55

Bonce

Original Poster:

4,339 posts

303 months

Monday 2nd August 2004
quotequote all
Nice idea but we can't use server.transfer for the hundreds of hyperlinks dotted around the site!

Besides, the site is written and working, I was just wondering if anyone had any stats on session timouts vs performance. We use session variables on the majority of our websites and have done for years to no ill effects.

lanciachris

3,357 posts

265 months

Monday 2nd August 2004
quotequote all
Youve missed the actual problem here - youve got a form that might take 20 minutes to complete!

If nowt else you need to have save buttons or somesuch on that form to ease the pain

KormaChameleon

46 posts

279 months

Tuesday 3rd August 2004
quotequote all
From what I remember, the basic footprint required for a session is around 10KB, whether you store something or not. If you have 200 concurrent users you may be loading the server with 2MB rather than 200KB.

There's nothing wrong with using Session - there are plenty of sites using it. It's just that some sites grow beyond their initial estimates and then you run into problems. That's why it's preferable to redegin a stateless site.

The real problems arise persisting non thread safe objects in the Session variables and causing thread contention and deadlocks which will affect the sites scalability.

It's difficult to tell - best bet is to monitor server performance - I think there may be performance issues later - I've never designed an application using Session with that many concurrent users!

Mark.S

473 posts

301 months

Wednesday 4th August 2004
quotequote all
With a few thousands users your never going to see a problem, even with session timout extended to 60 minutes. If usage exploded you could easily switch to using a dedicated session state server, using memory or SQL as the store.

Bonce

Original Poster:

4,339 posts

303 months

Thursday 5th August 2004
quotequote all
Thanks guys!

(I know that the form is too large but I'm afraid it's been dictated by the customer's requirements. At least all of the fields are optional)