I think the results are going to be pretty erratic.
The issue that I see is that the garbage collector operation is (to my
knowledge) not deterministic.
IOW, you're not really accounting for memory that could be garbage
collected. So, I think that you'll have a systematic bias showing less
memory than is actually available.
I suppose you could throw in
Runtime.getRuntime().runFinalization()
Runtime.getRuntime().gc()
However, runtime.gc() just "suggests that the Java Virtual Machine
expend effort toward recycling unused objects in order to make the
memory they currently occupy available for quick reuse"
Todd Hivnor wrote:
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
--
George Sexton
MH Software, Inc.
Voice: +1 303 438 9585
URL: http://www.mhsoftware.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org