歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS Web壓力測試工具ApacheBench (ab)獨立安裝

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

日期:2017/2/27 15:53:46   编辑:Linux教程
Apache服務自帶了應該用於壓力測試的工具ab(ApacheBench),對應做一些簡單的壓力測試,它完全能夠勝任,本文主要介紹,在centos中不安裝Apache的情況下,安裝ab

1,ab運行的時候需要依賴包,我們先安裝依賴包,直接yum安裝就可以了
yum install apr-util

2, 下載apache的rpm包,分離ab
[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簡單用法
參數很多,一般我們用 -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
Copyright © Linux教程網 All Rights Reserved