64113

How to find out size of ASP.NET session, when there are non-serializable objects in it?

I have a feeling that I'm putting rather much data in my ASP.NET session, but I've no idea how much and if I should be concerned. I found a similar question, but that relies on serializing objects and checking their serialized size. In my case the majority of data in the session is in objects from another library which doesn't have its classes marked as "Serializable". (I know that this restricts me to using InProc session state provider, but that's another issue). Does anyone have an idea on how to traverse the object graph and find out its size?

<strong>Added:</strong> OK, one way would be a manual traversal of the object graph and usage of Marshal.SizeOf() method. But that's a lot of writing to get that working. Is there perhaps a simpler way of achieving the same effect? I'm not aiming for byte precision, I'm interested in the order of magnitude (kilobytes, megabytes, tens of megabytes...)

Answer1:

For testing, you could put together a stub Custom Session provider, implementing the SessionStateStoreProviderBase abstract class. I would write backing fields that stash everything in WebCache (so that you have session data managed), and eventually generate a statistic using the Marshal.SizeOf() method when the SetAndReleaseItemExclusive method is called.

public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { double MemSize = 0; foreach (object sessObj in item.Items) { MemSize += Marshal.SizeOf(sessObj); } }

Consult this question for more information on getting field size: Getting the size of a field in bytes with C#

Answer2:

can't you generate a heap dump and find the size of the session from that. in java land i can dump the heap then open it up in mat, find the session object and find out the size of the subgraph.

Answer3:

You can probably store the session state information in the database and check the size, but I am not sure if there is any tool out there that can let you view and traverse the object graph.

If possible, check your design one more time to see if you can minimize the information in the session.

Recommend

  • Ruby on Rails: Cant download new gems (Name or service not known)
  • Find the maximum values in 2nd column for each distinct values in 1st column using Linux
  • iterator for vector of structures in thrust
  • something like gimp “fuzzy select” in python/PIL
  • Convert LPWSTR * array of string pointers to C#
  • Prolog binary search tree test - unwanted parents' parent node comparison
  • K Shortest Path Python Not Working
  • Rely on Facebook user id as a permanent user identifier
  • Basler USB Camera byte buffer to image conversion
  • OSStatus error -50 (invalid parameters) AudioQueueNewInput recording audio on iOS
  • Finding parents in a tree hierarchy for a given child LINQ (lambda expression)
  • How to work with AMMediaType for video filters
  • How to add learning rate to summaries?
  • Pythons argparse default value doesn't work
  • How to move an element within a structure, possibly with zippers?
  • Detection of framework usage on Mac system?
  • Double dispatch in Java example
  • Regex for Specific Tag
  • C# Excel interop - how to test if interop object is still working and performing a task?
  • How can we prepend rows to a react native list-view?
  • Find JSON nested nodes using multiple string values
  • How to unpack 32bit integer packed in a QByteArray?
  • Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)
  • Azure table store snapshot/backup capability
  • Memory error in python- how to use more memory
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • How to get current document uri in XSLT?
  • What's the purpose of QString?
  • SharedPreferences or SQLite Database?
  • Sort List of Strings By Version
  • Jackson Parser: ignore deserializing for type mismatch
  • Why is the size of this struct 32?
  • Trying to switch camera back to front but getting exception
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • How do I configure my settings file to work with unit tests?
  • Is it possible to post an object from jquery to bottle.py?
  • Programmatically clearing map cache