EC2 Tomcat

So, I’ve been using AWS EC2 for awhile to host my app. I’ve been able to get away with using 2 instances as t2.mediums for awhile. However as I get more traffic it seems like the 4GB memory isn’t enough. The instances barely break a sweat on CPU usage. I was thinking of bumping to m4.large for double the memory.

I was wondering if you had any tips/advice on what instance types or any other info really for tomcat apps!


Related discussions:

R4 has better networking and higher ram:CPU ratios so you may be able to use smaller instances. May not help at the smaller end of the instance scale though.

Have you thought about a cloudwatch alarm on the memory usage and spin up or down other ec2 in auto scaling group based on that?

It boils down to what you want to pay

r4.large looks like it’s got lots of memory, is that what you are using?

Why not t2.large? If you’re not hitting CPU or IO constraints, t2 will give you the most memory for the $ until you get to 16G, then r4 becomes most cost-effective.

If you’re not breaking s sweat on CPU what makes you think you’re short on RAM?

Right, seems like your CPU usage would increase if the RAM is full.

Not a given but yes, commonly that would be the case. If you’re short on RAM you’ll thrash GC which will materialize as heavy CPU utilization.

Other indicators are OOM errors in the application logs. GC logs are quite obvious but since they weren’t posted I’m guessing OP doesn’t have them.

Yeah, so I already have auto scaling groups in place but the ELB doesn’t seem to be balancing the load effectively.

I have alarms in place which flag over 80% memory, and looking at the CPU and memory graphs in CloudWatch ~90% memory utilization corresponds to ~5.5% CPU utilization.

Don’t GC or OOM logs setup, this would be an option to pass to Java? Would be super helpful if I could snag a resource from you! :smiley:

80% memory isn’t inherently bad. If you’re deliberately caching data in process, that would be expected. If you’re doing file I/O you’ll use block cache. Many, many scenarios where it’s perfectly normal.

Memory isn’t written to CloudWatch without an extra agent. What are you using to capture that metric and what is it measuring specifically?

I have no idea what you’re asking wrt a resource. The answer to your first question is easily googled.

I’m doing a little file I/O. Went up to m4.large increasing the dedicated Xms and xmx to 5.2 from 3.2.

I’m using the mon scripts AWS provides. Wrote a chef cookbook to install and configure them as a cron job to sent results every minute.

I was meaning as a java opt environment variable similar to xms and xmx memory arguments. Totally cool that’s you don’t have a resource I’ll just google one. :blush:

Ok, well can’t help much further w/o GC logs but what you describe isn’t inherently wrong. If you’re setting min:max to the same, it’s not uncommon for the JVM to consume the memory you allocate. If the metric is reporting above that, you may have off heap caching or FS caching kicking in. Impossible to know without you posting more detail. At the end of the day, still not seeing anything to indicate that you actually have memory pressure. Everything you describe is typical for a regular cadence of requests to an HTTP server and I still don’t see a reason to change families and sizes.

Awesome, thanks for all the help and tips. I’m putting GC logs in place now and I’ll monitor them to see what’s going on. Any particular thing you suggest I watch out for?

No problemo. Frequency and duration of collection as well as memory reclaimed during collections would be the starting point. How to do that depends on the collector you’re using.

[edit:fixed typo]