Search code examples
tomcatamazon-web-servicesamazon-ec2railocfml

Do multiple Tomcat instances make sense on EC2 instances?


I'm installing Railo on an AWS EC2 (Ubuntu) instance. I came across this guide for installing Railo on Ubuntu with multiple Tomcat7 instances, which prompts the following question:

Given the ability to "spin up" multiple EC2 instances and load balance with elastic IP/Route 53, does configuring each individual EC2 instance to run multiple Tomcat instances provide additional benefit? Is it worth it, or is it just redundant?


Solution

  • You'll have to identify your bottlenecks: If your server is running out of memory with a single tomcat, there's no use in starting a second tomcat. Also, if your CPU is maxed out, there's typically no advantage in spining up a second tomcat.

    However, if you're balancing between different servers anyway, have enough CPU and memory available on one machine, you might gain something from running two tomcats on one machine: E.g. you can remove one of them at a time from the loadbalancer, update it and add it to the balancer again - then do the same for the second one.

    But... you can do this with one tomcat per VM anyway.

    I'm afraid: You'll have to answer this question to yourself, by measuring: If the load that you get can be handled by 4 tomcats on 4 EC2 instances, can it also be handled by 4 tomcats on 2 EC2 instances? How many resources (CPU, memory, I/O) do you typically have free on each of the EC2 instances you run? This all is heavily dependent on your usecase and what the machines are actually doing.

    More examples: If your network bandwidth is saturated while you have CPU and memory left, a second tomcat will not leverage more bandwidth on the machine - it will only lower the throughput on the other tomcat as they'll have to share the connection bandwidth.

    If your network bandwidth is not saturated and your tomcat is waiting for external resources (e.g. webservices, databases) it might make sense to utilize surplus CPU and Memory with a second instance.

    But then there's the point of resilience: If one EC2 instance goes down, it would take two of your tomcats with it. Can you tolerate that or is that the point why you went to the cloud in the first place?