How can I optimize the number of apache concurrency settings?

Source: Internet
Author: User

1. Modify it in the httpd. conf file.

The code is as follows: Copy code
# Server-pool management (MPM specific)
# Include conf/extra/httpd-mpm.conf


Remove the # comment in the above sentence

2. Determine the current MPM mode of apache (winnt mode, worker K mode, and worker mode)

1. For the ipvk. c module

Each sub-process has only one thread. Each process can maintain only one connection at a specified time. On most platforms, the Prefork MPM is more efficient than the Worker MPM, but the memory usage is much larger. Prefork's wireless program design will be more advantageous in some cases than worker: it can use third-party modules that do not handle thread security well.
Since it is a process and a thread, in prefork. c, the two values are equal. Note: The maximum ServerLimit value is 2000.

2. For the work. c module

It is multi-threaded. By default, a process has 25 threads. Therefore, if ServerLimit is set to 100, MaxClients can be set to 2500 at most.
Here we talk about our poor vps, in order to save money, generally only-1 GB memory, and prefork. c. A process occupies about 30-45 MB of memory (this value is equivalent to the php-cgi memory usage in php-fpm). Therefore, if there is MB of memory, the system + mysql (minimum configuration savings) eat about MB, and the remaining memory is to run 10 processes, so this value is really poor, but for sites with low traffic, this concurrency is enough, generally, it is not a problem to run thousands of traffic. Therefore, for web services, it is more appropriate to get more memory or run lnmp.

Go to the apache/bin directory
Cmd command: httpd.exe-1

Note: mpm_xxx.c. If xxx is winnt, it indicates winnt. It may also be a worker k or worker.

3. Modify the httpd-mpm.conf file

The code is as follows: Copy code
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_winnt_module>
ThreadsPerChild 150 // modify the value.
MaxRequestsPerChild 0
</IfModule>


4. Restart apache and test it.

In Linux, the MPM mode is generally used.
The code is as follows: Copy code
<IfModule mpm_prefork_module>
StartServers 5 // start five processes in advance
MinSpareServers 5 // minimum idle process
MaxSpareServers 10 // maximum number of idle processes
MaxClients 150 // number of concurrent connections
MaxRequestsPerChild 0 // specifies the number of threads in a process, which is better for worker. 0 is not limited.
</IfModule>


Provide you with reasonable suggestions for some websites and medium-sized websites:

The code is as follows: Copy code
<IfModule mpm_prefork_module>
StartServers 5 // start five processes in advance
MinSpareServers 5 // minimum idle process
MaxSpareServers 10 // maximum number of idle processes
ServerLimit 1500 // used to modify apache programming parameters
MaxClients 1000 // number of concurrent connections
MaxRequestsPerChild 0 // specifies the number of threads in a process, which is better for worker. 0 is not limited.
</IfModule>


If your website has a pv of 1 million, you can set it as follows:

The code is as follows: Copy code
ServerLimit 2500 // used to modify apache programming parameters
MaxClients 2000 // number of concurrent connections


/******* Comment ********/

StartServers
Specifies the number of sub-processes created when the server starts. The default value of prefork is 5.
MinSpareServers
Minimum number of idle sub-processes. The default value is 5. If the number of idle sub-processes is less than MinSpareServers,
Apache will generate a new sub-process at a maximum speed per second. Do not set this parameter too large.
MaxSpareServers
Set the maximum number of idle sub-processes. The default value is 10. If there are idle sub-processes that exceed the number of MaxSpareServers, the parent process will kill the redundant sub-processes.
Do not set this parameter too large. If you set the value of this command to a smaller value than MinSpareServers, Apache will automatically change it to "MinSpareServers + 1 & Prime ;.
MaxClients
Limit the maximum number of client access requests (the number of concurrent threads of a single process) at the same time. The default value is 256. Any request that exceeds the limit of MaxClients will enter the waiting queue. Once a link is released,
Requests in the queue will receive services. To increase this value, you must increase ServerLimit at the same time.
MaxRequestsPerChild
Each sub-process allows the maximum number of requests of the servo within its lifetime. The default value is 10000. When the limit of MaxRequestsPerChild is reached, the sub-process will end.
If MaxRequestsPerChild is "0 & Prime;", the child process will never end. Setting MaxRequestsPerChild to a non-zero value has two advantages:

1. It can prevent (accidental) infinite memory leakage and thus exhaust the memory.
2. A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.

Supplement: how to use the AB tool for Apache stress testing

Run cmd to enter the doscommand line interface, cd to enter the Apache/bin directory, and enter the command:
AB .exe-n 10000-c 100 localhost/index. php
The preceding command line indicates that the index. php page is accessed 10000 times, and the concurrent access is 100 each time. After the command is executed, wait patiently for a while and the following results will be displayed. The image details the meaning of the results returned by the test.
The-c concurrency parameter indicates the total number of executions. For example,-c 10000 indicates a total of 10000 executions,
Parameter-n requests indicates the number of simultaneous connections

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.