Increasing Tomcat’s memory

how-to
Aug 18, 20092 mins

If you happen to casually peruse the Grails documentation, you might notice the following note regarding memory (please note, man, that the emphasis has been added by yours truly):

If memory is not a problem on your server then allocate a large amount of memory, such as 512M or more. Also use the server VM option. EG: (-server -Xms512M -Xmx512M). Usually it is better to set both min and max heap size to the same in server applications.

Accordingly, if you’re using Tomcat (and you’d like to allocate a lot of memory), you can edit the catalina.(bin | sh) file found in the bin directory of your Tomcat installation.

For example, on a Windows machine (where I currently find myself these days), I added the following statement around line 71:

set JAVA_OPTS=%JAVA_OPTS% -server -Xms512M -Xmx512M

Incidentally, non-scientific testing of perceived performance before and after the changes listed above resulted in an extremely noticeable speed up in processing of a high volume of RESTful requests. It seems like the above note from Grails is good advice; plus, adding the -server option is a good idea in general due to the HotSpot VM’s ability to selectively compile heavily used code.

You can now follow The Disco Blog on Twitter, baby!
andrew_glover

When Andrew Glover isn't listening to “Funkytown” or “Le Freak” he enjoys speaking on the No Fluff Just Stuff Tour. He also writes articles for multiple online publications including IBM's developerWorks and O'Reilly’s ONJava and ONLamp portals. Andrew is also the co-author of Java Testing Patterns, which was published by Wiley in September 2004; Addison-Wesley’s Continuous Integration; and Manning’s Groovy in Action.

More from this author