如何使用siege測試服務器性能


siege是一款開源的壓力測試工具,可以根據配置對一個WEB站點進行多用戶的並發訪問,記錄每個用戶所有請求過程的相應時間,並在一定數量的並發訪問下重復進行。

1 安裝

# make sure you have the ssl libs installed(http://digitalleafblower.com/?p=166)
yum install mod_ssl openssl 
git clone https://github.com/JoeDog/siege.git
cat INSTALL  # 步驟
./utils/bootstrap 
./configure --with-ssl=/usr/bin/openssl
make
make install
export PATH=$PATH:/usr/local/bin

驗證:siege -V

2 get請求測試:

siege -c 100 -r 10 -f someScript.url

-c是並發量,-r是重復次數。並發量乘重復次數就是總的請求次數。

url文件就是一個文本,每行都是一個url,它會從里面隨機訪問的。

類似ab的純並發壓力測試:

siege -c 100 -r 10 http://www.google.com

(http://www.blogjava.net/iamtin/archive/2007/10/24/how_to_use_siege.html)

測試tornado程序性能:

$ siege -c 1000 -t 10s 'http://mysite.cn:8090'

xxx

Lifting the server siege...
Transactions:           4191 hits
Availability:         100.00 %
Elapsed time:           9.12 secs
Data transferred:       871.92 MB
Response time:            0.50 secs
Transaction rate:       459.54 trans/sec
Throughput:          95.60 MB/sec
Concurrency:          231.10
Successful transactions:        4203
Failed transactions:             0
Longest transaction:          6.56
Shortest transaction:         0.04

3 post請求測試

siege -c 500 -r 1 '10.23.54.151:19595/v1/db/nova/service_get_all POST <./postfile.json

content_type被正確設置為application/json,服務器正常處理返回。原來siege只能通過文件的擴展名來確定content type格式
(http://blog.csdn.net/xuriwuyun/article/details/12711927)

# 默認Content-type: application/x-www-form-urlencoded
# -g GET, pull down HTTP headers and display the transaction.
siege -c 1000 -t 10s 'http://mysite.cn:8090/login-is POST node=xxx&password=xxx' -g
# map the file extension to the appropriate content-type
# Content-type: application/json
siege -c 10 "http://mysite:8001/query_code POST <./querycode.json"  -t 10s

4 其他web壓力測試工具

siege簡單易用,其缺點在於統計結果過於粗糙。

如果想知道請求的平均時間、連接、處理、等待時間等信息,可以用apache自帶的AB工具(Apache Benchmark)

# 163yum源
cd /etc/yum.repos.d

#備份系統自帶的yum源

mv CentOS-Base.repo CentOS-Base.repo.bk

#下載163網易的yum源:

#centos7.x:

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

#centos6.x:

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

#更新完yum源后,執行下邊命令更新yum配置,使操作立即生效

yum makecache

ref(https://yq.aliyun.com/ziliao/115638)

安裝好Apache,就自帶AB了
yum install httpd

參數很多,一般我們用 -c 和 -n 參數就可以了. 例如:

./ab -c 1000 -n 1000 http://127.0.0.1/index.php

輸出的關鍵參數包括但不限於:

Requests per second: 122.12 [#/sec] (mean)
//大家最關心的指標之一,相當於 LR 中的 每秒事務數 ,后面括號中的 mean 表示這是一個平均值
Time per request: 8188.731 [ms] (mean)
//大家最關心的指標之二,相當於 LR 中的 平均事務響應時間 ,后面括號中的 mean 表示這是一個平均值
Time per request: 8.189 [ms] (mean, across all concurrent requests)
//每個請求實際運行時間的平均值
Transfer rate: 162.30 [Kbytes/sec] received
//平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導致響應時間延長的問題

Connection Times (ms)
min mean[+/-sd] median max // 最小值、平均數、中位數、最大值
Connect: 4 646 1078.7 89 3291
Processing: 165 992 493.1 938 4712
Waiting: 118 934 480.6 882 4554
Total: 813 1638 1338.9 1093 7785

ref(http://www.cnblogs.com/shipengzhi/archive/2012/10/09/2716766.html)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM