In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Working principle and configuration of worker
Relative to prefork,worker, it is a new MPM in version 2.0 that supports a mixed model of multi-threading and multi-process. Because threads are used to process, it is possible to handle a relatively large number of requests, and the overhead of system resources is less than that of process-based servers. However, worker also uses multiple processes, and each process generates multiple threads to achieve process server-based stability. The way MPM works will be the trend of Apache 2.0.
After configure-with-mpm=worker, compile make and install make install. In the default generated
The following configuration segments are available in httpd.conf:
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
The principle of worker is that the main control process generates a "StartServers" child process, each of which contains a fixed number of ThreadsPerChild threads, and each thread processes the request independently. Similarly, in order not to generate threads when the request arrives, MinSpareThreads and MaxSpareThreads set the minimum and maximum number of idle threads, while MaxClients sets the total number of threads in all child processes. If the total number of threads in the existing child process does not meet the load, the control process will derive a 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, which is not enough if the load is heavy. The ThreadLimit instruction is used explicitly, and its maximum default value is 20000. The above two values are located on the following two lines in the source tree server/mpm/worker/worker.c:
# define DEFAULT_THREAD_LIMIT 64
# define MAX_THREAD_LIMIT 20000
These two lines correspond to the number of limits for ThreadsPerChild and ThreadLimit. It's best to change 64 to the desired value before configure. Be careful not to set these two values too high to exceed the processing capacity of the system, which makes the system unstable because the Apache does not start.
The total number of requests that can be processed simultaneously in Worker mode is determined by the total number of child processes multiplied by the ThreadsPerChild value, which should be greater than or equal to MaxClients. If the load is so heavy that the number of existing child processes cannot be satisfied, the control process will derive new child processes. By default, the maximum total number of child processes is 16, and you also need to explicitly declare ServerLimit when enlarged (the maximum is 20000). These two values are located on the following two lines in the source tree server/mpm/worker/worker.c:
# define DEFAULT_SERVER_LIMIT 16
# define MAX_SERVER_LIMIT 20000
It is important to note that if ServerLimit is explicitly declared, its value multiplied by ThreadsPerChild must be greater than or equal to MaxClients, and MaxClients must be an integral multiple of ThreadsPerChild, otherwise Apache will automatically adjust to a corresponding value (which may be an unexpected value). The following are common worker configuration segments:
StartServers 3
MaxClients 2000
ServerLimit 25
MinSpareThreads 50
MaxSpareThreads 200
ThreadLimit 200
ThreadsPerChild 100
MaxRequestsPerChild 0
Through the above description, we can understand the working principle of prefork and worker, two important MPM in Apache 2.0, and configure the core parameters related to Apache according to the actual situation to achieve maximum performance and stability.
PS: I am afraid there is a mistake in the following personal understanding.
StartServers 3 / / apache has started to create 3 httpd processes immediately (can be seen by ps aux)
MaxClients 2000 / / accepts a maximum of 2000 requests at a time (actually 2000 threads)
ServerLimit 25 / / apache can start up to 25 processes.
MinSpareThreads 50 / / apache must have at least 50 idle threads to wait for the next request. If dissatisfied, the thread will be created by the process.
MaxSpareThreads 200 / / apache can have up to 200 threads. If there are more than 200 threads, then kill the extra threads.
ThreadLimit 200 / / A process can only create a maximum of 200 threads
ThreadsPerChild 100 / / set a process to create a fixed number of threads
MaxRequestsPerChild 10000 / / is set to be killed when a process has received a total of 10000 requests. To free up memory.
As we can see from the above configuration, when apache starts, three httpd processes are started, and each process generates another 100 threads, but exceeds the maximum limit, so 100 threads are killed, that is, one process. When there are 300 requests at some point, there are currently only 200 threads, so the parent process creates 2 more child processes. After the request is processed, the idle is released to less than 200.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.