Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allocating a Java heap for Tomcat on an EC2 instance

I'm writing a Java servlet that I'm planning to deploy on Amazon AWS using Elastic Beanstalk. My tests show that things run well using a Small EC2 instance using their stock Tomcat AMI that Beanstalk uses.

I'm trying to figure out how to properly allocate Java heap space for this configuration. A Small instance has 1.7 GB of memory, so I'm thinking that a 1024MB heap will work well. I realize that memory will be needed for other things even though the only "real" purpose of this instance is to run Tomcat. And I also know that there's some point with large heaps where the standard Sun/Oracle JVM doesn't really work.

Is this a reasonable way to allocate the memory? Should I be using more or less? What tools can I use to help determine the optimal configuration?

like image 489
Sander Smith Avatar asked Nov 04 '22 09:11

Sander Smith


1 Answers

1024 seems ok, maybe a bit much.

I'm not exactly sure what your servlet is doing, but to give you an idea, I have an ecommerce application with about 1000 daily users running on 2 small ec2 instances. Tomcat load is distributed via mod_jk.

I did not tune the JVM at all and kept the default settings. I'm also using terracotta distributed object caching, and that process seems to be consuming most of the memory.

Are you deployed on a linux based os or windows? IMO, linux does a better job at managing available memory.

As to tools, I would suggest deploying your application as is to a small ec2 instance and using a tool like JMeter to stress test the application. During the stress test, you can have the top utility open(assuming your app is on linux and top is installed).

Try to break your application by seeing how much load it can handle. That's the beauty of ec2, you can setup a test environment in minutes and discard it right after.

like image 83
Roy Kachouh Avatar answered Nov 09 '22 05:11

Roy Kachouh