locked
Storing in Session vs Application Memory - Advice RRS feed

  • Question

  • User-1343058805 posted

    Hi Guys,

    I need your suggestion to choose best approach of session management. Our current applicaiton storing user related information as well as search results in the session. If search results exceeds 4000 records our applicaiton fails (with unable to serialize ....), we do pagination by reading the data from session. Initial approach proven that keeping data in session and do pagination is faster but over the time data also growing.

    So Management requested development team to come up with best approach to make the application work with huge data as well as pagination.

    We have total 8 searches, current implementation stores only 1 search result in the database at a time. Out of 8 searches, 3 searches takes upto 2-3 minutes to return results (based on search criteria). 

    Approach 1: Returning 100 records at a time from the database
    In this approach, I suggested keeping the search results in session based table and return only 100 records. When user request 3 page then return 3rd 100 records etc. With this implementation storing only 100 records at a time in the session.
    Draw back: In concurrent environment, there could be multiple I/O's into session table (this session table for each sessionID  - these tables will be dropped on certain interval - this is all well planned)

    Approach 2: One of team member suggested storing session information in memory as a class object and this object is accessible until the user session is invalid. Here I have to create 8 class objects (List<T>) for each search (there 8 searches). If user performing 8 searches, there will be 8 objects sitting in the application memory until user session ends where as Approach 1 there will only one session object out of searches and stores only 100 records at time.
    Drawback:
    1. Too many objects in the memory and occupies until user session ends
    2. Storing all the records in the memory


    Number of total users are apprx 10,000 and current users at a time around 1000.

     Please let me know the best approach.

     

    Thanks

    Sham

    Wednesday, June 27, 2012 10:10 PM

Answers

  • User1943143334 posted

    Hi,

    Application State is global memory! 

    So for every session,you may store the information in Application! GC works as usual!

    Hope it helps u...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 28, 2012 11:38 AM

All replies

  • Wednesday, June 27, 2012 10:17 PM
  • User1943143334 posted

    Hi,

    First of all, avoid storing the search results in Application memory, since it's global!

     Regrading Approach 2 - 

    You can create a HashTable with unique 8 values to store the search results! Now store the Hash table in the session! Now per session there will be one session variable - Hashtable, again holds the 8 different searches as you required! 

    In this scenario, you don't need to store the data in Application state.

    Regrading performance, you may need to increase the hardware based on the traffic to your web application!

    Hope it helps u...

    Thursday, June 28, 2012 7:45 AM
  • User-1343058805 posted

    Hi Roopesh,

    Thanks for sharing your input. We are planning to increase the hardware. So search results will stored in the HashTable.


    In our design, we are planning to keep this HashTable object until user session ends. If it is not application state,
    Where can I store this hash object for further reference?
    How long this object will be available?
    Is Garbage Collector doesn't free the memory used by hash table if it is not frequently used?

    Thanks

    Sham

    Thursday, June 28, 2012 10:25 AM
  • User1943143334 posted

    Hi,

    Obvisously in Session! Session will be available until user sign off or abandoned!

    You store it in Session!!! Once the session is destroyed the memory will be free!

    Moreover, try using StateServer[Session Mode] - http://dotnetguts.blogspot.in/2009/06/steps-for-session-inproc-mode-to.html

    Hope it helps u...

    Thursday, June 28, 2012 10:29 AM
  • User-1343058805 posted

    Thanks for quick response. Our current goal is to move out everything from session.

    We are using StateServer to store session data, state server failing in case of huge search result. As per my other teammatte proposal store the search result in hashtable which is part of Applicaiton object. According to your suggestion application state is not the right place.

    Session: out of scope

    Application State: concerns are, consume lot of memory in multi user environment and there is no guarantee application objects are exist until the session ends (GC might free the objects if not frequently used)

    Thanks

    Sham

    Thursday, June 28, 2012 10:45 AM
  • User1943143334 posted

    Hi,

    Application State is global memory! 

    So for every session,you may store the information in Application! GC works as usual!

    Hope it helps u...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 28, 2012 11:38 AM