Hi,
So I have a large domain with around 40 persistent classes (x 10-100,000 instances). The objects are connected in such a way that almost the entire database is linked together in one giant object graph. I use factory-level caching, which works quite well to reduce the load on the database.
I'm using a Servlet container and there are a few cases where I'd like to put some of the objects in this graph on the HTTP session. These situations are usually one of the following:
1. As a convenience I want to stick a single, or collection of persistent instances on the session so I can retrieve them later ...
2. I'm in the process of creating a new persistent instance. It is not actually persistent yet but it has pointers to persistent data.
At first I wasn't aware of how much memory overhead this was adding to the container. When the load went up and the server went into swap death repeatedly I realized that each HTTP session was taking 1MB or more of memory since each session was holding a copy of the entire object graph.
In case 1, it is easy enough to put the object identifier (class/id) on the session instead of the actual instance. Marshaling can even be handled transparently using the HttpSession interface.
However, I haven't figured out a nice solution for case 2. The only thing I have come up with is very messy: to save the pointers as identifiers in another session attribute or to make the new instance "aware" of both pointers and identifiers, or to alter the data model and save an unfinished instance to the database. What I'm looking for is a more transparent way of handling this stuff. Perhaps there is a way of associating the new instance with the session factory without writing it to the database.
Any suggestions?
|