search
HomeOperation and MaintenanceApacheApache changes the maximum number of concurrent connections

Apache changes the maximum number of concurrent connections

Oct 26, 2020 pm 04:38 PM
apacheNumber of concurrent connections

Apache changes the maximum number of concurrent connections

Apache provides multiple different MPM modules for different operating systems, such as: mpm_beos, mpm_event, mpm_netware, mpmt_os2, mpm_prefork, mpm_winnt, mpm_worker. If conditions permit, we can compile the specified MPM module into our own Apache according to actual needs (Apache's source code is open, allowing users to compile it themselves). However, if we do not choose during compilation, Apache will select the corresponding MPM module according to different operating systems according to the following table. This is also the MPM module recommended by Apache for different platforms.

(Recommended tutorial: apache)

Default MPM module on different operating systems

Operating system MPM module description

Windowsmpm_winnt No need to introduce it:)

Unix/Linuxmpm_prefork No need to introduce it:)

BeOSmpm_beos is a multimedia operating system developed by Be Company. The official version has stopped updating.

Netwarempm_netware A network operating system launched by NOVELL

OS/2mpmt_os2 An operating system originally jointly developed by Microsoft and IBM, now developed solely by IBM (Microsoft gave up OS/2 , switch to developing Windows)

mpm_event module can be regarded as a variant of mpm_worker module, but it is experimental and is generally not recommended for use.

Of course, Apache also provides finished Apache on its official website that has compiled corresponding MPM modules according to different operating systems. You can click here to enter the Apache official website to download.

In addition, if we want to know what kind of MPM module is used internally in an Apache, we can enter the Apache installation directory\bin using the command line, and then type the command httpd -l to view Which MPM module is currently used internally by Apache.

Use the httpd -l command to view the compiled module

Since in normal development work, BeOS, NetWare, OS/2 and other operating systems are not common, here we mainly focus on Windows and Unix/ The MPM module on the Linux operating system is explained. On Windows and Unix/Linux operating systems, there are three main MPM modules: mpm_winnt, mpm_prefork, and mpm_worker.

mpm_prefork module

mpm_prefork module is mainly used in the Apache server on Unix/Linux platform. Its main working method is: when the Apache server is started, the mpm_prefork module will pre-create multiple child processes (the default is 5), after receiving the client's request, the mpm_prefork module then transfers the request to the sub-process for processing, and each sub-process can only be used to process a single request at the same time. If the current number of requests will exceed the number of pre-created sub-processes, the mpm_prefork module will create new sub-processes to handle the additional requests. Apache always tries to keep some spare or idle child processes available for upcoming requests. In this way, the client's request does not need to wait for the child process to be generated after receiving it.

Since in the mpm_prefork module, each request corresponds to a child process, it occupies more system resources than the other two modules. However, the advantage of the mpm_prefork module is that each of its sub-processes will handle the corresponding single request independently, so that if a problem occurs with one of the requests, it will not affect other requests. At the same time, the mpm_prefork module can be applied to third-party modules that are not thread-safe (such as non-thread-safe versions of PHP), and is easy to debug on platforms that do not support thread debugging. In addition, the mpm_prefork module also has higher stability than the mpm_worker module.

mpm_worker module

The mpm_worker module is also mainly used in the Apache server on the Unix/Linux platform. It can be regarded as an improved version of the mpm_prefork module. The mpm_worker module works similarly to the mpm_prefork module. However, when processing the same request, process-based (such as mpm_prefork) takes up more system resources than thread-based processing. Therefore, unlike the mpm_prefork module, the mpm_worker module will allow each child process to create a fixed number of service threads and a listening thread, and let each service thread handle the client's request. The listening thread is used to monitor access requests and send them Passed to the service thread for processing and response. Apache always tries to maintain a pool of spare or idle service threads. In this way, the client does not need to wait for a new thread or process to be established before it can be processed.

Compared with the mpm_prefork module, the mpm_worker module can further reduce system resource overhead. In addition, it also uses multiple processes, and each process has multiple threads, so it adds a certain degree of stability compared to a completely thread-based processing method.

mpm_winnt module

mpm_winnt module is an MPM module optimized and designed specifically for Windows operating systems. It only creates a separate child process and spawns multiple threads in this child process in turn to handle the request.

Modify MPM module configuration

After having a certain understanding of Apache's MPM module, we can modify Apache's maximum concurrent connection configuration for different MPM modules.

1. Enable MPM module configuration file

There is a configuration file named httpd-mpm.conf in the Apace installation directory/conf/extra directory. This file is mainly used to configure the MPM module. However, by default, Apache's MPM module configuration file is not enabled. Therefore, we need to enable this configuration file in the httpd.conf file as follows:

# Server-pool management (MPM specific)Include conf/extra/httpd-mpm.conf (remove the Comment symbol "#")

2. Modify the relevant configuration in the MPM module configuration file

After starting the MPM module configuration file, we can use a text editor to open the configuration file, we You can see that there are many configuration nodes in this configuration file, as shown in the figure below:

The corresponding configuration will only take effect when Apache uses the corresponding MPM module

At this time, we need Modify the parameter configuration under the corresponding node according to the MPM module currently used by the Apache server. First, let's take a look at the default configuration under the mpm_winnt module:

#Since the mpm_winnt module will only create one sub-process, the parameter settings for a single sub-process here are equivalent to the parameter settings for the entire Apache. ThreadsPerChild 150# Recommended settings: Small website=1000 Medium website=1000~2000 Large website=2000~3500MaxRequestsPerChild 0# Recommended settings: Small=10000 Medium or large=20000~100000

The corresponding configuration parameters are as follows:

ThreadsPerChild

The maximum number of concurrent threads per child process.

MaxRequestsPerChild

The total number of requests that each child process is allowed to handle. If the cumulative number of requests processed exceeds this value, the subprocess will end (and then determine whether to create a new subprocess as needed). Setting this value to 0 means that the total number of requests is not limited (the subprocess will never end).

It is recommended to set this parameter to a non-zero value, which can bring the following two benefits:

It can prevent possible memory leaks in the program from continuing indefinitely, thereby exhausting memory.

Give processes a limited lifetime to help reduce the number of active processes when server load is reduced.

Note: Among the above parameters related to counting the number of requests, for KeepAlive connections, only the first request will be counted.

Next, let’s take a look at the default configuration under the mpm_perfork module and mpm_worker module:

#mpm_perfork module StartServers 5# Recommended settings: Small = Default Medium = 20~50 Large = 50~100MinSpareServers 5# Recommended settings: consistent with StartServers MaxSpareServers 10# Recommended settings: Small=20 Medium=30~80 Large=80~120 MaxClients 150# Recommended settings: Small=500 Medium=500~1500 Large=1500~3000MaxRequestsPerChild 0# Recommended Settings: Small = 10000 Medium or Large = 10000~500000 (In addition, you need to set the ServerLimit parameter additionally, which is best consistent with the value of MaxClients.)

# StartServers:  数量的服务器进程开始
# MinSpareServers:  最小数量的服务器进程,保存备用
# MaxSpareServers:  最大数量的服务器进程,保存备用
# MaxRequestWorkers:  最大数量的服务器进程允许开始
# MaxConnectionsPerChild:  最大连接数的一个服务器进程服务

prefork The control process initially establishes "StartServers" After the child process is created, create a process to meet the needs set by MinSpareServers, wait for one second, continue to create two, wait for another second, continue to create four... In this way, the number of created processes will be increased exponentially, up to a maximum of one second. 32, until the value set by MinSpareServers is met. This mode eliminates the need to create a new process when a request comes, thereby 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 will automatically kill some redundant processes. Do not set this value too large, but if the value is smaller than MinSpareServers, Apache will automatically adjust it to MinSpareServers 1. If the site load is heavy, consider increasing both MinSpareServers and MaxSpareServers.

MaxRequestsPerChild sets the number of requests that each child process can handle. Each child process will be automatically destroyed after processing "MaxRequestsPerChild" requests. 0 means infinite, that is, the child process is never destroyed. Although the default setting to 0 allows each child process to handle more requests, setting it to a non-zero value also has two important benefits:

1. It can prevent accidental memory leaks. 2. When the server load decreases, the number of child processes will be automatically reduced.

Therefore, this value can be adjusted according to the load of the server.

The MaxRequestWorkers directive set will limit the number of requests that can be serviced simultaneously. Any connection attempts within the MaxRequestWorkerslimit will usually be queued, up to a number of directives based on the ListenBacklog.

In versions prior to apache2.3.13, MaxRequestWorkers was called MaxClients.

(MaxClients is the most important of these instructions. It sets the requests that Apache can handle at the same time. It is the parameter that has the greatest impact on Apache performance. Its default value of 150 is far from enough. If the request The total number has reached this value (can be confirmed by ps -ef|grep http|wc -l), then subsequent requests will be queued until a processed request is completed. This means that there are still a lot of system resources left but HTTP access is not The main reason for being very slow. Although in theory, the larger the value, the more requests that can be processed, but Apache's default limit cannot be greater than 256.)

#mpm_worker module StartServers 2#Recommended settings: Small=Default Medium=3~5 Large=5~10MaxClients 150#Recommended settings: Small=500 Medium=500~1500 Large=1500~3000MinSpareThreads 25#Recommended settings: Small= Default medium=50~100 Large=100~200MaxSpareThreads 75#Recommended settings: Small=Default medium=80~160 Large=200~400 ThreadsPerChild 25#Recommended settings: Small=Default medium=50~100 Large=100~200MaxRequestsPerChild 0# Recommended settings: Small = 10000 Medium or Large = 10000~50000 (In addition, if MaxClients/ThreadsPerChild is greater than 16, you need to set the ServerLimit parameter additionally. ServerLimit must be greater than or equal to the value of MaxClients/ThreadsPerChild.)

Corresponding configuration The parameters are as follows:

StartServers

The number of child processes created when starting Apache.

MinSpareServers

The minimum number of child processes that are idle.

The so-called idle child process refers to a child process that is not processing requests. If the current number of idle child processes is less than MinSpareServers, Apache will spawn new child processes at a maximum rate of one per second. Adjusting this parameter is only necessary on very busy machines. This value should not be too large.

MaxSpareServers

The maximum number of child processes that are idle.

This parameter needs to be adjusted only on very busy machines. This value should not be too large. If you set the value of this directive to be smaller than MinSpareServers, Apache will automatically modify it to MinSpareServers 1.

MaxClients

The maximum number of requests allowed for simultaneous connections.

Any request that exceeds the MaxClients limit will enter the waiting queue until the maximum value of the ListenBacklog directive limit is reached.

For non-threaded MPM (that is, mpm_prefork), MaxClients indicates the maximum number of child processes that can be used to handle client requests. The default value is 256. To increase this value, you must also increase ServerLimit.

For threaded or mixed MPM (that is, mpm_beos or mpm_worker), MaxClients represents the maximum number of threads that can be used to process client requests. The default value of threaded mpm_beos is 50. The default value for mixed MPM is 16 (ServerLimit) times 25 (ThreadsPerChild). Therefore, when increasing MaxClients to more than 16 processes to provide, you must also increase the value of ServerLimit.

MinSpareThreads

Minimum number of threads in idle state.

Different MPMs handle this command differently:

The default value of mpm_worker is 75. This MPM will monitor the number of idle threads on an entire server basis. If the total number of idle threads in the server is too few, the child process will generate new idle threads. The default value of mpm_netware is 10. Since this MPM only runs a single child process, of course this MPM also monitors the number of idle threads based on the entire server. mpm_beos and mpmt_os2 work similar to mpm_netware. The default value of mpm_beos is 1; the default value of mpmt_os2 is 5.

MaxSpareThreads

The maximum number of threads in idle state.

Different MPMs handle this command differently:

The default value of mpm_worker is 250. This MPM will monitor the number of idle threads on an entire server basis. If the total number of idle threads in the server is too large, the child process will kill the excess idle threads. The default value of mpm_netware is 100. Since this MPM only runs a single child process, of course this MPM also monitors the number of idle threads based on the entire server. mpm_beos and mpmt_os2 work similar to mpm_netware. The default value of mpm_beos is 50; the default value of mpmt_os2 is 10.

Note: ServerLimit represents the maximum number of processes that Apache allows to create. It is worth noting that Apache has an internal hard limit of ServerLimit 20000 at compile time (ServerLimit 200000 for the mpm_prefork module). You cannot exceed this limit.

Be especially careful when using this command. If ServerLimit is set to a value much higher than actually needed, too much shared memory will be allocated. If you set ServerLimit and MaxClients to exceed the system's processing capabilities, Apache may not start, or the system may become unstable.

Note: When configuring relevant parameters, please first ensure that the server has sufficient hardware performance (for example: CPU, memory, etc.). If you find that the server's memory usage has increased as the server's running time has increased since startup, it may be a memory leak in the program. Please adjust the value of the parameter MaxRequestsPerChild downward to reduce the impact of the memory leak, and then proceed as soon as possible. Find out where the problem is in the program.

The above is the detailed content of Apache changes the maximum number of concurrent connections. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:简书. If there is any infringement, please contact admin@php.cn delete
Apache's Legacy: Impact on Web HostingApache's Legacy: Impact on Web HostingMay 06, 2025 am 12:03 AM

Apache's impact on Webhosting is mainly reflected in its open source features, powerful capabilities and flexibility. 1) Open source features lower the threshold for Webhosting. 2) Powerful features and flexibility make it the first choice for large websites and businesses. 3) The virtual host function saves costs. Although performance may decline in high concurrency conditions, Apache remains competitive through continuous optimization.

Apache: The History and Contributions to the WebApache: The History and Contributions to the WebMay 05, 2025 am 12:14 AM

Originally originated in 1995, Apache was created by a group of developers to improve the NCSAHTTPd server and become the most widely used web server in the world. 1. Originated in 1995, it aims to improve the NCSAHTTPd server. 2. Define the Web server standards and promote the development of the open source movement. 3. It has nurtured important sub-projects such as Tomcat and Kafka. 4. Facing the challenges of cloud computing and container technology, we will focus on integrating with cloud-native technologies in the future.

Apache's Impact: Shaping the InternetApache's Impact: Shaping the InternetMay 04, 2025 am 12:05 AM

Apache has shaped the Internet by providing a stable web server infrastructure, promoting open source culture and incubating important projects. 1) Apache provides a stable web server infrastructure and promotes innovation in web technology. 2) Apache has promoted the development of open source culture, and ASF has incubated important projects such as Hadoop and Kafka. 3) Despite the performance challenges, Apache's future is still full of hope, and ASF continues to launch new technologies.

The Legacy of Apache: A Look at Its Impact on Web ServersThe Legacy of Apache: A Look at Its Impact on Web ServersMay 03, 2025 am 12:03 AM

Since its creation by volunteers in 1995, ApacheHTTPServer has had a profound impact on the web server field. 1. It originates from dissatisfaction with NCSAHTTPd and provides more stable and reliable services. 2. The establishment of the Apache Software Foundation marks its transformation into an ecosystem. 3. Its modular design and security enhance the flexibility and security of the web server. 4. Despite the decline in market share, Apache is still closely linked to modern web technologies. 5. Through configuration optimization and caching, Apache improves performance. 6. Error logs and debug mode help solve common problems.

Apache's Purpose: Serving Web ContentApache's Purpose: Serving Web ContentMay 02, 2025 am 12:23 AM

ApacheHTTPServer continues to efficiently serve Web content in modern Internet environments through modular design, virtual hosting functions and performance optimization. 1) Modular design allows adding functions such as URL rewriting to improve website SEO performance. 2) Virtual hosting function hosts multiple websites on one server, saving costs and simplifying management. 3) Through multi-threading and caching optimization, Apache can handle a large number of concurrent connections, improving response speed and user experience.

Apache's Role in Web Development: Pioneering TechnologyApache's Role in Web Development: Pioneering TechnologyMay 01, 2025 am 12:12 AM

Apache's role in web development includes static website hosting, dynamic content services, reverse proxying and load balancing. 1. Static website hosting: Apache has simple configuration and is suitable for hosting static websites. 2. Dynamic content service: Provide dynamic content by combining it with PHP, etc. 3. Reverse proxy and load balancing: As a reverse proxy, it distributes requests to multiple backend servers to achieve load balancing.

Is Apache Dying? Debunking the MythsIs Apache Dying? Debunking the MythsApr 30, 2025 am 12:18 AM

Apache is not in decline. 1.Apache is still a stable and reliable choice, and continues to update performance optimization and security enhancement in version 2.4. 2. It supports extensive modular expansion, is simple to configure, but is not as efficient as Nginx when it is highly concurrency. 3. In actual applications, Apache improves SEO performance through modules such as mod_rewrite. 4. Apache can be integrated with modern technologies such as Docker to improve deployment and management efficiency. 5. Apache's performance can be significantly improved by tuning configuration and using optimization modules.

Apache: Configuring and Managing a Web ServerApache: Configuring and Managing a Web ServerApr 29, 2025 am 12:18 AM

The steps to configure and manage ApacheHTTPServer include: 1. Basic configuration: Set the server name, listening port, and document root directory. 2. Advanced configuration: Set up virtual host, enable SSL encryption and URL rewriting. 3. Performance optimization: Adjust KeepAlive settings and use cache. 4. Solve FAQs: Check configuration file syntax and optimize server parameters. Through these steps, you can ensure that the Apache server runs stably and optimize its performance.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor