Sergii,
I checked in this morning to post an update about this - I had asked a
similar question previously about Tomcat setenv.sh file and settings.
In my case (similar), loads would be fine at first (0.2 0.0 0.3)
something like that. Then, over a day, it would grow and eventually I
would see something like CPU usage at 120%^ and loads of 100.0 120.0
101.0.
Something was wrong. My server is my own hardware in a colo running
Ubuntu Server 11.04. Apache 2, Tomcat 7, Railo 3, MySQL 5. It's a
dual quad core Xeon 5620 chipset, 48 GB of RAM and all SSD on GB
connection. So I/O should never be an issue. And considering that I
was running the same app for years on a 7 year old PPC (Apple) X Serve
system with no problems under Blue Dragon, surely the issue had to be
my heap settings.
After weeks of tinkering, trying different settings and researching,
here are my results.
Started with
=======> export JAVA_OPTS="-server -Xmx2g -XX:MaxPermSize=256m -
Djava.awt.headless=true";
Ran OK, but had random problems with CPU load, out of memory errors
with Railo when running large imports (XML parse).
Then... got "smart" and tried to learn all about the garbage
collection and "tweak" things (ha!)
=======> export JAVA_OPTS="-server -Xss1024k -Xms1g -Xmx16g -
XX:MaxPermSize=128m -XX:NewSize=512m -XX:+UseConcMarkSweepGC -XX:
+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=80 -
Djava.awt.headless=true"
That didn't help. Problems were only worse.
Then,
=======> export JAVA_OPTS="-server -Xss1024k -Xms1g -Xmx16g -
XX:MaxPermSize=512m -XX:NewSize=64m -XX:+UseConcMarkSweepGC -XX:
+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=80 -XX:
+CMSClassUnloadingEnabled -XX:+UseParNewGC -Djava.awt.headless=true";
Causes max cpu usage, lods above 100.0 and use of all memory. WTF?
Still believing I knew what I was doing, I tried...
=======> export JAVA_OPTS="-server -XX:+UseConcMarkSweepGC -XX:
+CMSIncrementalMode -XX:CMSInitiatingOccupancyFraction=80 -XX:
+CMSClassUnloadingEnabled -XX:+UseParNewGC -Djava.awt.headless=true";
Result, not enough memory left within the heap to run maintenance on
databases on a regular basis
Next up, more research:
-
http://sanjaal.com/java/tag/jvm-option-parameter-xxuseconcmarksweepgc/
-
http://lucene.472066.n3.nabble.com/Garbage-Collection-I-have-given-bad-advice-in-the-past-td3102099.html
Which lead to...
=======> export JAVA_OPTS="-server -Xss1024k -Xms1g -Xmx2g -
XX:MaxPermSize=512m -XX:NewSize=64m -XX:+UseParallelGC -
XX:ParallelGCThreads=16 -XX:+CMSClassUnloadingEnabled -
Djava.awt.headless=true";
Still had problems, so I tried...
=======> export JAVA_OPTS="-server -Xss1024k -Xms1g -Xmx2g -
XX:MaxPermSize=512m -XX:NewSize=64m -Djava.awt.headless=true";
this built up load until more and more cpu and memory were used.
didn't reach the 100% laods of past (70.x, etc), but was headed there.
Next up...
Found in the Railo group, according to bruce (bottom of page)
https://groups.google.com/forum/#!topic/railo/3TF9YxtEaR0
But then sean corfield weighed in, in response to me a few weeks ago
http://groups.google.com/group/railo/browse_thread/thread/bd92b0747759274d
try this next (worked fine)
=======> export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m -
XX:+ExplicitGCInvokesConcurrent -XX:+UseConcMarkSweepGC -XX:
+CMSClassUnloadingEnabled";
YES! Finally!!! Worked great! A bit slow for some page loads that are
intensive. The trick seems to be to set the Xms and Xmx to the same
so that java doesn't have to do this dynamically. Since this worked
great, decided to start adding more memory to the heap to see if there
was a limit or problem with more memory and garbage collection...
Loads were always 0.x 0.x and 0.x, CPU never above 1 or 2%
So I added more memory next to see how it would go...
=======> export JAVA_OPTS="-Xms2048m -Xmx2048m -XX:MaxPermSize=512m -
XX:+ExplicitGCInvokesConcurrent -XX:+UseConcMarkSweepGC -XX:
+CMSClassUnloadingEnabled";
Worked great! Things started speeding up (heavy database queries,
etc). Loads were always 0.x 0.x and 0.x, CPU never above 1 or 2%
More still... AND I noticed that I had left off the awt headless
flag, so I put that back in.
=======> export JAVA_OPTS="-Xms4096m -Xmx4096m -XX:MaxPermSize=512m -
XX:+ExplicitGCInvokesConcurrent -XX:+UseConcMarkSweepGC -XX:
+CMSClassUnloadingEnabled -Djava.awt.headless=true";
Things going swimmingly. Sweet! Loads were always 0.x 0.x and 0.x,
CPU never above 1 or 2%
Now, let's try 8 GB...
=======> export JAVA_OPTS="-Xms8192m -Xmx8192m -XX:MaxPermSize=512m -
XX:+ExplicitGCInvokesConcurrent -XX:+UseConcMarkSweepGC -XX:
+CMSClassUnloadingEnabled -Djava.awt.headless=true";
F'n awesome! Loads were always 0.x 0.x and 0.x, CPU never above 1 or
2%
And now, let's go to 1/3 of available RAM since that's why it's there,
no sense in having it if you're not using it - 16 GB!!
=======> export JAVA_OPTS="-Xms16384m -Xmx16384m -XX:MaxPermSize=512m
-XX:+ExplicitGCInvokesConcurrent -XX:+UseConcMarkSweepGC -XX:
+CMSClassUnloadingEnabled -Djava.awt.headless=true";
Sweet!!! Loads were always 0.x 0.x and 0.x, CPU never above 1 or 2%,
page loads are lightening fast, GB+ size data parsing it done in
seconds, everyone is flippin happy!!
Bottom line - it looks like it's a bad idea to try and be smarter
than your modern, updated software (64 bit OS, latest Java (6 or 7),
latest Tomcat and Railo. It would appear that the garbage collection
and other settings have already been considered and well implemented.
So the final setting would seem to be:
-Xms16384m
-Xmx16384m
-XX:MaxPermSize=512m
-XX:+ExplicitGCInvokesConcurrent
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-Djava.awt.headless=true";
Where -Xms16384m -Xmx16384m -XX:MaxPermSize=512m are all set
according to your available memory, and how heavy duty you think your
app is or needs or wants to be.
Hope it helps!!!
-Derrick
> Currently config looks like thishttp://
pastebin.com/jH98jEvz-- tasks work
> just fine, applications also feel OK. Only CPU usage stays high...
>
> I've played with config and looks like deleting some of the tasks helps,
> for example this is cut and "safe" version of config:
http://pastebin.com/k6QkanPg-- when I use it everything is OK.
>
> The more of "unsafe" entries I add -- the more CPU is used. In full version
> it looks like thishttp://
dl.dropbox.com/u/2495797/img/1203/tomcat-cpu-htop.png