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.
Related
I have several pages with about 200 images each. When I access them, Apache opens a lot of threads, using more than 1 Gb of RAM. I can see several "httpd" entries on "top" command, each using 0.6% of RAM.
All files are static, small JPG files. I'm using .htaccess for client side caching, but this is not enough since I have several new users each hour, non-cached ones.
My config:
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 30
StartServers 1
MinSpareServers 2
MaxSpareServers 4
ServerLimit 300
MaxClients 300
MaxRequestsPerChild 0
MaxRequestWorkers 300
What is the best way to serve lots of static files, per page, with low memory usage? It's a CentOS 7, Apache 2.4.6, almost in default config, except the directives above.
Thanks.
1GB Ram is quite nothing but Apache is depending also a lot about your CPU specs.
I am not sure how many CPU you have but I think the following setting need to be increased to
StartServers 5
MinSpareServers 5
MaxSpareServers 10
Also you can check the loading time using the developer tools in browser where you can check each image how much it takes to load.
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.
Currently, I'm using c3.2xlarge Amazon EC2 instance (8 vCPU and 15GB of RAM) with Apache2 installed on it. The server is under high load almost every time, so, sometimes it hangs up and CPU is overloaded for a couple minutes. Health Check reporting that instance is in unhealthy state. However, this is what I see running htop while server in a "working day" mode:
As you can see, the CPU is healthy, but only 2GB of RAM out of 15 is used.
This is mpm_prefork.conf file:
<IfModule mpm_prefork_module>
StartServers 20
MinSpareServers 20
MaxSpareServers 30
ServerLimit 360
MaxClients 360
MaxRequestWorkers 360
MaxConnectionsPerChild 1000
</IfModule>
And this is part of apache2.conf:
Timeout 200
KeepAlive On
MaxKeepAliveRequests 700
KeepAliveTimeout 5
I already changed ServerLimit and MaxClients from 150 to 360 and situation seems better (only 1GB of RAM was used before).
How can I optimize performance with prefork/apache config to archive more RAM usage and less CPU throttling?
Fond out the average amount of memory consumed by each Apache process Y (ps -ef | grep httpd). Subtract the amount of memory that other processes in your VM are consuming from 15GB (add some more buffer if you anticipate that the other processes may consume more memory in future). Let the difference be X. You can then set the MaxClients as approximately X/Y.
I have the pre_virtualhost_global.conf with these settings (worker MPM):
KeepAlive On
KeepAliveTimeout 10
MaxKeepAliveRequests 500
ServerLimit 16
MaxClients 512
MinSpareThreads 96
MaxSpareThreads 512
ThreadLimit 64
ThreadsPerChild 64
ThreadStackSize 2097152
MaxRequestsPerChild 0
and the dayli munin graph:
In the peak the server load is about 1.2, I have 4 core of CPU.
Soon I expect a traffic about two times more than it is in the graph.
My first question is everything ok with my configuration to accept much more traffic?
Second: When the server creates new threads I experience about 25-50% higher load for about 2-3 minutes, I think because of memory realocation or something. It is possible to set the server to create threads to maximum, I mean in my case to be 1024 idle threads when the server has no traffic? I have to mention, I have enough memory to serve 1024 threads.
Tweaking with Worker MPM and prefork could help in less memory consumption but increasing the maximum thread requests and max keep live request could help serving more traffic. Try this below link for Optimizing Apache for performance
I have an OSQA (python / django q&a application) installation serving 8 different sites. The sites are all in development, receiving minimal traffic. The server is a virtual private server with 512 mb of ram.
Apache is only serving dynamic pages with mod_wsgi behind Nginx. I can't stop Apache consuming more and more memory with each request until the server chokes.
I experimented with the configuration parameters without much luck to minimize the memory footprint. With the following mpm_prefork parameters in apache2.conf:
StartServers 2
MinSpareServers 1
MaxSpareServers 4
MaxClients 4
MaxRequestsPerChild 100
2 apache processes start using 4 mb and after the first request there are 4 processes with each nearly 50 mb and with each new request those 4 processes climb steadily up to nearly 200 mb each.
I feel like there is something wrong going on. Any suggestions are greatly appreciated.
KeepAlive Off
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 3
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 2
WSGIDaemonProcess osqaWSGI processes=2 python-path=/web/osqa_server:/web/osqa_server/lib/python2.6 threads=1 maximum-requests=550
WSGIProcessGroup osqaWSGI
Ran httperf against this with 10,000 concurrent hits and it was still standing.