Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

In-depth optimization of Apache web pages-- ab stress testing, working mode

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Ab stress testing is a tool Apache has its own stress testing tool ab, which is easy to use and can simulate various conditions to initiate a test on the web server. The ab tool can directly initiate a test request locally on the web server, which is very important to understand the processing performance of the server, because it does not include the network transmission time of the data and the local computing time of the user pc. Thus, the performance of the web server can be judged by observing various time indicators, so as to optimize the parameters. In the process of performance adjustment and optimization, the ab stress test tool can be used to test and optimize the optimization effect before using ab for stress test optimization, restart the service, and then use ab for stress test to compare the results of the two tests. To see whether the optimization effect is obvious in order to evaluate the performance of web services more objectively, it is generally necessary to carry out multiple tests before and after optimization, and take the average of the tests to compare the ab tool using the command format: aboptions] website URL parameters description:-nmai Murray -v example: / usr/local/httpd/bin/ab-n5000-c900 www.kgc.com/index.html to adjust the number of total and concurrent users according to the situation during the test. Key parameters description parameters describe the header information of   Server Software   http response data, host name in url request Server Portweb server software, listening port of Document Path request, absolute url root of Document Path request. For the body length of path Document Lengthhttp response data Concurrency Level concurrent number of users Time taken for tests the total time it takes for all these requests to be processed Complete requests represents the total number of requests Failed requests failed requests total Total transferred request response data length sum of Requests per second server throughput Number of requests processed per second Time per request average request wait time Time per request average of actual elapsed time per request Percentage of the requests served within a certain time (ms) description of the distribution of processing time per request Apache working mode introduction to Apache as the most widely used and most stable open source server software used by today's web server, there are many working modes. The source package installs httpd to check the httpd-mpm-conf file at all times. The file is located in the extra/conf directory and currently has two main modes:

Event mode

Prefork mode

Worker mode can be viewed using. / httpd-l to view apache current working mode event working mode introduces event is the latest working mode of Apache, it is very similar to worker mode, except that it solves the problem that thread resources are wasted during keep-alive long connections, event working mode will fail when it encounters some incompatible modules, and will fall back to worker mode event working mode requires Linux system (Linux 2.6 +) to support epoll. To enable it. What needs to be added is the HTTPS connection (SSL) event working mode in the event working mode, there will be some special threads used to manage these keep-alive type threads when there is a real request, pass the request to the server thread, and allow it to release after the execution is completed, so that a thread can handle several requests, realizing asynchronous non-blocking. This enhances the event parameter explanation for request processing in high concurrency scenarios # # in the http-mpm.conf configuration file, the following is the definition of the event module StartServers 3MinSpareThreads 75MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 parameter description parameter describes the initial number of processes at the start of the StartServers service, the default minimum number of free child processes in 3MinSpareThreads, and the maximum number of free child processes in 75MaxSpareThreads by default By default, the number of threads generated by each child process in 250ThreadsPerChild. By default, 25MaxRequestWorkers limits the maximum number of access requests for clients at a time. By default, 400MaxConnectionsPerChild allows the number of requests per child process in its life cycle. If the total number of requests has reached this value, the child process will end. If set to 0, the child process will never end. Set this value to a non-zero value to prevent memory leaks caused by running PHP event optimization recommendations

Can be debugged according to the production environment to determine the appropriate parameters

# # Optimization reference ServerLimit 1000 StartServers 20 MinSpareThreads 25 MaxSpareThreads 1200 ThreadsPerChild 50 MaxRequestWorkers 2000 MaxC onnectionsPerChild 1000prefork working mode prefork is a multiprocessing module (MPM), which implements a process-based, pre-derived web server, which is suitable for systems without thread-safe libraries and requiring thread compatibility problems to be avoided when each request is independent of each other. If a problem with one request does not affect the strong self-tuning ability of other requests, only good configuration instructions are needed to adapt to enterprise application requirements. The most important thing is to set MaxClients to a large enough value to handle the potential request peak, but not too large, so as to prevent the memory required from exceeding the physical memory. A separate control process (parent process) is responsible for generating child processes. Child processes are used to listen to requests and respond, so there will always be some spare (spare) or idle child processes in memory to respond to new requests, which can speed up the response. The parent process is usually carried out as root to bind port 80, and the child process is usually run as a low-privileged user. The user who runs the child process through the User and Group of the configuration item must have read access to the content of the website. However, you must have as few permissions to other resources as possible to ensure that no working mode is specified during compilation and installation. Prefork mode is used by default. You can use httpd- l to view the prefork parameter explanation # # in the httpd-mpm.conf configuration file The following is the definition of the prefork module: StartServers 20 MinSpareServers 10 MaxSpareServers 50 MaxClients 150 MaxRequestsPerChild 0 parameter indicates the maximum number of processes created when ServerLimit is started MinSpareServers minimum idle processes MaxSpareServers maximum number of idle processes MaxClients maximum number of child processes to be created to process requests MaxRequestsPerChild the maximum number of requests each process handles, the process is destroyed, if set to 0 Child processes never end prefork optimization recommendations

Can be debugged according to the production environment to determine the appropriate parameters

# # Optimization reference ServerLimit 1000 StartServers 10 MinSpareServers 10 MaxSpareServers 30 MaxClients 1000 MaxRequestsPerChild 5000worker working mode introduction worker is also a multithreading module (MPM), which enables network services to support mixed multithreaded processes. Due to the use of threads to process requests, all can handle massive requests, while the overhead of system resources is less than that of process-based MPM, but it also uses multiple processes, each with multiple threads. The most important instructions to control the MPM in order to obtain the stability of the process-based MPM are the ThreadsPerChild instruction to control the number of threads allowed to be established per child process and the MaxClients instruction worker to control the number of buses allowed to be established. The number of threads that each process can have is fixed, and the server will increase or decrease the number of processes according to the load. A separate control process (parent process) is responsible for the establishment of child processes. Each child process can set up a number of ThreadsPerChild service threads and one listening thread. The listening thread listens to the access request and passes it to the server process to process and reply. Apache always maintains a spare or idle server thread pool. The client does not need to wait for the establishment of a new thread or process to get the service. The parent process is usually started as root to bind port 80. Subsequently, Apache sets up child processes and threads User and Group instructions with lower-privileged users to configure the running user of the Apache child process. Child processes should have read access to web pages, but should limit permissions as far as possible. The worker parameter describes the maximum number of ServerLimit processes, the default value is 16 "" ThreadL imit maximum number of threads per child process, the default value is the number of child processes established when the "64" StartServers server starts, and the default value is the maximum number of access requests allowed by "3" MaxClients at the same time (maximum number of threads) MinSpare Threads minimum idle threads The default value is "75" MaxSpare Threads to set the maximum number of idle threads. The default value is the number of resident threads of execution established by each child process of the "250th" ThreadsPerChild. The default value is 25MaxRequestsPerChild to set the maximum number of requests that each child process is allowed to serve during its lifetime. Set to "0" and the child process will never end the instance (prefork as an example) [root@localhost httpd-2.4.29]. / configure\-- with-mpm=prefork\ # add working mode this configuration item [root@localhost httpd-2.4.29] # vim / etc/httpd.conf input / mpm look for this keyword, locate the previous # comment delete Include conf/extra/httpd-mpm.conf # # to this line to delete the comment Enable the feature [root@localhost ~] # cd / usr/local/httpd/conf/extra/ [root@localhost extra] # vim httpd-mpm.conf StartServers 10 # # the number of processes created when starting is changed to 10 MinSpareServers 10 # # the minimum idle is changed to 10 MaxSpareServers 20 # # the maximum is set to 20 MaxRequestWorkers 200 # # access Set the quantity to 200 MaxConnectionsPerChild 0mm # after modification, press Esc to exit the insert mode. Enter: wq save and exit [root@localhost extra] # cd.. / bin/ [root@localhost bin] #. / apachectl stop [root@localhost bin] #. / apachectl start## turn off the service again [root@localhost bin] # lsof-I: 80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 58933 root 3u IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58937 daemon 3u IPv4 88357 0t0 TCP localhost.localdomain: Http (LISTEN) httpd 58938 daemon 3U IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58939 daemon 3U IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58940 daemon 3U IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58941 daemon 3U IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58942 daemon 3u IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58943 daemon 3u IPv4 88357 0t0 TCP localhost.localdomain: Http (LISTEN) httpd 58944 daemon 3U IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58945 daemon 3u IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) httpd 58946 daemon 3u IPv4 88357 0t0 TCP localhost.localdomain:http (LISTEN) # # remove a main process The other child processes change to 10 Apache directory attribute directory permission settings and this pair of statements set permissions for the home directory or virtual directory. They are a pair of container statements that must appear in pairs, encapsulating specific set directory permission statements between them. These statements only work on the set directory and its subdirectories, directory attribute parameters, Options sets which properties to use in a particular directory AllowOverride allows instruction types to exist in .htaccess files Require sets the access control of the directory Indexes when the user accesses the directory, but does not specify which file to access, and there is no default web page in the directory, returns the multi-emphasis graph negotiated between the files in the directory and the subdirectory list MultiViews content An intelligent feature of Apache. ExecCGI allows execution of CGI scripts in that directory when accessing objects that do not exist in that directory FollowSymLinks allows file systems to use symbolic connections Includes allows server-side inclusion of functions IncludesNoExec allows server-side inclusion of functions, but forbids execution of CGI scripts All contains all features except MultiViews, if there is no Options statement Default is All instance (modify the configuration file to open the directory attribute) [root@localhost bin] # vim / etc/httpd.conf// input / htdocs look for this keyword and find the following fields Two functions are supported: DocumentRoot "/ usr/local/httpd/htdocs" # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named * explicitly*-"Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks / / 1.Index: a file that presents / / 2.FollowSymLinks as a list and supports linking # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted / / blacklist and whitelist # We can turn off the firewall first Use the host browser to verify [root@localhost bin] # systemctl stop firewalld.service [root@localhost bin] # setenforce 0 [root@localhost bin] # cd / usr/local/httpd/htdocs/ [root@localhost htdocs] # lsindex.html [root@localhost htdocs] # cat index.html It works! [root@localhost htdocs] # lsindex.html [root@localhost htdocs] # mv index.html a.html [root@localhost htdocs] # lsa.html [root@localhost htdocs] # touch b.html C.html d.html [root@localhost htdocs] # lsa.html b.html c.html d.html// will now be presented as a list of files From another point of view, we can use this to provide file download resources, and there is no need for home page identification.

Put the link file into the site [root@localhost htdocs] # ln-s / usr/share/man/. / / put the man manual into this folder and see if he can recognize the link file [root@localhost htdocs] # lsa.html b.html c.html d.html man

Thank you for reading!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report