温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Apache服务ab压力测试

发布时间:2020-07-21 18:25:26 来源:网络 阅读:465 作者:wx5d2c2d660c282 栏目:系统运维

将ab压力测试之前,先讲解一下相关概念:

吞吐率(Requests per second)

服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。

计算公式:

总请求数 / 处理完成这些请求数所花费的时间,即
Request per second = Complete requests / Time taken for tests

并发连接数(The number of concurrent connections)

某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。

并发用户数(The number of concurrent users,Concurrency Level)

要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。

用户平均请求等待时间(Time per request)

计算公式:

处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即
Time per request = Time taken for tests /( Complete requests / Concurrency Level)

服务器平均请求等待时间(Time per request: across all concurrent requests)

计算公式:

处理完成所有请求数所花费的时间 / 总请求数,即
Time taken for / testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也=用户平均请求等待时间/并发用户数,即
Time per request / Concurrency Level

ab压力测试工具

  • Apache自带压力测试工具ab,简单易用,且可以模拟各种条件对Web服务器发起测试请求;

  • ab工具可以直接在Web服务器本地发起测试请求,这对于需要了解服务器的处理性能至关重要,因为它不包括数据的网络传输时间以及用户PC本地的计算时间,从而可以通过观测各种时间指标判断Web服务器的性能,以便进行参数的优化调整。

  • 在进行性能调整优化过程中,可用ab压力测试工具进行优化效果的测试

使用ab压力测试工具优化过程

  • 优化前先使用ab工具进行压力测试;

  • 优化后,重启服务,再使用ab进行压力测试;

  • 对比两次测试的结果,看优化效果是否明显;

  • 为了能更客观的评价web服务的性能,一般优化前后都要进行多次测试,取测试结果的平均值进行对比。

ab工具的使用

命令格式:

ab [options] 网站网址

常用参数:

-n:总共的请求执行数
-c:并发数
-t:执行测试的总时间,单位是秒
-v:打印多少故障排除信息
-V:显示版本号并退出

手工编译安装Apache服务:

(1)安装DNS服务的软件包bind。

[root@localhost ~]# yum install bind -y
......//省略安装过程
[root@localhost ~]#

(2)对DNS服务的主配置文件进行修改。

[root@localhost ~]# vim /etc/named.conf

options {
        listen-on port 53 { any; };                   //127.0.0.1改为any
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { any; };               //localhost改为any

(3)对DNS服务的区域配置文件进行修改。

[root@localhost ~]# vim /etc/named.rfc1912.zones

zone "abc.com" IN {                                 //添加一个域名信息
        type master;
        file "abc.com.zone";
        allow-update { none; };
};

(4)查看一下IP地址。

[root@localhost named]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.52.133  netmask 255.255.255.0  broadcast 192.168.52.255
        inet6 fe80::3e1d:31ba:f66a:6f80  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:1c:3f  txqueuelen 1000  (Ethernet)
        RX packets 14532  bytes 20210558 (19.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6054  bytes 399142 (389.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

(5)保留权限复制一份DNS服务的区域数据配置文件,进行修改。

[root@localhost ~]# cd /var/named/          //切换目录
[root@localhost named]# ls                        //查看
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[root@localhost named]# cp -p named.localhost abc.com.zone    //复制
[root@localhost named]# vim abc.com.zone 

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
www IN  A       192.168.52.133             //添加IPv4的域名解析

(6)开启named服务。

[root@localhost named]# systemctl start named      //开启服务
[root@localhost named]# systemctl stop firewalld.service      //关闭防火墙
[root@localhost named]# setenforce 0         //关闭增强性安全功能
[root@localhost named]# 

(7)在宿主机将我们所需的工具包共享出去。

Apache服务ab压力测试

(8)通过Samba服务将工具包挂载到Linux系统。

[root@localhost ~]# smbclient -L //192.168.100.50/   //查看共享
Enter SAMBA\root's password:      //匿名共享,没有密码,直接回车
OS=[Windows 10 Enterprise LTSC 2019 17763] Server=[Windows 10 Enterprise LTSC 2019 6.3]

    Sharename       Type      Comment
    ---------       ----      -------
    IPC$            IPC       远程 IPC
    share           Disk      
    tools           Disk      
    Users           Disk      
Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
NetBIOS over TCP disabled -- no workgroup available
[root@localhost ~]# mkdir /mnt/tools    //创建挂载目录
[root@localhost ~]# mount.cifs //192.168.100.50/tools /mnt/tools/     //挂载
Password for root@//192.168.100.50/tools:  
[root@localhost ~]# cd /mnt/tools/    //进入挂载目录
[root@localhost tools]# ls     //查看
awstats-7.6.tar.gz                extundelete-0.2.4.tar.bz2  forbid.png                 jdk-8u191-windows-x64.zip  LAMP-C7
cronolog-1.6.2-14.el7.x86_64.rpm  fiddler.exe                intellijideahahau2018.rar  john-1.8.0.tar.gz          picture.jpg
[root@localhost tools]# 

(9)将源码编译安装Apache服务的压缩包解压到“/opt/”目录。

[root@localhost tools]# cd LAMP-C7/       //切换目录
[root@localhost LAMP-C7]# ls
apr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt      php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2     mysql-5.6.26.tar.gz
[root@localhost LAMP-C7]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt/     //解压
......//省略解压详情
[root@localhost LAMP-C7]# tar zxvf apr-1.6.2.tar.gz -C /opt/           //解压
......//省略解压详情
[root@localhost LAMP-C7]# tar zxvf apr-util-1.6.0.tar.gz -C /opt/     //解压
......//省略解压详情

(10)进入“/opt/”目录,将两个apr包移动到“httpd-2.4.29/srclib/”目录,并重命名。

[root@localhost LAMP-C7]# cd /opt/    
[root@localhost opt]# ls
apr-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

(11)进入“httpd-2.4.29/”目录,然后安装编译所需环境包。

[root@localhost opt]# ls
httpd-2.4.29  rh
[root@localhost opt]# cd httpd-2.4.29/
[root@localhost httpd-2.4.29]# ls
ABOUT_APACHE     ap.d          CHANGES         docs         httpd.spec      libhttpd.dep  Makefile.win   README            srclib
acinclude.m4     build         CMakeLists.txt  emacs-style  include         libhttpd.dsp  modules        README.cmake      support
Apache-apr2.dsw  BuildAll.dsp  config.layout   httpd.dep    INSTALL         libhttpd.mak  NOTICE         README.platforms  test
Apache.dsw       BuildBin.dsp  configure       httpd.dsp    InstallBin.dsp  LICENSE       NWGNUmakefile  ROADMAP           VERSIONING
apache_probes.d  buildconf     configure.in    httpd.mak    LAYOUT          Makefile.in   os             server
[root@localhost httpd-2.4.29]# 
[root@localhost httpd-2.4.29]# yum -y install \
> gcc \
> gcc-c++ \
> make \
> pcre \
> pcre-devel \
> expat-devel \
> zlib-devel \
> perl
......//省略安装过程

(12)进行对Apache服务器的配置。

[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \    //安装路径
> --enable-so \     //启用动态加载模块支持
> --enable-rewrite \     //启用网页地址重写功能
> --enable-charset-lite \    //启用字符集支持
> --enable-cgi    //启用CGI脚本程序支持

(13)编译安装Apache服务。

[root@localhost httpd-2.4.29]# make && make install
......//省略编译安装过程
[root@localhost httpd-2.4.29]#

(14)对Apache服务配置文件进行修改

[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf     //创建软链接,方便使用
[root@localhost httpd-2.4.29]# 

Listen 192.168.50.133:80    //开启IPv4监听
#Listen 80      //注释IPv6监听
#
ServerName www.abc.com:80      //设置域名

ab压力测试

[root@localhost named]# ab -n 3000 -c 1000 www.abc.com/index.html
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.abc.com (be patient)
Completed 300 requests
Completed 600 requests
Completed 900 requests
Completed 1200 requests
Completed 1500 requests
Completed 1800 requests
Completed 2100 requests
Completed 2400 requests
Completed 2700 requests
Completed 3000 requests
Finished 3000 requests

Server Software:        Apache/2.4.29            //http响应数据的头信息
Server Hostname:        www.abc.com         //请求的url中的主机名称
Server Port:            80                                   //web服务器软件的监听端口

Document Path:          /index.html              //请求的url根的绝对路径
Document Length:        45 bytes                //http响应数据的正文长度

Concurrency Level:      1000                     //并发的用户数
Time taken for tests:   21.061 seconds    //所有这些请求被处理完成所花费的时间总和
Complete requests:      3000         //表示请求总数
Failed requests:        220             //失败的请求总数
   (Connect: 0, Receive: 0, Length: 220, Exceptions: 0)
Total transferred:      810356 bytes       //请求的响应数据长度总数
HTML transferred:       126180 bytes
Requests per second:    142.44 [#/sec] (mean)      //服务器的吞吐率,每秒处理的请求总数
Time per request:       7020.414 [ms] (mean)    //用户平均请求等待时间
Time per request:       7.020 [ms] (mean, across all concurrent requests)    //每个请求实际运行时间的平均值
Transfer rate:          37.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9  14.5      4      62
Processing:     9 1389 5135.1     27   21027
Waiting:        0   27  34.4     22     234
Total:         13 1398 5132.8     33   21027

Percentage of the requests served within a certain time (ms)   //描述每个请求处理时间的分布情况。
  50%     33
  66%     37
  75%     42
  80%     55
  90%     95
  95%  21020
  98%  21027
  99%  21027
 100%  21027 (longest request)
[root@localhost named]#
参数 描述
Server Software http响应数据的头信息
Server Hostname 请求的url中的主机名称
Server Port web服务器软件的监听端口
Document Path 请求的url根的绝对路径
Document Length http响应数据的正文长度
Concurrency Level 并发的用户数
Time taken for tests 所有这些请求被处理完成所花费的时间总和
Complete requests 表示总请求数
Failed requests 失败的请求总数
Total transferred 请求的响应数据长度总和
Requests per second 服务器的吞吐率,每秒处理的请求数
Time per request 用户平均请求等待时间
Time per request 每个请求实际运行时间的平均值
Percentage of the requests served within a certain time (ms) 描述每个请求处理时间的分布情况
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI