Apache服務自帶了應該用於壓力測試的工具ab(ApacheBench),對應作一些簡單的壓力測試,它徹底可以勝任,本文主要介紹,在centos中不安裝Apache的狀況下,安裝abhtml
1,ab運行的時候須要依賴包,咱們先安裝依賴包,直接yum安裝就能夠了python
yum install apr-utilios
2, 下載apache的rpm包,分離abnginx
[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簡單用法apache
參數不少,通常咱們用 -c 和 -n 參數就能夠了。centos
#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工具