How to configure tcp connection for the maximum number of concurrent users in Apache

Source: Internet
Author: User

The httpd_mpm.conf file is in the \ conf \ extra file of your apache installation, and is still in the apache httpd. conf # Include conf/extra/httpd-mpm.conf before # Oh.

During configuration and compilation, Apache can select the desired MPM module and use the./configure -- with-mpm = MPM command. We mainly know the two MPM modules prefork and worker.

Prefork
If "-- with-mpm" is not used to explicitly specify an MPM, prefork is the default MPM on Unix platforms. It adopts the pre-Dispatch process mode and uses separate sub-processes to process different requests. processes are independent of each other. After make compilation and make install, use httpd-l to determine the currently used
MPM is prefork. c. View the httpd-mpm.conf configuration file that contains the following default configuration segments:

The Code is as follows: Copy code
<IfModule prefork. c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>

After the "StartServers" sub-process is initially created, the prefork control process creates a process to meet the needs of the MinSpareServers settings. Wait for one second to create two more processes, and then wait for one second to create four more processes ...... In this way, the number of Created processes is increased exponentially, up to 32 processes per second until the value set by MinSpareServers is met. This mode eliminates the need to generate new processes when requests arrive, thus reducing system overhead and increasing performance. MaxSpareServers sets the maximum number of idle processes. If the number of idle processes is greater than this value, Apache automatically kill unnecessary processes. This value should not be too large, but if it is smaller than MinSpareServers, Apache will automatically adjust it to MinSpareServers + 1. If the site load is large, consider increasing MinSpareServers and MaxSpareServers at the same time. MaxRequestsPerChild sets the number of requests that each sub-process can process. Each sub-process is automatically destroyed after processing "MaxRequestsPerChild" requests. 0 means that the sub-process will never be destroyed. Although the default value is 0, each sub-process can process more requests, setting it to a non-zero value also has two important advantages: 1. It can prevent accidental Memory leakage. 2. When the server load drops, the number of sub-processes is automatically reduced. Therefore, you can adjust this value based on the server load. MaxClients is the most important of these commands. It sets the request that Apache can process at the same time and is the parameter that has the greatest impact on Apache performance. The default value of 150 is far from enough. If the total number of requests has reached this value (you can confirm it through ps-ef | grep http | wc-l), the subsequent requests will be queued, until a processed request is completed. This is the main reason why there are still a lot of system resources and HTTP access is slow. In theory, the larger the value, the more requests can be processed, but the default limit of Apache cannot be greater than 256. The ServerLimit command can increase MaxClients without re-compiling Apache. ServerLimt should be placed in the first position, and it does not work between other commands (I do not understand the reason ).

The Code is as follows: Copy code
<IfModule prefork. c>
ServerLimit 10000
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 10000
MaxRequestsPerChild 0
</IfModule>

Worker
Compared with prefork, worker is a brand new MPM that supports multi-thread and multi-process hybrid models. Because threads are used for processing, a relatively large number of requests can be processed, and the overhead of system resources is smaller than that of process-based servers. However, worker also uses multiple processes, and each process generates multiple threads to achieve stability based on the process server. After configure -- with-mpm = worker, make and install it. There are the following default configuration segments in the default generated httpd-mpm.conf:

The Code is as follows: Copy code
<IfModule worker. c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

A Worker generates a "StartServers" sub-process by the main control process. Each sub-process contains a fixed number of ThreadsPerChild threads, and each thread processes Requests independently. Similarly, in order not to generate a thread when the request arrives, MinSpareThreads and MaxSpareThreads set the minimum and maximum number of Idle threads, while MaxClients sets the maximum number of clients simultaneously connected. If the total number of threads in the existing sub-process cannot meet the load, the control process will derive a new sub-process. The maximum default values of MinSpareThreads and MaxSpareThreads are 75 and 250, respectively. These two parameters have little impact on Apache performance and can be adjusted as needed. ThreadsPerChild is the most performance-related command in worker MPM. The maximum default value of ThreadsPerChild is 64. If the load is large, 64 is not enough. The ThreadLimit command must be explicitly used. The maximum default value is 20000. In Worker mode, the total number of requests that can be processed simultaneously is determined by the total number of sub-processes multiplied by the value of ThreadsPerChild. The value must be greater than or equal to MaxClients. If the load is large and the number of existing sub-processes cannot meet the requirements, the control process will derive a new sub-process. By default, the maximum number of sub-processes is 16. When you increase the number, you must explicitly declare ServerLimit (the maximum value is 20000 ). Note that if ServerLimit is explicitly declared, the value multiplied by ThreadsPerChild must be greater than or equal to MaxClients, and MaxClients must be an integer multiple of ThreadsPerChild, otherwise, Apache automatically adjusts to a corresponding value.

The Code is as follows: Copy code
<IfModule worker. c>
ServerLimit 25
ThreadLimit 200
StartServers 3
MaxClients 2000
MinSpareThreads 50
Maxsparethread S 200
ThreadsPerChild 100
MaxRequestsPerChild 0
</IfModule>

The following shows how to test the Server using the test tool AB provided by Apache (set the index page of the request to 6 bytes, and configure 2 cpu and 2G memory for Apache Server). The cpu % indicates the cpu usage, mem indicates the memory usage (in MB), and RequestsPerSecond indicates the number of requests processed per second.
1. Prefor Mode
(ServerLimit, StartServer, MinSpareServers, MaxSpareServers, MaxClients, MaxRequestPerChild)

-N/-c (AB parameter) Cpu % Mem Requestspersecond
(-, 5, 5, 10,150, 0)
100000/100 28.8 285 8434
100000/200 29.2 304 8032
100000/500 25.3 323 7348
100000/1000 24.4 330 5886
(Random, 5, 5, 10, 0)
100000/100 28.7 371 8345
100000/200 27.4 389 7929
100000/500 24.9 417 7229
100000/1000 23.4 437 6676
(Random, 5, 5, 10, 0)
100000/100 28.8 408 8517
100000/200 27.0 422 8045
100000/500 24.2 455 7236
100000/1000 22.5 470 6570
(Random, 5, 5, 10, 0)
100000/100 29.6 330 8407
100000/200 28.1 349 8014
100000/500 26.4 380 7290
100000/1000 24.0 400 6686
 

2. Worker Mode
(ServerLimt, Threadlimt, Startservers, MaxClients, MinspareThread, MaxspareThread, ThreadperChild, MaxRequestPerChild)

-N/-c (AB parameter) cpu % mem RequestsperSecond
(50,500, 50,200,200, 0)
100000/100 18.6 188 6020
100000/200 20.1 195 5892
100000/500 19.8 209 5708
100000/1000 22.2 218 6081
(100,500, 50,200,100, 0)
100000/100 24.5 240 6919
100000/200 23.6 247 6798
100000/500 24.6 254 6827
100000/1000 22.3 271 6114
(200,500, 50,200, 50, 0)
100000/100 27.3 301 7781
100000/200 27.4 307 7789
100000/500 26.0 320 7141
100000/1000 21.8 344 6110

Relatively speaking, the prefork method is faster than worker, but it requires a little more cpu and memory resources than woker.

Paste the mpm file of my system below

 

The Code is as follows: Copy code

#
# Server-Pool Management (MPM specific)
#

#
# PidFile: The file in which the server shoshould record its process
# Identification number when it starts.
#
# Note that this is the default PidFile for most MPMs.
#
<IfModule! Mpm_netware_module>
PidFile "logs/httpd. pid"
</IfModule>

#
# The accept serialization lock file must be stored on a local disk.
#
<IfModule! Mpm_winnt_module>
<IfModule! Mpm_netware_module>
LockFile "logs/accept. lock"
</IfModule>
</IfModule>

#
# Only one of the below sections will be relevant on your
# Installed httpd. Use "apachectl-l" to find out
# Active mpm.
#

# Prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>

# Worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

# BeOS MPM
# StartThreads: how many threads do we initially spawn?
# MaxClients: max number of threads we can have (1 thread = 1 client)
# MaxRequestsPerThread: maximum number of requests each thread will process
<IfModule mpm_beos_module>
StartThreads 10
MaxClients 50
# MaxRequestsPerThread 10000
</IfModule>

# NetWare MPM
# ThreadStackSize: Stack size allocated for each worker thread
# StartThreads: Number of worker threads launched at server startup
# MinSpareThreads: Minimum number of idle threads, to handle request spikes
# MaxSpareThreads: Maximum number of idle threads
# MaxThreads: Maximum number of worker threads alive at the same time
# MaxRequestsPerChild: Maximum number of requests a thread serves. It is
# Recommended that the default value of 0 be set for this
# Directive on NetWare. This will allow the thread
# Continue to service requests indefinitely.
<IfModule mpm_netware_module>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
Maxsparethread s 250
MaxThreads 1000
MaxRequestsPerChild 0
Maxapsaradb for memfree 100
</IfModule>

# OS/2 MPM
# StartServers: Number of server processes to maintain
# MinSpareThreads: Minimum number of idle threads per process,
# To handle request spikes
# MaxSpareThreads: Maximum number of idle threads per process
# MaxRequestsPerChild: Maximum number of connections per server process
<IfModule mpm_mpmt_os2_module>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 0
</IfModule>

# 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
MaxRequestsPerChild 0
</IfModule>

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.