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
Related
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.
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.
Edit
Running my OS on the VirtualBox was the issue. As soon as I made my OS the native on the disk, I was able to see the performance boost.
Original
I've read a lot of people recommend ditching Apache+mod_php for HAProxy+nginx+PHP-FPM. I'm trying to verify that it's a more efficient setup, but am not seeing the results people describe. Both siege and ab (Apache Benchmark) are showing that Apache at any number of concurrent connections is giving better responses per second, and can support more connections .
I'm running Ubuntu 11.04 server on VirtualBox. It has 10 gigs of space, and 1,344 megs of memory. I used apt-get for installing the programs mentioned above. Here are the related config files with just the important parts included.
haproxy.cfg
global
maxconn 4096
user haproxy
group haproxy
daemon
stats socket /var/run/haproxy.sock mode 0600 level admin
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen tcpcluster *:80
mode tcp
option tcplog
balance roundrobin
server tcp01 192.168.1.199:8080 check
nginx.conf
worker_processes 2;
events {
worker_connections 768;
}
www.conf
pm = dynamic
pm.max_children = 10
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 500
apache.conf
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 10
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 10
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 10
MaxRequestsPerChild 0
</IfModule>
Given that PHP-FPM and Apache both have a maximum of 10 children, I would expect that any speed advantage would be visible. In every test I've run (always waiting until load is 0.01 before I run the test), Apache is always able to handle more request more efficiently.
Is there some other optimization that can be made so that the setup best suited to scale will outperform the setup that should not be more efficient?
Use haproxy as a connection concentrator : use "mode http" instead of "mode tcp", use "option http-server-close" and set a server maxconn value well below the worker connections value. You should cross a point where the lower concurrency brings much more performance with much lower RAM usage and better cache efficiency along the whole chain.
BTW, what are the numbers we're talking about ? Do they measure in hundreds or in thousands of requests per second ? Because clearly, the application server will make a real difference only in the higher loads. Obviously if the application runs very slowly, there is no reason to see a difference when replacing the server.
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.
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.