Centos Web 壓力測試工具ApacheBench (ab)獨立安裝

摘要: ab命令會建立不少的併發訪問線程,模擬多個訪問者同時對某一URL地址進行訪問。它的測試目標是基於URL的,所以,既能夠用來測試Apache的負載壓力,也能夠測試nginx、lighthttp、tomcat、IIS等其它Web服務器的壓力。 ab命令對發出負載的計算機要求很低,既不會佔用很高CPU,也不會佔用不少內存,但卻會給目標服務器形成巨大的負載,其原理相似CC攻擊。本身測試使用也須注意,不然一次上太多的負載,可能形成目標服務器因資源耗完,嚴重時甚至致使死機。html

Apache服務自帶了應該用於壓力測試的工具ab(ApacheBench),對應作一些簡單的壓力測試,它徹底可以勝任,本文主要介紹,在centos中不安裝Apache的狀況下,安裝abios

1,ab運行的時候須要依賴包,咱們先安裝依賴包,直接yum安裝就能夠了nginx

yum install apr-utilapache

2, 下載apache的rpm包,分離abcentos

[root@Tomcat ~]# mkdir ab
[root@Tomcat ~]# cd ab
[root@Tomcat ab]# yum -y install yum-utils
[root@Tomcat ab]# yumdownloader httpd  #yumdownloader 須要安裝yum-utils才能使用,默認是沒有的安裝的
[root@Tomcat ab]# rpm2cpio httpd-2.2.3-91.el5.centos.i386.rpm |cpio -idmv
[root@Tomcat ab]# \cp -pa usr/bin/ab /usr/bin/  #複製到系統PATH就可使用了

 

3,ab簡單用法tomcat

參數不少,通常咱們用 -c 和 -n 參數就能夠了。服務器

#ab -c 1000 -n 4000 http://www.yousite.com/index.html  #具體到某頁面網絡

-n後面的4000表明總共發出4000個請求;-c後面的1000表示採用1000個併發(模擬1000我的同時訪問),後面的網址表示測試的目標URL。併發

[root@Tomcat ab]# ab -c 1000 -n 4000 http://192.168.0.222/docs/manager-howto.html
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.222 (be patient)
Completed 400 requests
Completed 800 requests
Completed 1200 requests
Completed 1600 requests
Completed 2000 requests
Completed 2400 requests
Completed 2800 requests
Completed 3200 requests
Completed 3600 requests
Finished 4000 requests


Server Software:        nginx/1.4.3
Server Hostname:        192.168.0.222
Server Port:            80

Document Path:          /docs/manager-howto.html
Document Length:        73924 bytes

Concurrency Level:      1000
Time taken for tests:   0.875928 seconds
Complete requests:      4000
Failed requests:        0
Write errors:           0
Total transferred:      296732000 bytes
HTML transferred:       295696000 bytes
Requests per second:    4566.59 [#/sec] (mean)
#最重要的指標之一,至關於LR中的每秒事務數,後面括號中的mean表示這是一個平均值,越大抗壓越強
Time per request:       218.982 [ms] (mean) 
#最重要的指標之二,至關於LR中的平均事務響應時間,後面括號中的mean表示這是一個平均值
Time per request:       0.219 [ms] (mean, across all concurrent requests)
Transfer rate:          330822.86 [Kbytes/sec] received
#平均每秒網絡上的流量,吞吐量,越大抗壓越強

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   4.5      0      29
Processing:     1   17  14.5     17     653
Waiting:        0   17  14.5     17     653
Total:         15   18  15.2     17     674

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     18
  75%     18
  80%     18
  90%     20
  95%     22
  98%     37
  99%     40
 100%    674 (longest request)

 

主要介紹裏面的幾個指標,我基本也就看這幾個指標,簡單測試足夠了,若是要全面的監控nginx,須要用到專業的監控程序,如nagios工具

參考:https://my.oschina.net/harlanblog/blog/395420

 yum install apr-util

yum install yum-utils

cd /opt

mkdir /opt/ab

yum install yum-utils.noarch

yumdownloader httpd-tools*

rpm2cpio httpd-*.rpm | cpio -idmv

cp /opt/ab/usr/bin/ab /usr/bin/

參考:

http://blog.csdn.net/fyqaccpt96/article/details/43272001

http://www.cnblogs.com/terryguan/p/6681055.html

相關文章
相關標籤/搜索