Reputation: 21
We have an ASP.NET Webforms application, where currently we are storing our session data in a State Server. Now we wish to increase the session timeout period for the application.
This is Of course possible, but for this we need to calculate the new hardware requirements.
And hence we need to see the size of the objects stored in the session. Could you please suggest any way/tool that can help us to identify the size of various objects stored in the session.
Any help or pointers would be greatly appreciated.
Upvotes: 1
Views: 2439
Reputation: 1
Use this to get the size of all objects stored in the current Session:
public long GetSessionSize()
{
long totalBytes = 0;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter b = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
MemoryStream m;
try
{
foreach (string key in Session)
{
//--- First add size of key
totalBytes += key.Length * 2;
//--- Next add size of object if it exists
Object x = Session[key];
if (x != null)
{
m = new MemoryStream();
b.Serialize(m, x);
totalBytes += m.Length;
}
}
}
catch { }
return totalBytes;
}
Upvotes: 0
Reputation: 62260
we need to see the size of the objects stored in the session.
In State Server, you cannot see individual Session's size.
However, you can see the over all memory usage of aspnet_state.exe inside Task Manager. I believe it is enough to determine how much memory you need for new server.
If you want very detail, you want to spin up a new SQL Server (just for few hours to few days) to store session state, and then query the following to get the individual session state object -
SELECT [sessionid],[created], datalength(SessionItemLong)
FROM ASPStateTempSessions
If you are making a total new environment, I would suggest you to look at StackExchange's Redis Cache which is also used in Windows Azure.
Upvotes: 2
Reputation: 77876
NO, in that case you will have calculate the object before storing to session and make a total memory footprint size. See here on how you can get the size of object
How to get object size in memory?
Upvotes: 2