Hi All, We wanted to load balance tomee(tomcat) server.I.e we want to make 2-3 separate tomcat instances and load balance with Apache.Can any once suggest max how many tomcat instance I can keep in a single server .
Server Details .
RAM: 16 GB
OS: W2008 R2
Processor: Intel(R) Xeon (R)2.70 GHZ
No of Cores: 4
We have single server now and we want to use that server only .So,I want to create max possible tomcat instance on single server.We don't want to buy new server to create more tomcat instance.
I don't see how multiple Tomcat processes on the same server can facilitate load balancing.
It's still the same machine with limited number of cores, limited RAM, and limited network bandwidth, but now with additional overheads of process switching and process memory.
AFAIK, tomcat has a thread pool based architecture, not an event loop. So a request serviced by 1 tomcat with a threadpool of 4n threads is the same as 4 tomcats with a total threadpool of 4n threads, and without the overheads.
Multiple tomcats on same server is not true horizontal scaling in my opinion.
posted 4 years ago
@Tim - Thanks
@Karthik :Thnaks . tomcat has a thread pool based architecture, not an event loop. So a request serviced by 1 tomcat with a threadpool of 4n threads is the same as 4 tomcats with a total threadpool of 4n threads, and without the overheads. .Are you saying here Should we increase thread pool on each instance .I am not much aware of tomcat architecture,setting.Can you elaborate or provide some reference url so that i can get more details.
Are you saying even if I create a extra instance (2nd tomcat instance ) ,it will increase performance/stability ?
load balance tomee(tomcat) server.I.e we want to make 2-3 separate tomcat instances and load balance with Apache. So,I want to create max possible tomcat instance on single server.We don't want to buy new server to create more tomcat instance.
I'll explain with an example scenario of what I mean.
You have 1 tomcat instance now.
Let's say you have set up CPU, memory and network performance monitoring on your server.
From your web server logs, you have found that you have a constant number of upto 500 or so concurrent requests.
From your perf monitoring, you've seen that one or more resources is overwhelmed.
It may be that CPU usage is uncomfortably high constantly (say > 80%).
Or memory usage is high (say > 80% of max heap), resulting in frequent garbage collections and increasing response delays.
Whatever it is, now you want to "load balance" to avoid overwhelming the server.
The correct way to load balance is to add more machines.
Earlier, you had 1 server with 4 cores and 16GB, and it was overwhelmed.
So you buy a second identical server and now you have totally 8 cores and 32GB.
Half the requests can now be distributed to the second machine, and that reduces the load on the first overwhelmed server.
This concept can be extended to any number of servers, because each one *adds* to your total CPU, memory, and network resource (strictly speaking, network bandwidth is still limited upstream, but until the upstream's limit is reached, it's still adding up).
But when you launch multiple tomcat instances on the *same* server, it's not adding anything to your total resources.
It's just making those resources even more scarce per instance.
If the single tomcat instance was overwhelmed earlier at 500 requests, each instance will become overwhelmed even earlier now
(maybe at 75 requests), because each one of them is competing with other instances for the same resources.
(2nd tomcat instance ) it will increase performance/stability ?
It won't increase performance.
But it can improve *availability* under standard loads.
If the single tomcat instance crashes due to some error, site visitors will get an error until it restarts.
But with additional instances, another instance can pick up the request immediately and respond.
But if the server itself crashes, it won't help with availability either, because all instances go down at the same time.
Are you saying here Should we increase thread pool on each instance
No, my point was to illustrate that adding more tomcat instances on same server is not going to balance CPU load, because there is no difference between 200 threads in 1 instance or 50 threads across 4 instances. From CPU point of view, it's still 200 threads and it still has only 4 cores to service them.