I have a Java application running under Tomcat 6.0.18 on Ubuntu. This is using Sun's 1.6.0_07 JVM. I know how to set the max heap space by setting -Xmx256m in CATALINA_OPTS. But with a lot of sessions, I still have the possibility of running out of heap space. My application uses a lot of memory per user. I know I should avoid this, but at this point I can't dramatically change the software. And most of the time we have a small number of users anyway. I would like to proactively avoid running out of heap space. I would like people get a "Server Too Busy" message, _before_ the heap is actually exhausted.
I would rather serve 40 users well than 45 users poorly. I'm wondering if there are any Tomcat configuration options, or filters, or whatever, which might address this. My current idea, which I think is solid, is to check the available memory before populating any new Session instances. My current test uses the following formula to determine the amount of space available: Runtime.getRuntime().maxMemory() -Runtime.getRuntime().totalMemory() +Runtime.getRuntime().freeMemory(); In other words, take the amount of memory we COULD allocate, subtract the amount we HAVE allocated, and then add back the amount that is allocated but unused. To phrase it another way, add the amount of free memory to the amount of unallocated memory. In practice this formula approaches zero as I get closer and closer to running out of heap space. So it seems to be correct. I’m wondering what people think of this idea, or if there is a better / simpler way to accomplish my goal. Opinions? Ideas? --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org