In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The hardware environment in which Apache runs is the factor that has the greatest impact on performance.
Among the various hardware indicators, the memory has the greatest impact on performance, followed by the speed of the hard disk.
The working mode of ● Apache
1. Prefork mode (a non-threaded one)
⑴, main working mode: when the Apache server is started, the mpm_prefork module will create multiple sub-processes in advance (default is 5), each child process has only one thread. After receiving the request from the client, the mpm_prefork module will transfer the request to the child process, and each child 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 child processes, the mpm_prefork module creates new child processes to handle additional requests. Apache always tries to keep some spare or idle subprocesses to meet upcoming requests so that client requests do not have to wait for subprocesses to be generated after they are received.
⑵ prefork is more efficient than worker, but memory usage is mostly not good at dealing with high concurrency scenarios
The important parameters that affect the performance of ⑶ Apache in prefork mode are described:
# prefork MPM
The default number of child processes started when StartServers 5 # Apache starts
MinSpareServers 5 # minimum number of idle child processes
MaxSpareServers 10 # maximum number of idle child processes
MaxRequestWorkers 250 # MaxRequestWorkers sets the maximum number of requests allowed to access at the same time, and any request that exceeds the MaxRequestWorkers limit will enter the waiting queue
MaxConnectionsPerChild 500 # sets the number of requests that each child process can handle. Each process is automatically destroyed after processing the "MaxConnectionsPerChild" request. 0 means infinity, that is, child processes are never destroyed. Set to 1 to prevent unexpected memory leaks. A setting of 2 means that the number of child processes is automatically reduced when the server load drops. This value can be adjusted according to the load of the server
★ Note:
① MaxRequestWorkers is the most important of these instructions, which sets the request that Apache can process at the same time, and is the parameter that has the greatest impact on the performance of Apache. If the total number of requests has reached this value (confirmed by ps-ef | grep http | wc-l), then subsequent requests will be queued until a request has been processed. This is the main reason why there are a lot of system resources left and http access is slow. Although in theory, the higher the value, the more requests can be processed, it is recommended that you set the initial value to the maximum physical memory / 2 in MB, and then dynamically adjust it according to the load.
After the initial establishment of the "StartServers" child process, the ② prefork control process creates one process to meet the needs of the MinSpareServers setting, waits for one second, continues to create two, and then waits for one second to continue to create four. In this way, the number of processes created can be increased exponentially to a maximum of 32 per second until the value set by MinSpareServers is met. This mode eliminates the need to generate new processes when requests come, thus reducing system overhead to increase performance. MaxSpareServers sets the maximum number of idle processes. If the number of idle processes is greater than this value, Apache will kill some redundant processes. Do not set this value too high, but if the value is lower than MinSpareServers, Apache will automatically adjust it to MinSpareServers+1. If the site is heavily loaded, consider increasing MinSpareServers and MaxSpareServers at the same time.
The difference between ③ ServerLimit and MaxClients (MaxRequestWorkers): in the Apache era, the only parameter to control the maximum number of processes is MaxClients, and this parameter is written to a maximum of 256. it is invalid to try to set it to more than 256. this is because the server hardware of the Apache1 era is limited. However, in the Apache2 era, due to the upgrade of server hardware, the hardware is no longer limited, so ServerLimit this parameter to control the maximum number of processes, the ServerLimit value > = MaxClient value is valid. ServerLimit should be placed before MaxClients, and the value should not be less than Maxclients.
④ view modules loaded by Apache: apachectl-t-D DUMP_MODULES or apachectl-M or apachectl-l
View the working mode of Apache: httpd-v or httpd-l
⑤ modifies prefork parameters and starts prefork mode
Vi / usr/local/http-2.4.23/conf/extra/httpd-mpm.conf
Vi / usr/local/http-2.4.23/conf/httpd.conf add two lines: LoadModule mpm_prefork_module/mod_mpm_prefork.so and Include conf/extra/httpd-mpm.conf
Restart the httpd service
2. Worker mode (multi-thread and multi-process)
Comparison between ⑴ and prefork: prefork is slightly faster than worker, but it also requires slightly more CPU and memory resources than worker.
Description of important parameters that affect the performance of ⑵ Apache in worker mode
# worker MPM
The default number of child processes started when StartServers 3 # Apache starts
MinSpareThreads 75 # minimum number of idle worker processes
MaxSpareThreads 250 # maximum number of idle worker threads
ThreadPerChild 25 # number of threads per child process
MaxRequestWorkers 400 # MaxRequestWorkers sets the maximum number of requests allowed to access at the same time, and any request that exceeds the MaxRequestWorkers limit will enter the waiting queue
MaxConnectionsPerChild 0 # sets the number of requests that each child process can handle. Each process is automatically destroyed after processing the "MaxConnectionsPerChild" request. 0 means infinity, that is, child processes are never destroyed.
★ Note:
① Worker generates "StartServers" child processes from the main control process. Each child process 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 MaxRequestWorkers sets the maximum total number of clients connected at the same time, if the total number of threads in the existing child process can not meet the load, the control process will derive new child processes. 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 of ThreadsPerChild is 64. If the load is heavy, 64-bit is not enough. To use the ThreadLimit instruction, its maximum default value is 20000.
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 MaxRequestWorkers. 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 the declaration ServerLimit also needs to be displayed when enlarged. It is important to note that if ServerLimit is declared, then its value multiplied by ThreadsPerChild must be greater than or equal to MaxRequestWorkers, and MaxRequestWorkers must be an integral multiple of ThreadsPerChild, otherwise Apache will automatically adjust to a corresponding value.
The difference between a ④ process and a thread (a thread is an execution unit within a process and a schedulable entity within a process)
Address space: an execution unit within a process; the process has at least one thread; they share the process's address space; and the process has its own independent address space
B, resource ownership: a process is a unit of resource allocation and ownership, and threads within the same process share the resources of the process.
C. Threads are the basic unit of processor scheduling, but processes are not
D, both can be executed concurrently: processes and threads are the basic units of program running experienced by the operating system, and the system uses this basic unit to realize the concurrency of the application.
E. to put it simply, a program has at least one process and a process has at least one thread
The division scale of threads is smaller than that of processes, which makes multithreaded programs have high concurrency.
The process has an independent memory unit during execution, and multiple threads share memory, which greatly improves the running efficiency of the program.
3. Event mode
This is the latest working mode of Apache, a variation of worker mode, which separates the service process from the connection. The difference of worker mode is that it solves the problem that thread resources are wasted during keep-alive persistent connections. In event working mode, there are some special threads to manage these keep-alive type threads and pass the request to the server thread when a real request comes. When the execution is finished, it is allowed to be released. This enhances request processing in high concurrency scenarios. Event mode does not support https access very well.
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.