Upping Railo/Tomcat Memory

1,046 views
Skip to first unread message

Ryan Letulle

unread,
Sep 6, 2009, 11:18:00 AM9/6/09
to Railo
I am getting a "Java Heap Space" error on one of my nightly jobs.  Apparently, I am only using a max of like 90 mb of memory for Railo/Tomcat jobs which is causing my issue.

I did some googling and found this information:

The key to upping Tomcat's memory is the JAVA_OPTS variable (Java runtime options). Finding out where to up this setting was shockingly easy. After a couple of spins around Google, I found a post that pointed to the Catalina startup script. So, I opened up catalina.sh with TextMate (this file is located in Tomcat's bin folder).

Next, I searched for JAVA_OPTS. I found the following line:
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"

All I did was change it to:
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms128m -Xmx512m"

I restarted Tomcat and I was good to go. Tomcat still only used about 90 MB when it fired up but as soon as I went to parse a 3 MB XML file, no more out of memory errors. Rather than getting an OOM exception, Tomcat's RAM usage increased to 196 MB, something it never did before. What I found cool is that it did not spike from there. I ran the parsing page several times, Tomcat stayed steady at 196. Good kitty! I mean, yeah Tomcat.

Can anyone testify to this as being the correct move to make?  Save me the time of f'ing up everything else that is working ok.

--
Ryan LeTulle

Ryan Letulle

unread,
Sep 6, 2009, 11:38:19 AM9/6/09
to Railo
Update:

Looked in my installation using Jordan's Tomcat install script and found what appears to be the equivalent settings in tomcat/bin/catalina.sh.

# Set juli LogManager config file if it is present and an override has not been issued
if [ -z "$LOGGING_CONFIG" ]; then
  if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
    LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
  else
    # Bugzilla 45585
    LOGGING_CONFIG="-Dnop"
  fi
fi

if [ -z "$LOGGING_MANAGER" ]; then
  JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
  JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi

I am looking to change the highlighted text to: 

JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms128m -Xmx512m"


Can anyone out there help me to feel better about this change?

--
Ryan LeTulle

Randy

unread,
Sep 6, 2009, 12:09:56 PM9/6/09
to Railo
From a tip I got from Dave here is what I changed...:

# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for
most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="-Djava.awt.headless=true -Xms512m -Xmx512m -
XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -
XX:MaxPermSize=256m -XX:+DisableExplicitGC"
fi

This was one of the first things that appear after the general
settings in my file, but I am using the Ubuntu install, so it appears
in the /etc/init.d/tomcat6 file. But the JAVA_OPTS="-
Djava.awt.headless=true should appear in the cataline.sh.

Randy

Ryan Letulle

unread,
Sep 6, 2009, 12:20:47 PM9/6/09
to ra...@googlegroups.com
I don't have anything near that in catalina.sh.

--
Ryan LeTulle

Randy

unread,
Sep 6, 2009, 5:34:58 PM9/6/09
to Railo
Alrighty... I think someone that knows more about what they are doing
will probably respond... :) But I would guess you can put it anywhere
it's setting java_opts.

Randy

Dave

unread,
Sep 6, 2009, 10:01:04 PM9/6/09
to ra...@googlegroups.com
at the very top right after big comment block

whostheJBoss

unread,
Sep 6, 2009, 10:02:43 PM9/6/09
to Railo
I just use the {tomcat}/bin/catalina.bat and put this at the very top:

set CATALINA_OPTS="-Xms512m -Xmx512m -XX:PermSize=64M -
XX:MaxPermSize=128M"

If you edit {tomcat}/bin/catalina.sh you can use export instead of
set:

export CATALINA_OPTS="-Xms512m -Xmx512m -XX:PermSize=64M -
XX:MaxPermSize=128M"

(Adjust for real values, obviously.)

This seems to work just fine for me...

Dave

unread,
Sep 6, 2009, 10:03:06 PM9/6/09
to ra...@googlegroups.com
#   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
#                   (JSSE) installation, whose JAR files will be added to the
#                   system class path used to start Tomcat.
#
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 656834 2008-05-15 21:04:04Z markt $
# -----------------------------------------------------------------------------
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m
 -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"


# OS specific support.  $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac










On Sep 6, 2009, at 11:20 AM, Ryan Letulle wrote:

Dave

unread,
Sep 6, 2009, 10:04:00 PM9/6/09
to ra...@googlegroups.com
you could also make a file named: setenv.sh
and put it in there and stick that in the bin folder and it will get picked up






On Sep 6, 2009, at 11:20 AM, Ryan Letulle wrote:

Ryan Letulle

unread,
Sep 6, 2009, 11:28:14 PM9/6/09
to ra...@googlegroups.com
thx guys, I'll try it in the morn

--
Ryan LeTulle

Jordan Michaels

unread,
Sep 7, 2009, 2:03:20 PM9/7/09
to ra...@googlegroups.com
Exactly right Dave. =)

Ryan, if you used my installer, look for this file. Tomcat memory
settings are in there. Just change the numbers, restart, and you'll be
all set.

Warm regards,
Jordan Michaels
Vivio Technologies
http://www.viviotech.net/
Open BlueDragon Steering Committee
Adobe Solution Provider

Ryan Letulle

unread,
Sep 7, 2009, 2:32:12 PM9/7/09
to ra...@googlegroups.com
Well, I couldn't find a setenv.sh file so I put it in catalina.sh just below the first comment block.  Now the admin is correctly reporting 1510 mb.  With 2 Gig total is this amount ok?

--
Ryan LeTulle

Ryan Letulle

unread,
Sep 7, 2009, 2:37:09 PM9/7/09
to ra...@googlegroups.com
or is that the Mac x server settings ;)

BTW
Really the only other thing running of any significance is MySQL.

--
Ryan LeTulle

Jordan Michaels

unread,
Sep 7, 2009, 2:51:23 PM9/7/09
to ra...@googlegroups.com
Ryan,

Please accept my most sincere apologies. Apparently the setenv.sh file
was something I did for the OpenBD installer that I did NOT do for the
Railo installer. This will be corrected in the next release. I am very
sorry for the misinformation, and I'm glad you got it figured out
regardless.

Warm regards,
Jordan Michaels
Vivio Technologies
http://www.viviotech.net/
Open BlueDragon Steering Committee
Adobe Solution Provider


Ryan Letulle

unread,
Sep 7, 2009, 3:10:10 PM9/7/09
to ra...@googlegroups.com
Jordan
no problem, thx

--
Ryan LeTulle

Sean Corfield

unread,
Sep 7, 2009, 5:39:46 PM9/7/09
to ra...@googlegroups.com
On Sun, Sep 6, 2009 at 7:04 PM, Dave<cfl...@jamwerx.com> wrote:
> you could also make a file named: setenv.sh
> and put it in there and stick that in the bin folder and it will get picked
> up

This is the "recommended" approach. setenv.sh is an optional file that
will not be overwritten if you upgrade Tomcat and it lets you keep
your environment-specific settings isolated.

Don't forget to make it executable!
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Dave

unread,
Sep 7, 2009, 5:47:05 PM9/7/09
to ra...@googlegroups.com
on a mac you'd do this in terminal with the following command:

chmod +x setenv.sh

of course set the path to the file if you are not in the directory

Dave

unread,
Sep 7, 2009, 5:51:43 PM9/7/09
to ra...@googlegroups.com
I think I have about 40 of my sites now running railo on the xserve with 2gb set for java and there has been no issues.
Just checked the server from iphone with istat and total memory being used right now is only 541mb system wide.

Image manipulations seem to spike it a bit but still no issues. I need to get cfvideo license this week and see how that does as well.

Ryan Letulle

unread,
Sep 8, 2009, 10:26:09 AM9/8/09
to ra...@googlegroups.com
When I try to restart Tomcat using the supplied /opt/railo/railo_ctl restart I get:

Shutting down Railo: Error occurred during initialization of VM
Could not reserve enough space for object heap


I am assuming that I now have my memory settings too high:

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m
 -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"


I changed 1536 to 1024 and still get the same error.  Am I missing something or should I go down even further to say 512?  I have 2 gig of memory total on this VPS (Centos 5x, MYSQL, Tomcat, Railo)

Thx.

--
Ryan LeTulle

Andrea Campolonghi

unread,
Sep 8, 2009, 10:28:04 AM9/8/09
to ra...@googlegroups.com
Ryan,

you can start from lower memory allocation.
If jvm needs more will ask to OS and will increase memory usage.

Andrea
--
Andrea Campolonghi

http://www.andreacfm.com

Ryan Letulle

unread,
Sep 8, 2009, 10:35:58 AM9/8/09
to ra...@googlegroups.com
Thx, I changed 1536 to 512 and Tomcat restarted clean and is processing templates.

--
Ryan LeTulle

Jordan Michaels

unread,
Sep 8, 2009, 12:59:06 PM9/8/09
to ra...@googlegroups.com
Which 1536 did you change? I believe Andrea is referring to the min/max
memory specifications. IE: something like this might work better:

-Xms256m -Xmx1536m

This sets the minimum to 256 megs and the max to a gig and a half. That
leaves a lot of room for garbage collection to clean up messes and
potentially have memory enough when other applications spike in memory
usage.

Warm regards,
Jordan Michaels
Vivio Technologies
http://www.viviotech.net/
Open BlueDragon Steering Committee
Adobe Solution Provider


Ryan Letulle wrote:
> Thx, I changed 1536 to 512 and Tomcat restarted clean and is processing
> templates.
>
> --
> Ryan LeTulle
>
>
> On Tue, Sep 8, 2009 at 9:28 AM, Andrea Campolonghi
> <acampo...@gmail.com <mailto:acampo...@gmail.com>> wrote:
>
> Ryan,
>
> you can start from lower memory allocation.
> If jvm needs more will ask to OS and will increase memory usage.
>
> Andrea
>
>
> On Tue, Sep 8, 2009 at 4:26 PM, Ryan Letulle <bayo...@gmail.com
> <mailto:bayo...@gmail.com>> wrote:
>
> When I try to restart Tomcat using the supplied
> //opt/railo/railo_ctl restart/ I get:
>
> /Shutting down Railo: Error occurred during initialization of VM
> Could not reserve enough space for object heap/
>
> I am assuming that I now have my memory settings too high:
>
> /JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
> -server -Xms1536m -Xmx1536m
> -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
> -XX:MaxPermSize=256m -XX:+DisableExplicitGC"/
>> >> <mailto:zora...@gmail.com

Andrea Campolonghi

unread,
Sep 8, 2009, 1:44:27 PM9/8/09
to ra...@googlegroups.com
Yes Jordan,
I refer to Xms so that jvm starts will a lower level and if needed increase the size.
In my opinion is very hard to predict the memory that will be needed from jvm in many cases so teh risk is to allocate more memory that what will be needed especially for startup.

Andrea

Ryan Letulle

unread,
Sep 8, 2009, 2:00:33 PM9/8/09
to ra...@googlegroups.com
I understand.  For some reason I cannot restart it with the new settings right now.  I get (Could not reserve enough space for object heap).  I guess there are to many processes going.  I'll try to change them to 512/1024 tonight.

--
Ryan LeTulle

Andrea Campolonghi

unread,
Sep 8, 2009, 2:31:02 PM9/8/09
to ra...@googlegroups.com
Ryan try to reserve some space for PermGen.
That's teh plece wher obejct are done.

Andrea

Andrea Campolonghi

unread,
Sep 8, 2009, 2:34:26 PM9/8/09
to ra...@googlegroups.com

Matt Quackenbush

unread,
Oct 8, 2009, 1:34:21 AM10/8/09
to ra...@googlegroups.com
I know this thread is like a month old, but it seems to be the closest one to what I am looking for.  I am on Winbloze (XP Pro, SP 3), and have just installed Tomcat 6.0.20.  It, of course, has the default memory set, which is really, really, really low.  Everything I can find says to edit the catalina.bat or catalina.sh file (I'm assuming .bat for me, being on Winbloze).  However, I cannot find any such file.  The only catalina.* files I have found are:

{tomcat}/conf/catalina.properties
{tomcat}/conf/catalina.policy
{tomcat}/lib/catalina.jar
{tomcat}/lib/catalina-ant.jar
{tomcat}/lib/catalina-ha.jar
{tomcat}/lib/catalina-tribes.jar

Neither of the first two contain any reference to JAVA_OPTS.  What am I missing?

Thanks in advance.

Dave

unread,
Oct 8, 2009, 2:51:59 AM10/8/09
to ra...@googlegroups.com
WHAT!!!!! Winblowz rocks!!!! or so I hear.....

easiest way is to just make a new file in tomcat/bin called setenv.sh
http://emberapp.com/jamwerx/images/setenv1

add the info in there
http://emberapp.com/jamwerx/images/setenv

You can put it in catalina.sh right after the big top comment block..
it's not in there by default.

Matt Quackenbush

unread,
Oct 8, 2009, 3:28:08 AM10/8/09
to ra...@googlegroups.com
LOL  Yeah, Winbloze rawks askers.  ;-)

Okay, so, I created the setenv.sh file as directed, and placed it in {tomcat}/bin as directed.  I then restarted Tomcat in spite of not being directed to - I know, Winbloze *and* deviating from the directions....

On the Server Status page I still see the following:

Free memory: 6.41 MB Total memory: 21.07 MB Max memory: 63.56 MB

Something tells me that I screwed something up somewhere.

Oh, and the catalina.sh file simply does not exist on my machine.

Doug Boude

unread,
Oct 8, 2009, 3:29:40 AM10/8/09
to ra...@googlegroups.com
Matt,
I'm using Tomcat on Winbloze as well. My Tomcat installation included a shortcut to a little executable called "Configure Tomcat" (C:\Program Files\Tomcat6\bin\Tomcat6w.exe for my installation). This app has a few tabs, one of which is labeled "Java". In that tab is a section called "Java Options", and it is there that I added my own settings for the JVM. 

It's a lot better than hand editing freakin' configuration files. Windows may blow, but GUIs are the shiznit.

I'm going to try and attach a screenshot (PNG) of what i'm talking about since pictures really do say 1k words.

Oh, and for what it's worth, here are the settings I'm currently using (my server has 3 gb of ram, btw):

-Dcatalina.home=C:\Program Files\Tomcat6
-Dcatalina.base=C:\Program Files\Tomcat6
-Djava.endorsed.dirs=C:\Program Files\Tomcat6\endorsed
-Djava.io.tmpdir=C:\Program Files\Tomcat6\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\Program Files\Tomcat6\conf\logging.properties
-XX:MaxPermSize=768m
-Xmx1815m
-Xms1815m
-Xmn128m
-XX:PermSize=768m
-XX:+AggressiveHeap

Doug Boude  :0)
tomcatJVMsettings.png

Matt Quackenbush

unread,
Oct 8, 2009, 3:51:11 AM10/8/09
to ra...@googlegroups.com
LOL!  I routinely call it Winbloze, but I am in full agreement with your GUI assessment.  I am neither a Windows lover or hater, and I feel the exact same way about Mac (or *nix).  But, as I have told many people for many years, I can't help it... I'm a point and click kinda guy when it comes to configuration maintenance.  I have gotten better though in the last couple of years, thanks to the prodding and assistance from some guys that were born with a Unix shell in their crib.  (Perhaps it was even in the womb with them?)  ;-)

Anyways, between the two, I was able to successfully get it up and running nicely.  So, thank you Dave for most of the settings, and thank you Doug for pointing me in the right direction of where to make the change on Winbloze (my install didn't like your exact settings, but that could be because I have JRun running CF8 as well).  Oh, and yes, the pictures *definitely* helped.  :-)

Reply all
Reply to author
Forward
0 new messages