Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Points about sessions in ASP.NET

Suppose we have a website with 100k active users.

If we want to save email, name, last name and gender of users in sessions, how much space is allocated to all the sessions?

Are the sessions affecting server RAM, server bandwidth or something else?

Please give me a little information about session functionality and effect of session overload on the server.

like image 251
distance Avatar asked May 07 '15 08:05

distance


People also ask

What is the use of sessions?

A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.

What is the use of session in C#?

Session is a feature in ASP.NET Core that enables us to save/store the user data. Session stores the data in the dictionary on the Server and SessionId is used as a key. The SessionId is stored on the client at cookie. The SessionId cookie is sent with every request.


2 Answers

The session themselves will consume the server RAM if your mode is set to InProc, which is limited only by the amount of RAM available to the worker process.

Considering your high demand, you want to be really careful what you're putting in the session, only when it's absolutely necessary. Don't put things in session and leave them there for use in a page or two, just go back to the database and get them, otherwise your session size will creep up drastically.

Based on what you're storing, it's only 5kb or even less, so based on 100k users, that would be:

5kb * 100,000 = 488.28MB

So you see, even though you're only storing a couple of details, at that level of usage the memory usage is quite significant.

For such high demand and usage, I would consider using a dedicated state server (StateServer mode) which allows you to manage it separately and allocate the resources to that server as required.

The other option is using SQL Server session (SQLServer mode) which is limited only by the size that is available to the database. So we're talking hard disk space here and not RAM. To be honest though, if you're going to the database to retrieve your session information, then why not just go to the database and retrieve the information you need anyway?

like image 96
mattytommo Avatar answered Oct 27 '22 20:10

mattytommo


I would recommend you to store such data in the client when you have 100k users. Your pages will be larger and require more bandwidth but you will allocate less memory on the server. If you talking about a ASP-application check this article http://www.codeproject.com/Articles/416137/Understanding-Session-Management-Techniques-in-ASP

like image 42
Marcus Höglund Avatar answered Oct 27 '22 21:10

Marcus Höglund