1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 手把手教你 嘴对嘴传达------Apache --ab测试

手把手教你 嘴对嘴传达------Apache --ab测试

时间:2019-01-02 00:17:52

相关推荐

手把手教你 嘴对嘴传达------Apache --ab测试

文章目录

一、ab的原理二 、ab测试结果关键参数说明1、ab常用参数三、实验步骤1、一键编译安装apache2、一键配置dns服务3、在网站首页放张图片4、没压缩之前ab测试一下5、压缩之后测试6、再重新测试

一、ab的原理

ab是apachebench命令的缩写。

ab的原理:ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。

ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原理类似CC攻击。自己测试使用也需要注意,否则一次上太多的负载。可能造成目标服务器资源耗完,严重时甚至导致死机。

二 、ab测试结果关键参数说明

1、ab常用参数

-n :总共的请求执行数,缺省是1;-c: 并发数,缺省是1;-t:测试所进行的总时间,秒为单位,缺省50000s-p:POST时的数据文件-w: 以HTML表的格式输出结果

具体如下Server Hostname: 192.168.110.132 #请求的URL主机名Server Port: 80#请求端口Document Path:/ #请求路径Document Length: 5039 bytes #HTTP响应数据的正文长度Concurrency Level:100 #并发用户数,这是我们设置的参数之一Time taken for tests: 11.317 seconds #所有这些请求被处理完成所花费的总时间 单位秒Complete requests:1097#总请求数量,这是我们设置的参数之一Failed requests: 159#表示失败的请求数量(Connect: 0, Receive: 0, Length: 159, Exceptions: 0)Write errors: 0Total transferred:5674622 bytes#所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度HTML transferred: 5527624 bytes #所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度Requests per second: 96.94 [#/sec] (mean) #吞吐量,计算公式:Complete requests/Time taken for tests 总请求数/处理完成这些请求数所花费的时间Time per request: 1031.611 [ms] (mean) #用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)。处理完成所有请求数所花费的时间/(总请求数/并发用户数)Time per request: 10.316 [ms] (mean, across all concurrent requests) #服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency LevelTransfer rate:489.68 [Kbytes/sec] received 表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。Connection Times (ms)min mean[+/-sd] median maxConnect: 1 516 1148.73 7077Processing:4 212 415.327 2193Waiting: 3 178 339.126 1833Total:6 728 1158.689 7445Percentage of the requests served within a certain time (ms)50%88 #50%的请求在88ms内返回66% 90975% 104380% 115190% 229495% 301998% 4093 #98%的请求在4093ms内返回99% 7024100% 7445 (longest request)

三、实验步骤

1、一键编译安装apache

#!/bin/baship=ping -c 2 -w 3 -i 0.3 $ip &>/dev/nullif [ $? -eq 0 ]thenecho " 可以ping的通百度"elseecho "正在更改你的网卡"sed -i '/^IPADDR=/cIPADDR=192.168.110.132' /etc/sysconfig/network-scripts/ifcfg-ens33sed -i '/^GATEWAY=/cGATEWAY=192.168.110.2' /etc/sysconfig/network-scripts/ifcfg-ens33sed -i '/^DNS1=/cDNS1=8.8.8.8' /etc/sysconfig/network-scripts/ifcfg-ens33echo "网卡配置文件已改完 正在重启网络服务"systemctl restart networkfiping -c 2 $ip &>/dev/nullif [ $? -eq 0 ] ;thenecho "一切准备就绪"elseecho "请检查你绑定的网卡是不是vm8"ficd ~cd apachetar zxvf apr-1.6.2.tar.gztar zxvf apr-util-1.6.0.tar.gztar jxvf httpd-2.4.29.tar.bz2mv apr-1.6.2 httpd-2.4.29/srclib/aprmv apr-util-1.6.0 httpd-2.4.29/srclib/apr-utilyum -y install gcc gCc-C++ make pcre-devel expat-devel perl zlib-develif [ $? -eq 0 ];thenecho "正在下载软件包环境"ficd httpd-2.4.29./configure \--prefix=/usr/local/httpd \--enable-so \--enable-rewrite \--enable-charset-lite \--enable-cgi \--enable-deflateif [ $? -eq 0 ];thenecho "./configure 执行成功"elseecho "凉了"fimakemake installcp /usr/local/httpd/bin/apachectl /etc/init.d/httpdsed -i '2a#chkconfig: 35 85 21' /etc/init.d/httpdchkconfig --add httpdsed -i '/#ServerName :80/cServerName :80' /usr/local/httpd/conf/httpd.confsed -i '52s/^/#/' /usr/local/httpd/conf/httpd.confsed -i '/#Listen 12.34.56.78:80/cListen 192.168.110.132:80' /usr/local/httpd/conf/httpd.confln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.confln -S /usr/local/httpd/bin/* /usr/local/bin/systemctl stop firewalld.servicesetenforce 0service httpd startif [ $? -eq 0 ] ;thenecho "成功启动apache"elseecho "完犊子了"fi

2、一键配置dns服务

#!/bin/bashsed -i 's/localhost/any/' /etc/named.confsed -i 's/127.0.0.1/any/' /etc/named.confsed -i '19,23{H};23G' /etc/named.rfc1912.zonessed -i '25s/localhost//' /etc/named.rfc1912.zonessed -i '27s/named.localhost/.zone/' /etc/named.rfc1912.zones#cat>>/etc/named.rfc1912.zones<<EOF#zone "" IN {# type master;# file ".zone";# allow-update{none; };#};#EOFcp -p /var/named/named.localhost /var/named/.zone#sed -i '/127.0.0.1\|AAAA/d' /var/named/.zonecat>/var/named/.zone<<EOF\$TTL 1D@ IN SOA @ rname.invalid. (0 ; serial1D; refresh1H; retry1W; expire3H ) ; minimumNS@A 127.0.0.1www IN A 192.168.110.132EOFsed -i '1inameserver 192.168.110.132' /etc/resolv.confnslookup

3、在网站首页放张图片

cd /usr/local/httpd/bin/ln -s /usr/local/httpd/bin/ab /usr/sbin/service httpd start[root@localhost bin]# setenforce 0[root@localhost bin]# systemctl stop firewalldhost has address 192.168.110.132cd /usr/local/httpd/htdocsvim index<html><body><h1>It works!</h1></body></html><img src="av.jpg"/></body></html>

4、没压缩之前ab测试一下

[root@localhost htdocs]# ab -n 3000 -c 1000 /index.htmlThis is ApacheBench, Version 2.3 <$Revision: 1807734 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, /Licensed to The Apache Software Foundation, /Benchmarking (be patient)Completed 300 requestsCompleted 600 requestsCompleted 900 requestsCompleted 1200 requestsCompleted 1500 requestsCompleted 1800 requestsCompleted 2100 requestsCompleted 2400 requestsCompleted 2700 requestsCompleted 3000 requestsFinished 3000 requestsServer Software: Apache/2.4.29Server Hostname: Server Port: 80Document Path:/index.htmlDocument Length: 80 bytesConcurrency Level:1000Time taken for tests: 0.734 seconds ////0.734秒处理Complete requests:3000Failed requests: 0Total transferred:972000 bytesHTML transferred: 240000 bytesRequests per second: 4086.01 [#/sec] (mean)Time per request: 244.737 [ms] (mean)Time per request: 0.245 [ms] (mean, across all concurrent requests)Transfer rate:1292.84 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median maxConnect: 0 29 17.42774Processing:5 67 92.440503Waiting: 3 60 91.532491Total: 21 96 103.567562Percentage of the requests served within a certain time (ms)50%6766%8775%9580%9890% 11195% 32698% 50599% 511100% 562 (longest request)[root@localhost htdocs]#

5、压缩之后测试

进入主配置文件 /usr/local/httpd/conf/httpd.conf

开启下面三个功能模块

LoadModule headers_module modules/mod_headers.soLoadModule filter_module modules/mod_filter.soLoadModule deflate_module modules/mod_deflate.so

最后一行填写

<IfModule mod_deflate.c>AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascrip text/jpg text/pngDeflateCompressionLevel 9SetOutputFilter DEFLATE</IfModule>

6、再重新测试

这里需要强调的是 ,压力测试是有偶然性的 ,需要多次测试取平均值 ,这里小编测试的网站没有东西,就不进行测试了

[root@localhost conf]# ab -n 3000 -c 1000 /index.html在进行压力测试Time taken for tests: 20.964 seconds

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。