Deep optimization of apache working mode, ab stress test, apache directory attribute

ab pressure test Apache has its own stress testing tool ab, which is simple and easy to use. It can simulate various conditions to make a test reques...
The function of ab pressure testing tool
ab use of pressure testing tools, parameter description
Example
Key test instructions of ab tool test results
Introduction to event working mode
Introduction to the working mode of prefork
Introduction to prefork parameters
prefork optimization
Introduction to worker working mode
How the worker works
Details of worker parameters
(prefork real column)
Catalog property parameters
Configure directory properties (real column)
Put connection files in the site

ab pressure test Apache has its own stress testing tool ab, which is simple and easy to use. It can simulate various conditions to make a test request to the web server ab tool can directly launch the test request in the local 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 calculation time of the user pc, so that the performance of the web server can be judged by observing various time indexes, so as to optimize and adjust the parameters

The function of ab pressure testing tool

Stress test with ab before optimization After optimization, restart the service and use ab for stress test 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, we usually need to test several times before and after optimization, and take the average value of the test for comparison

ab use of pressure testing tools, parameter description

ab[options] website -n,-c,-t,-v

Example

#Apac/usr/local/httpd/bin/ab -n5000 -c900 www.kgc.com/index.html

Key test instructions of ab tool test results

Introduction to Apache working mode

During the test, the total number of users and the number of concurrent users should be adjusted according to the situation

Apache is the most widely used and stable open source server software as the web server. There are many working modes. When the source package installs HTTPD, you can view the httpd-mpm.cong file, which is located in the extra/conf directory At present, there are two modes: event mode preork mode worker mode How to distinguish working mode prefork: a process contains a thread worker/event: a process contains multiple processes

Introduction to event working mode

event is the latest working mode of Apache. It is very similar to worker mode. The difference is that it solves the problem that thread resources are wasted when keep alive long connection is used event working mode will fail when a module with incompatible write is encountered, and it will fall back to worker mode The event working mode requires the support of Linux system (Linux 2.6 +) for epoll to enable, and the HTTPS connection (SSL) needs to be supplemented event to establish a connection and keep it connected is like calling to say "hang up for a while" and "hang up for a while". I can set the time-out time, disconnect when it is over, and disconnect the conversation at any time.

How event works

In the event working mode, there will be some special threads to manage these keep alive threads. When there is a real request coming, pass it to the thread of the server, and allow it to be released after execution. In this way, one thread can handle several requests, and realize asynchronous non blocking. This enhances request processing in high concurrency scenarios Flexible control. In case of multiple requests, the previous process can be released and high concurrency can be handled

Details of event parameters

<ifMoudle mpm_event_module> In the startservers 3 configuration file, start three processes Minspare threads 75 minimum number of idle threads 75 MaxSpare Threads 250 maximum number of idle threads 250 Threadsperchild 25 25 threads are opened by default in each process Maxrequestworkers 400 maximum concurrent requests 400 If maxconnectionsperchild 0 is set to 0, the subprocess will never end. If it is set to a value other than 0, memory leakage caused by running PHP can be prevented

Introduction to the working mode of prefork

prefork is a multiprocessing module (MPM), which implements a process type, preplanned web server. It is suitable for a system without thread safety library and needs to avoid thread compatibility problems Each request is required to be independent of each other. If there is a problem with one request, other requests will not be affected It has a strong self-regulation ability, and only needs a few configuration instructions to adjust it can be suitable for enterprise application requirements The most important thing is to set MaxClients to a value that is large enough to handle the potential peak requests, but not too large, so as to avoid that the required memory exceeds the physical memory

prefork mode of operation

A separate control process (parent process) is responsible for generating child processes, which are used to listen to and respond to requests. Therefore, there will always be some spare or idle child processes in memory to respond to new requests, which can speed up the response speed The parent process usually runs as root to bind port 80. The child process usually runs as a low privileged User, which can be configured through the User and Group of the configuration item Users running subprocesses must have read access to the content of the website, but they must have as few access to other resources as possible to ensure the security of the system No working mode is specified during compilation and installation. The default mode is prefork, which can be viewed with httpd -l

Introduction to prefork parameters

<ifModule mpm_prefork_module> Startservers 20 maximum processes Minspareservers 10 minimum idle processes Maxspareservers 50 most idle processes Maxclients 150 how many subprocesses can be created at most to process requests Maxrequestperchild 0 the maximum number of requests processed by each process. When the number of requests reaches, the process is destroyed. If it is set to 0, the subprocess will never end

prefork optimization

It can be debugged according to the production environment to determine the appropriate parameters ##Optimization reference <IfModule mpm prefork module> ServerLimit 1000 StartServers 10 MinSpareServers 10 MaxSpareServers 30 MaxClients 1000 MaxRequestsPerChild 5000 </IfModule>

Introduction to worker working mode

worker is also a multiprocessing module (MPM) that enables network services to support mixed multithreaded processes Because threads are used to process requests, all of them can process massive requests, while the overhead of system resources is less than that of process based MPM However, multi processes are also used, and each process has multiple threads to obtain the stability of process based MPM The most important instructions to control the MPM are: ThreadsPerChild instruction to control the number of threads allowed to be established for each subprocess and MaxClients instruction to control the number of bus programs allowed to be established

How the worker works

The number of threads that each process can own 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 establish a number of ThreadsPerChild service threads and a listening thread. The listening thread listens for the access request and passes it to the server process for processing and answering Apache always maintains a spare or idle pool of server threads. Clients can get services without waiting for new threads or processes to be established The parent process is generally started as root to bind port 80; then, Apache establishes the child process and thread as a user with lower permission The User and Group directives are used to configure the running User of the Apache subprocess. The subprocess should have read permission to the content of the web page, but should limit the permission as much as possible

Details of worker parameters

parameter Explain ServerLimit Maximum number of processes, default 16 "" ThreadL imit Maximum number of threads per subprocess, default is "64" StartServers The number of subprocesses established when the server starts. The default value is "3" MaxClients Maximum number of simultaneous access requests allowed (maximum number of threads) MinSpare Threads Minimum number of idle threads, default is "75" MaxSpare Threads Set the maximum number of idle threads. The default is "250" ThreadsPerChild The number of resident execution threads established by each subprocess. The default is 25 MaxRequestsPerChild Sets the maximum number of requests that each subprocess is allowed to serve during its lifetime. Set to '0', child processes will never end

(prefork real column)

[root@localhost httpd-2.4.29]#./configure \ --with-mpm=prefork \ ##Add working modethis configuration item [root@localhost httpd-2.4.29]# vim /etc/httpd.conf //Enter / mpm to find this keyword and delete the previous comment Include conf/extra/httpd-mpm.conf ##Navigate to this line to delete the comment and enable the function [root@localhost ~]# cd /usr/local/httpd/conf/extra/ [root@localhost extra]# vim httpd-mpm.conf <IfModule mpm_prefork_module> StartServers 10 ##The number of processes created at startup is changed to 10 MinSpareServers 10 ##Idle minimum changed to 10 MaxSpareServers 20 ##Max set to 20 MaxRequestWorkers 200 ##Access set to 200 MaxConnectionsPerChild 0 </IfModule> ##After modification, press Esc to exit the insertion mode, enter: wq to 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 :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 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 one main process, and the other subprocesses become 10
Apache directory properties The permission settings of the directory use the statements < directory directory path > and < / Directory > to set the permission of the main directory or virtual directory They are a pair of container statements, which must appear in pairs. They encapsulate the specific set directory permission statements, which only work on the set directory and its subdirectories

Catalog property parameters

parameter Effect Options Set which properties to use in a specific directory AllowOverride Allowed instruction types in. htaccess files Require Set access control for directories 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, the list of files and subdirectories in the directory is returned MultiViews Multi view of content negotiation, an intelligent feature of Apache When accessing an object that does not exist in the directory ExecCGI Allow CGI script execution in this directory FollowSymLinks Allow file systems to use symbolic connections in this directory Includes Allow server side to include features IncludesNoExec Allow the server side to include functions, but prohibit the execution of CGI scripts All Contains All properties except MultiViews. If there is no Options statement, the default is All

Configure directory properties (real column)

[root@localhost bin]# vim /etc/httpd.conf //Enter / htdocs to find this keyword and find the following fields, two of which are supported: DocumentRoot "/usr/local/httpd/htdocs" <Directory "/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: in the form of list //2. Follow symlinks and support linked files # # 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 //Black-and-white list </Directory> #We can turn off the firewall and use the host's browser for verification [root@localhost bin]# systemctl stop firewalld.service [root@localhost bin]# setenforce 0 [root@localhost bin]# cd /usr/local/httpd/htdocs/ [root@localhost htdocs]# ls index.html [root@localhost htdocs]# cat index.html <html><body><h1>It works!</h1></body></html> [root@localhost htdocs]# ls index.html [root@localhost htdocs]# mv index.html a.html [root@localhost htdocs]# ls a.html [root@localhost htdocs]# touch b.html c.html d.html [root@localhost htdocs]# ls a.html b.html c.html d.html //At this time, it will be displayed in the form of file list. From another point of view, we can use this point to provide file download resources. At this time, we do not need home page identification

Put connection files in the site

[root@localhost htdocs]# ln -s /usr/share/man/ ./ //Put the man manual in this folder to see if he can recognize the linked file [root@localhost htdocs]# ls a.html b.html c.html d.html man

5 November 2019, 12:52 | Views: 2796

Add new comment

For adding a comment, please log in
or create account

0 comments