We run the vendor-supplied webapp in Tomcat 5.5 using the standard session manager (in-memory). Since sessions can become quite large (20M +), running out of heap space is a serious concern. Users want to keep sessions for hours, if possible, but are more likely to evict sessions than end up with a ton of space. It does not seem that the provider correctly implemented Serializable in session objects, so switching to implementing a permanent session manager is not an option.
Tomcat allows you to set the maxActiveSessions property, which will limit the total number of sessions in the manager. However, when this limit is reached, no new sessions can be created before the expiration of existing sessions. We want to photograph the least recently used sessions first.
Ideally, we would like to end some recently used sessions when heap usage approaches the Xmx setting, even if they are not old enough to expire unconditionally. A very old version of the Tomcat developer mailing list suggested that this might allow a denial of service * attack, but since this application is only available on the corporate network, we do not care.
I was thinking of expanding StandardManager to override processExpires () and additional clobber sessions if the heap usage is greater than, say, 85% of max. However, in practice this seems a little problematic. What if muuch from the heap is not specified, and the garbage collector can collect a ton of objects (if it is tired of working) to reduce the heap to 50% of the maximum? I would torment sessions unnecessarily. I think we could mitigate this risk with some aggressive garbage collection settings. Also, how can I find out how much memory I saved by ending a session? I would have to wait a few GC cycles to know for sure. Perhaps I could take a conservative approach and delete no more than N sessions per background process cycle until the memory drops below an acceptable threshold. I could serialize the session as a way to estimate how much material GC'ed will be, but it depends on the provider implementing Serializable and marking the instance variables as transient, respectively.
Has anyone solved this problem? As a short-term fix, we increase the heap size, but this tape help also has its drawbacks.
- They referred to a public site where pre-registration sessions would be created. Someone can create many new sessions and supplant those that are actually used.
Update: We really do not have much control over the system architecture, and we specifically cannot reduce the use of the session. Nevertheless, we can work with the container as much as we want. However, Tomcat is the only open source servlet container supported by vendors.