How do I know the size of an ASP.NET session when it has non-serializable objects?

It feels like I'm putting quite a lot of data into my ASP.NET session, but I don't know how much and if I should be worried. I found a similar question , but it depends on the serialization of the objects and checking their serialized size. In my case, most of the data in the session is in objects from another library that does not have classes marked as "Serializable". (I know this limits me to using the InProc session state provider, but this is another problem). Does anyone have an idea on how to cross an object graph and find out its size?

Added: OK, one of the ways is to manually traverse the graph of objects and use the Marshal.SizeOf () method. But it is a lot of writing to make work. Perhaps there is an easier way to achieve the same effect? I'm not aiming at byte precision, I'm interested in the order of magnitude (kilobytes, megabytes, tens of megabytes ...)

+2
source share
3 answers

, SessionStateStoreProviderBase. , WebCache (, ), , Marshal.SizeOf(), SetAndReleaseItemExclusive.

        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);
        }

}

: #

+1

. java- , mat, .

+1

You can probably save the session state information in the database and check the size, but I'm not sure if there is any tool there that can allow you to view and move the graph of objects.

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

-1
source

Source: https://habr.com/ru/post/1710144/


All Articles