my dog learned polymorphism*
The moose likes Servlets and the fly likes Session Object size - memory management problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Object size - memory management problem" Watch "Session Object size - memory management problem" New topic

Session Object size - memory management problem

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
I know this question may not get answerd but Im having some memory management problems on an intranet server that has me wondering about the size of some of these objects. Here is what Im doing.
I retrieve x amount of rows from a MySQL db, each row consisting of the following fields (not all have data but most do): 90 strings, 10 doubles, 18 ints. I then place these resultset rows into a container object, 1 row per object, I then place these objects into a TreeMap (Must be in the correct order) & then into a session object.
Once a row has been approved I pull the treemap out of the session, remove the related row of data & place the TreeMap back into the session using the same name, hence overwriting the old one.
The problems all started when the people who are to approve these this (hence removing rows from the system) sat on their butts for a week & didnt do anything. Now they are having memory management problems & approval are not being updated correctly. (One guy has 1300+ records to approve)
I had them reboot the server & try again....problem went away for a while then came back after approving 100 or so bids.
I have rechecked all of my code to make sure I am closing objects, only found one inputstream I had missed, all resultset, connection, statement & printwriter objects are being closed.....
So Im back at the much memory would such an operation use. The server is a brand new AMD XP2000 with 1 gb of DDR333 RAM running Linux 7.2. Its running Apache, Resin, the jdk 1.4.0 & MySQL. Does this sound like it could be filling up the memory & causing this nonsense??
Thanks in advance...Im really stumped on this one!
[ January 31, 2003: Message edited by: DC Dalton ]
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
The server should be serializing out those sessions with big objects when memory gets tight - are all of the components serializable? Are you seeing any errors with respect to serialization?
You might consider serializing out the collection yourself and just keeping a reference in the session.
Incidently, if you modify a TreeMap thats in the session, you don't have to store it back, its the same TreeMap object, you just changed the contents.
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
It sounds like you are placing way too much information on the session.
The session is intended to be used as a temporary store of information not as a replacement for a true persistent storage.
Basically all of the operations that you are doing against your TreeMap held on the session should be performed against your persistent storage instead.
Using the architecture you have got at the moment just won't scale to even a moderate number of users.
Sorry to be the bearer of bad news

Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
We ran tests this weekend on the server & even with 1300 of these bids in the session the memory useage is minimal. (200 meg of 1 gig) that is also with all the other services running on the server. What we found was a freaked out database from what looks to have been a server crash or power flicker during the week. Once I straightened out the db everything seems OK but we are testing further today.
In response to the other comment about using a persistent way to handle these, the only other way I can see to handle them would be to hit the database every time they need another row which, Im sorry, is just crazy.
I didnt know TreeMaps were by reference, are all collections this way? Boy I have to dig the books out again! I will change over my objects to implement serializable also.
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
All objects that you get from the session are passed by reference and the TreeMap just handles the references to the objects that you have placed in the Map.
I wouldn't call 200Mb minimal memory useage, thats over 150K in memory per bid. You may call it crazy but from a design perspective I would definitely write & retreive the information from the DB directly. Databases can handle large volumes of simple insert/update statements and support a large number of simultaneous users providing you allocate sufficient DB connections in the pool. As an added benefit they also provide transaction control and rollback that you won't get without a lot of additional/messy coding if you are using items in memory to simulate persistent storage.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
No you missunderstood me. That is TOTAL memory usage by the ENTIRE system & 1200 objects in a session. That includes Linux, Apache, Resin, MySQL etc, etc, etc
I agree. Here's the link:
subject: Session Object size - memory management problem
Similar Threads
getting List values out of hibernate query
ResultSet Update problem with Oracle 9i using JDBC
calculate the size of the session
ResultSet and where the data returned actually is located.
About ResultSet