Tomcat6 memory allocation with Apache2 - apache

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?

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.

Related

Too many apache processes

I'm running a Centos 7.2 server with Apache version 2.4.6, with 6gb of ram and with Intel(R) Core(TM) i7-3930K CPU # 3.20GHz, 2 cores processor.
After I start apache webserver, with four wordpress sites, apache takes almost all of my ram memory and cpu, but it varies from time to time. Sometimes it takes around 1,5gb of ram and 40% cpu, but sometimes it takes all of my ram and 94% of cpu, and there are around 20 or even more of these processes :
/usr/sbin/httpd -DFOREGROUND
Taking all of ram and cpu.
After all ram i taken , mysql server crashes.
This is my httpd.conf file :
http://apaste.info/gg6
I have tried to limit processes by adding , :
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 2
MaxSpareServers 5
MaxClients 50
MaxRequestsPerChild 0
</IfModule>
But without of success,and prefork module is enabled.
Processes image
Thanks in advance :)
Did you try MaxMemFree and MaxRequestWorkers directives?
MaxMemFree sets ammount of memory in KBytes which will be availiable for each apache process without calling free() function.
MaxRequestWorkers sets ammount of simultaneous processes, other request will be queued till ListenBacklog is reached.

what causes 504 Gateway Time-out in mod_jk with tomcat7 & apache2?

I'm running tomcat 7 with apache 2.2 & mod_jk 1.2.26 on a debian-lenny x64 server with 2GB of RAM, 8GB of swap & an Intel Xeon CPU X3330. I've a GWT application which uses connection pooling to interact with backend mysql database. this application have to process many request, but each request takes a little time to process (assume 1 second) & then it must free's the allocated resources for using by the other requests. The number of concurrent clients may increase more than 200 at the pick time, but usually is less than 100.
Apache is configured in prefork-mpm mode with this configurations:
<IfModule mpm_prefork_module>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 256
MaxRequestsPerChild 2000
</IfModule>
& this is my worker.properties file:
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.connect_timeout=6000
worker.worker1.prepost_timeout=6000
worker.worker1.connection_pool_size=256
worker.worker1.connection_pool_minsize=64
worker.worker1.connection_pool_timeout=60
worker.worker1.reply_timeout=1000
worker.worker1.retries=5
worker.worker1.fail_on_status=-500
worker.worker1.cachesize=64
worker.worker1.cache_timeout=60
& this is configuration of tomcat connector in server.xml:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" connectionTimeout="60000" maxThreads="256" acceptorThreadCount="2" />
Now, the problem is that some of my application requests fail with a 504 gateway time-out error. I've changed & tested many settings is all above configuration files, but I could not gain a stable state. In addition, after some hours of running tomcat, many of running application on the server crashes with an error related to fork new processes & leak of system resources (I'm running on a VPS but I'm sure that I have enough resources & even more than I need to run such application & so I'm sure the problem is just because of bad configurations of apache, tomcat & mod_jk).
Any idea? please suggest an ideal configuration for mpm_prefork, mod_jk worker properties & tomcat connector settings with care to this spacial situation (I mean exactly we have an ajax application which process many short-time requests of many users).
Thanks

cannot launch more than 1000 apache processes though maxclients and serverlimits is set to 3000

we have a very strong server (32-cores cpu, 96GB ram) and have apache running in prefork mode. our apache2.conf file includes such settings :
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 5
MaxSpareServers 20
ServerLimit 3000
MaxClients 3000
MaxRequestsPerChild 1000
</IfModule>
the problem is, when our website is under heavy load (when apache process count reaches 1000 to be precise) (or when setting StartServers beyond 1000), apache2 freezes and needs to be restarted. Yet there is still plenty of ram, cpu is underused and apache process count is far beyond maxclients.
My question is, what should i do to allow apache to reach the maxclients configured in the conf file ?
please consider we have already played with /etc/security/limits.conf to set max opened files and nprocs to 5000 (ulimit -a showed these values were well taken into account).
No errors are shown in /var/log/apache2/error.log
Your Apache server may have a compiled in hard limit. To change it you need to recompile your webserver. The default is 200000 which should be high enough - but packages from your linux distribution may differ.
I would rather recommend to get of static file serving from your webserver. Put an nginx or lighttp server in front of your apache. Let it serve static content (images, css, javascript, etc.) and forward dynamic request to your apache.

apache/mod_wsgi: How do I spawn specific number of processes?

How do I spawn a specific number of processes in Apache when using mod_wsgi with the WSGIDaemonProcess setting?
I have my VirtualHost setup with the following (as a test):
WSGIDaemonProcess webserver user=webserver group=webserver processes=24 threads=8 display-name=%{GROUP} python-path=/var/virtualenv/lib/python2.6/site-packages
While my httpd.conf is setup as follows:
<IfModule prefork.c>
StartServers 8
MinSpareServers 1
MaxSpareServers 8
ServerLimit 24
MaxClients 24
MaxRequestsPerChild 4000
</IfModule>
Note, that I'm running a very constrained 256MB server with PostgreSQL database installed as well.
However, system shows far more than 24 processes for apache (more than 30). I expected that if I set the ServerLimit to the same as processes in WSGIDaemonProcess it would run at the constant 24. However, there seems to be a bunch of spare processes running for unknown reasons?
The ServerLimit directive has got nothing to do with mod_wsgi daemon mode. The 'processes' option to WSGIDaemonProcess is what specifies how many daemon processes mod_wsgi will create. It is a static number and not a dynamic number so just set it to how many you need. For that number of threads per process, there is no point setting it to more that 'processes=3' to start with as you are limited to 24 concurrent requests in the Apache child worker processes which proxy requests to the mod_wsgi daemon processes, so not possible to handle any more requests than that.
In general, if you are running in a memory constrained environment, then you should not be using prefork MPM but worker MPM. Is there a reason you must, such as needing to run PHP code as well? If not, change the MPM used.
How else you could configure things really depends on your code, response times and request throughput, which only you know.

Why is concurrency level not as high as expected when load testing Apache2 with "ab" ?

I am running Apache2/PHP on my CentOS 5.8 VPS server (2GB RAM, 2GHz processor) and I tried to do a basic load test. Since I am using the standard installation of Apache I assume that prefork model is the one being used. Here is the config:
<IfModule prefork.c>
StartServers 20
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
I did a short test with ab:
ab -q -c 100 -n 10000 mysite.com
In the same time I was checking mysite.com/server-status and I've never seen the number of requests currently being processed exceeding 10. How is this possible ?
According to my calculations the number of concurrent request should have been more than 10, ideally 100. Am I missing something here or Apache 2 server-status is reporting wrong ?
Thank you all.
You are correct that you could see more than 10 requests. You could in fact get more 256 concurrent requests being processed.
However, there's not enough information here to say why you didn't see more than 10 connections. Here are some possibilities:
A slow connection to the host being tested could reduce the number of parallel connections.
A slow application behind the URL being tested could reduce the number of parallel connections
Limitations in the /client/ could limit the number of the parallel connections. "ab" should provide some reporting on what level of concurrency it was able to achieve.
You could accidentally be setting "MaxClients" to a lower value elsewhere in your Apache configuration
... or you could have some other Apache configuration problem.
To provide a more specific answer, you could consider posting complete-as-possible copies of your "ab" output and the entire Apache configuration.