Search code examples
apachetomcatubuntumemorytomcat6

Tomcat6 memory allocation with Apache2


I have fronted Tomcat6 with Apache2.

On an Ubuntu instance I have Apache2 running with 8GB RAM, so decided to have following apache2.conf configurations.

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          550
    ServerLimit         550
    MaxRequestsPerChild  0
</IfModule>

Above configuration was done using below parameters and this blog post(how to configure apache MPM).

Apache Memory Usage (MB): 611.719
Average Proccess Size (MB): 8.26647

On another instance I have a Tomcat6 running with 8GB RAM. In the Tomcat6 server.xml following configuration is used.

<Connector port="8009" protocol="AJP/1.3" redirectPort="8080" maxThreads="500"/>

My problems are,

  • What's the process/steps to calculate/decide the number maxThreads parameter in Tomcat6?
  • How should be memory allocation should be done?

Solution

  • Tomcat6 is a Java application and as such memory allocation is done by the JVM. I suppose that you are willing to proxy tomcat through apache, if so usually 1 apache client will end up as 1 apache thread, so having a lower number of threads in tomcat than MaxClients directive in apache is advisable. This said, to calculate the maxThreads parameter might be difficult, depending on your application each thread may vary its memory usage, having an average might be useful but you have to take also into account other JVM memory spaces, eden, permgen, ...

    Take a look at JVM memory settings, per thread stack settings, ...I think this is what you might be looking for.