Maximum concurrent User Configuration in Apache TCP connection setting method

Source: Internet
Author: User
Tags memory usage

Apache can choose the MPM module you want to use when configuring compilation, and use the./configure--with-mpm=mpm command. We mainly understand the two MPM modules of prefork and worker.

Prefork
If you do not explicitly specify some kind of mpm,prefork without "--WITH-MPM", the default MPM on the UNIX platform. It uses a pre-derivation subprocess that handles different requests with a separate subprocess, and the processes are independent of each other. Use Httpd-l to determine the current use of the install after make compilation and build is installed
MPM is prefork.c. View the httpd-mpm.conf configuration file, which 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>

The Prefork control process creates a process, waits a second, continues to create two, waits a second, continues to create four, after the "startservers" child process is initially established, to meet the needs of minspareservers settings ... This increases the number of processes created, up to 32 per second, until the value of the Minspareservers setting is met. This pattern can reduce system overhead to increase performance by eliminating the need to generate new processes when requests arrive. Maxspareservers sets the maximum number of idle processes, and if the number of idle processes is greater than this value, Apache automatically kill some redundant processes. This value should not be set too large, but if the value set is smaller than Minspareservers, Apache will automatically adjust it to minspareservers+1. If the site load is large, consider increasing both minspareservers and maxspareservers. Maxrequestsperchild sets the number of requests that each child process can handle. Each subprocess is automatically destroyed after processing the "Maxrequestsperchild" request. 0 means infinite, that is, the child process never destroys. Although the default setting of 0 allows each subprocess to handle more requests, it also has two important benefits if set to a value other than 0:1, to prevent accidental memory leaks. 2. The number of sub processes will be reduced automatically when the server load drops. Therefore, you can adjust this value based on the server's load. MaxClients is one of the most important of these directives, setting the request that Apache can handle at the same time, which is the most influential parameter to Apache performance. The default value of 150 is far from sufficient, and if the total number of requests has reached this value (which can be confirmed by Ps-ef|grep Http|wc-l), then the subsequent request will be queued until a processed request has been completed. This is the main reason that there are a lot of system resources left and the HTTP access is slow. Although theoretically the larger the value, the more requests can be processed, but the Apache default limit is not greater than 256. Serverlimit instructions can increase maxclients without recompiling Apache. The SERVERLIMT should be placed in the first position, which does not work between the other instructions (do not understand why).

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 to Prefork,worker's new MPM that supports multithreaded and multi-process hybrid models. Because of the use of threads, a relatively large amount of requests can be processed, and system resources are less expensive than a server-based server. However, workers also use multiple processes, and each process generates multiple threads to gain stability based on the process server. After the Configure--with-mpm=worker, make compilation, made install installation. The following default configuration segments are available in the default generated httpd-mpm.conf:

  code is as follows copy code
<ifmodule Worker.c>
Startservers 2
maxclients
minsparethreads
maxsparethreads-
Threadsperchild 25< br> maxrequestsperchild 0
</ifmodule>

Worker generates the "Startservers" subprocess by the main control process, each of which contains a fixed number of threadsperchild threads, and each thread processes the request independently. Similarly, in order not to generate a thread when the request arrives, the Minsparethreads and maxsparethreads set the minimum and maximum number of idle threads, while maxclients sets the maximum total number of simultaneous clients. If the total number of threads in the existing child process does not meet the load, the control process derives the new child process. The maximum default values for Minsparethreads and Maxsparethreads are 75 and 250, respectively. These two parameters have little effect on the performance of Apache, and can be adjusted according to the actual situation. Threadsperchild is the most performance-related instruction in worker mpm. The maximum default value for Threadsperchild is 64, and 64 is not enough if the load is large. To explicitly use the THREADLIMIT directive, its maximum default value is 20000. The total number of requests that can be processed concurrently in worker mode is determined by the total number of child processes multiplied by the Threadsperchild value and should be greater than or equal to maxclients. If the load is large and the number of existing child processes is not satisfied, the control process derives the new child process. The default maximum number of child processes is 16, which also requires an explicit declaration of serverlimit (maximum is 20000). It is important to note that if Serverlimit is explicitly declared, then the value multiplied by threadsperchild must be greater than or equal to maxclients, and maxclients must be an integer multiple of the Threadsperchild, Otherwise Apache will automatically adjust to a corresponding value.

The code is as follows Copy Code
<ifmodule worker.c>
Serverlimit 25
Threadlimit 200
Startservers 3
MaxClients 2000
Minsparethreads 50
Maxsparethreads 200
Threadsperchild 100
Maxrequestsperchild 0
</IfModule>

The following is the use of Apache Test tool AB with the test of the server (set the requested index page for the 6bytes,apache server configuration 2cpu 2G memory), cpu% for CPU utilization, MEM for memory usage (m) , requestspersecond the number of requests processed per second.
1, Prefor Way
(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
(10000,5,5,10,500,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
(10000,5,5,10,1000,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
(10000,5,5,10,1500,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. The way of worker
(Serverlimt,threadlimt,startservers,maxclients,minsparethread,maxsparethread,threadperchild,maxrequestperchild )

-N/-C (ab parameter) cpu% mem Requestspersecond
(50,500,5,10000,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,5,10000,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,5,10000,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 mode is slightly higher than the worker, but it needs a little more CPU and memory resources than Woker.

My system MPM file is posted below

The code is as follows Copy Code

#
# Server-pool Management (MPM specific)
#

#
# pidfile:the file in which the server should a record its process
# identification number when it starts.
#
# the ' This ' is the ' default pidfile for most MPMs.
#
<ifmodule!mpm_netware_module>
Pidfile "Logs/httpd.pid"
</IfModule>

#
# The Accept serialization lock file must is 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 is relevant on your
# installed httpd. Use ' apachectl-l ' to find out the
# active MPM.
#

# prefork MPM
# Startservers:number of server processes to start
# minspareservers:minimum number of server P Rocesses which are kept spare
# maxspareservers:maximum number of server processes which are kept spare
# Maxclie Nts:maximum number of server processes allowed to start
# maxrequestsperchild:maximum number of requests a server PR Ocess serves
<ifmodule mpm_prefork_module>
    startservers           5
    minspareservers       5
    maxspareservers     
    maxclients          
    maxrequestsperchild   0
</ Ifmodule>

# worker MPM
# startservers:initial number of server processes to start
# maxclients:maximum number of Simult Aneous client Connections
# minsparethreads:minimum number of worker threads which are kept spare
# Maxsparethrea Ds:maximum number of worker threads which are kept spare
# threadsperchild:constant number of worker threads in Server Process
# maxrequestsperchild:maximum number of requests a server process serves
<ifmodule mpm_worker_ Module>
    startservers          2
     maxclients         
    minsparethreads     
    maxsparethreads      
    threadsperchild     
    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 would 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 is set for this
# directive on NetWare. This would allow the thread to
# continue to service requests indefinitely.
<ifmodule mpm_netware_module>
Threadstacksize 65536
Startthreads 250
Minsparethreads 25
Maxsparethreads 250
MaxThreads 1000
Maxrequestsperchild 0
Maxmemfree 100
</IfModule>

# OS/2 MPM
# Startservers:number of server processes to maintain
# minsparethreads:minimum number of idle thr EADS per process,
#                   to handle request Spikes
# maxsparethreads:maximum number of idle threads per process
# MAXREQUESTSP Erchild:maximum number of connections per server process
<ifmodule mpm_mpmt_os2_module>
     startservers           2
    minsparethreads        5
    maxsparethreads       
    maxrequestsperchild    0
</IfModule>

# WinNT MPM
# threadsperchild:constant number of worker threads in the server process
# maxrequestsperchild:m aximum  number of requests a server process serves
<ifmodule mpm_winnt_module>
    thre adsperchild     
    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.