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/01 Report--
Editor to share with you how to achieve ab stress testing, working mode and directory attribute optimization in Apache. I hope you will get something after reading this article. Let's discuss it together.
Ab stress testing tool
Apache has its own stress testing tool ab, which is easy to use and can simulate various conditions to initiate test requests to the Web server. The ab tool can initiate test requests directly local to 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, so that the performance of the Web server can be judged by observing various time indicators in order to optimize the parameters.
In the process of performance tuning and optimization, the ab pressure measurement tool can be used to test the optimization effect:
1. Use ab for stress testing before optimization
two。 After optimization, restart the service, and then use ab for stress testing
3. Compare the results of the two tests to see whether the optimization effect is obvious.
4. In order to evaluate the performance of web service more objectively, many tests should be carried out before and after optimization, and the average value of the test results is compared.
Use of ab tool
Command format
Ab [options] website URL
Related parameters
-number of requests sent by n-c concurrency-maximum number of seconds for t tests-v sets the level of detail of the display information
Example
/ usr/local/httpd/bin/ab-n5000-c900 www.kgc.com/index.html// should adjust the total and concurrent users according to the situation during the test. The key parameters describe the header information of the Server Softwarehttp response data. The host name in the url of the Server Hostname request, the host name of the Server Portweb server software, the listening port of the Document Path request, the absolute path of the url root, the body length of the Document Lengthhttp response data, Concurrency Level and Number of users sent Time taken for tests the total time taken for all these requests to be processed Complete requests represents the total number of requests Failed requests failed requests total response data length of Total transferred requests and throughput of the Requests per second server Number of requests processed per second Time per request average request wait time Time per request average 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 model overview
Apache is the most widely used and most stable open source server software for web servers today. It works in many ways, and when the source package installs httpd, you can view the httpd-mpm.conf file, which is located in the extra/conf directory.
There are two main mode name characteristics event mode / worker mode a process contains multiple threads prefork mode a process contains only one thread event working mode
(1) event is the latest working mode of Apache, which is very similar to worker mode, except that it solves the problem that thread resources are wasted when keep-alive long connections. Event working mode will fail when it encounters some incompatible modules and will fall back to worker mode. The event working mode requires epoll support from the Linux system (Linux 2.6 +) to enable it. What needs to be added is the HTTPS connection (SSL)
(2) in the event working mode, there are specialized threads to manage these keep-alive types of threads. When a real request comes, the thread that passes the request to the server finishes execution and allows it to be released. In this way, a thread can handle several requests, achieving asynchronous non-blocking. This enhances request processing in high concurrency scenarios.
Event parameter
In the httpd-mpm.conf configuration file, the following is the definition of the event module
The parameter StartServers 3MinSpareThreads 75MaxSpareThreads 250ThreadsPerChild 25MaxRequestWorkers 400MaxConnectionsPerChild 0 indicates the initial number of processes when the StartServers service is started, the minimum number of free child processes in the default 3MinSpareThreads, the maximum number of free child processes in the default 75MaxSpareThreads, the number of threads generated by each child process in the default 250ThreadsPerChild, and the maximum number of requests accessed by the client at the same time limited by default. By default, 400MaxConnectionsPerChild allows the maximum number of requests per child process during its life cycle. If the total number of requests has reached this value, the child process will end, and 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
Optimization suggestion: 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 Operation Mode
(1) prefork is a multiprocessing module (MPM), which implements a process and pre-derived web server, which is suitable for systems without thread safety library and need to avoid thread compatibility problems. It has good characteristics when each request is required to be independent of each other, and if there is a problem with one request, it will not affect other requests. It has a strong ability of self-regulation, and only a few configuration instructions are needed to adapt to the requirements of enterprise applications. The most important thing is to set MaxClients to a value large enough to handle potential request peaks, but not too large to avoid requiring more memory than physical memory
(2) A separate control process (parent process) is responsible for generating child processes, which are used to listen to requests and respond, so there will be some spare (spare) or idle child processes in memory to respond to new requests, which can speed up the response. The parent process usually runs as root to bind port 80, and the child process usually runs as a low-privileged user, which can be configured through the User and Group of the configuration item. The user running the child process must have read access to the content of the site, but must have as few permissions as possible to other resources to ensure system security. No working mode is specified when compiling and installing. Prefork mode is used by default, which can be viewed with httpd-l.
Prefork parameter
In the httpd-mpm.conf configuration file, the following is the definition of the prefork module
The parameter StartServers 20 MinSpareServers 10 MaxSpareServers 50 MaxClients 150 MaxRequestsPerChild 0 indicates the maximum number of ServerLimit processes created when StartServers starts. MinSpareServers minimum idle process MaxSpareServers maximum idle process MaxClients maximum number of child processes to handle requests MaxRequestsPerChild maximum number of requests each process is destroyed, if set to 0, the child process will never end
Optimization suggestion: 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 Operation
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 a listener thread, which listens for access requests and passes them to the service thread for processing and response. Apache always maintains a spare or idle pool of service threads, and the client can be serviced without waiting for a new thread or process to be established. The parent process is typically started as root to bind port 80; Apache then sets up child processes and threads with lower-privileged users. The User and Group directives are used to configure the running user of the Apache child process. Child processes should have read access to the content of the page, but should limit permissions as much as possible.
The parameter worker specifies the maximum number of ServerLimit processes. The default value is the maximum number of threads per child process of "16" ThreadLimit, the default value is the number of child processes established when the "64" StartServers server starts, the default value is the maximum number of access requests allowed by "3" MaxClients (maximum number of threads) MinSpare Threads minimum number of idle threads, and the default value is "75" MaxSpareThreads sets 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 Apache directory property
The permission settings of the directory use and
< /Directory >This sets permissions for statements in either the primary directory or the virtual directory. They are a pair of container statements that must appear in pairs, encapsulating specific set directory permission statements that only work on the set directory and its subdirectories.
Function of directory attribute parameter parameter
Options sets which features are used in a specific directory
AllowOverride allows instruction types that exist in htaccess files
Require sets the access control of the directory
Indexes returns a list of files and subdirectories in the directory when the user accesses the directory but does not specify which file to access, and there is no default web page in the directory
The multi-focus graph of MultiViews content negotiation is an intelligent feature of Apache. When accessing objects that do not exist in the directory
ExecCGI allows CGI scripts to be executed in this directory
FollowSymLinks allows file systems to use symbolic connections in this directory
Includes allows the server side to include functions
IncludesNoExec allows functions to be included on the server side, but forbids execution of CG scripts. All contains all the features except MultiViews. If there is no Options statement, the default is All.
An example demonstrates the prefork working mode of Apache working mode 1. Shared resource package And compile and install the Apache service [root@localhost] # smbclient-L / / 192.168.10.37Enter SAMBA\ root's password: Sharename Type Comment-LNMP Disk [root@localhost ~] # mount.cifs / / 192.168.10.37/LNMP / abcPassword for root@//192.168.10.37 / LAMP: [root@localhost ~] # cd / abc [root@localhost abc] # ls apr-1.6.2.tar.gz game.jpgapr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2awstats-7.6.tar.gz install_lamp.shcronolog-1.6.2-14.el7.x86_64.rpm mysql-5.6.26.tar.gzDiscuz _ X2.5_SC_UTF8.zip nginx-1.12.0.tar.gzerror.png php-5.6.11.tar.bz2 [root@localhost abc] # tar jxvf httpd-2.4.29.tar.bz2-C / opt [root@localhost abc] # tar zxvf apr-1.6.2.tar.gz-C / opt [root@localhost abc] # tar zxvf apr-util-1.6.0.tar. Gz-C / opt [root@localhost abc] # ls / optapr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh [root@localhost opt] # mv apr-1.6.2/ httpd-2.4.29/srclib/apr [root@localhost opt] # mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util [root@localhost opt] # cd httpd-2.4.29/ [root@localhost httpd-2. 4.29] # yum install-y gcc gcc-c++ pcre-devel zlib-devel expat-devel [root@localhost httpd-2.4.29] #. / configure\ >-- prefix=/usr/local/httpd\ >-- enable-deflate\ >-- with-mpm=prefork\ >-- enable-expires\ >-- enable-so\ >-- enable-rewrite\ >-- enable-charset-lite\ >-- enable-cgi [root@localhost httpd-2.4.29] # make & & make install [ Root@localhost httpd-2.4.29] # ln-s / usr/local/httpd/conf/httpd.conf / etc/httpd.conf II, Edit the relevant configuration files for the Apache service
1. Modify the httpd.conf main configuration file
[root@localhost httpd-2.4.29] # vim / etc/httpd.conf458 Include conf/extra/httpd-mpm.conf// retrieves the mpm module on line 458, delete the comment # to enable function 51 Listen 192.168.235.137 etc/httpd.conf458 Include conf/extra/httpd-mpm.conf// 80 / / retrieve IPv4 snooping on line 51 Uncomment and modify the address of the local Linux server 52 # Listen 80max / comment line 52 IPv6 snooping line 193 ServerName www.accp.com:80// retrieves line 193, uncomment and edit the domain name, here for reference only
two。 Check the httpd-mpm.conf configuration file to confirm the default parameters of prefork operating mode
[root@localhost httpd-2.4.29] # cd / usr/local/httpd/conf/extra/ enter the extension directory [root@localhost extra] # ls / / visible httpd-mpm.conf configuration file httpd-autoindex.conf httpd-mpm.confhttpd-dav.conf httpd-multilang-errordoc.confhttpd-default.conf httpd-ssl.confhttpd-info.conf httpd-userdir.confhttpd-languages.conf httpd-vhosts.confhttpd-manual.conf Proxy-html.conf [root@localhost extra] # vim httpd-mpm.conf 28 29 StartServers 5 / / 5 processes at startup 30 MinSpareServers 5 / / minimum idle processes 5 31 MaxSpareServers 10 / / maximum idle processes 10 32 MaxRequestWorkers 250 / / maximum concurrent processes 250 33 MaxConnectionsPerChild 0 / / the maximum number of connections is limited to 0.34 / / View the parameter information of prefork working mode [root@localhost bin] # cd / usr/local/httpd/bin// and switch to the / bin directory of Apache service [root@localhost bin] # lsab checkgid htcacheclean httxt2dbmapachectl dbmmanage htdbm logresolveapr-1-config envvars htdigest rotatelogsapu-1-config envvars-std htpasswdapxs fcgistarter httpd [root@localhost bin] #. / apachectl start// uses the built-in script of the Apache service to start the service [root@localhost bin] # netstat-ntap | grep 80 / / check whether port 80 of the service is enabled or not. Tcp 0 0192.168.235.137 root@localhost bin 80 0.0.0.0 root@localhost bin * LISTEN 35722/httpd [root@localhost bin] # lsof-I: 80 / / View the process information of port 80 of the system Where user is root is the main process The remaining five are all child processes COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 35722 root 3u IPv4 43621 0t0 TCP 192.168.235.137:http (LISTEN) httpd 35723 daemon 3u IPv4 43621 0t0 TCP 192.168.235.137:http (LISTEN) httpd 35724 daemon 3u IPv4 43621 0t0 TCP 192.168.235.137:http (LISTEN) httpd 35725 daemon 3u IPv4 43621 0t0 TCP 192.168.235.137:http (LISTEN) ) httpd 35726 daemon 3u IPv4 43621 0t0 TCP 192.168.235.137:http (LISTEN) httpd 35727 daemon 3u IPv4 43621 0t0 TCP 192.168.235.137:http (LISTEN)
3. Edit the httpd-mpm.conf configuration file and modify the prefork working mode parameters
[root@localhost bin] # vim / usr/local/httpd/conf/extra/httpd-mpm.conf 28 29 StartServers 10 / / change the number of processes at startup to 10 30 MinSpareServers 10 / / the minimum number of idle processes to 10 31 MaxSpareServers 50 / / the maximum number of idle processes to 50 32 MaxRequestWorkers 150 / / the maximum number of concurrent processes is 15033 MaxConnectionsPerChild 0 34
4. Restart the service
[root@localhost bin] #. / apachectl stop [root@localhost bin] #. / apachectl start
5. View the process information of prefork working mode
/ / use the. / httpd-l command to view the working mode, which is currently the prefork working mode [root@localhost bin] #. / httpd-lCompiled in modules: core.c mod_so.c http_core.c prefork.c / / View process information Five more child processes than the previous default mode [root@localhost bin] # lsof-I: 80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 36071 root 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36072 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36073 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36074 daemon 3U IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36075 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36076 daemon 3U IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36077 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36078 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36079 daemon 3U IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36080 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) httpd 36081 daemon 3u IPv4 51494 0t0 TCP 192.168.235.137:http (LISTEN) finished reading this article I believe you have a certain understanding of "how to achieve ab stress testing, working mode and directory attribute optimization in Apache". If you want to know more about it, you are welcome to follow the industry information channel. 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.
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.