使用文档参考地址:https://www.joedog.org/siege-manual/

siege4地址:http://download.joedog.org/siege/

cd /usr/local/src

#下载程序安装包:
wget http://download.joedog.org/siege/siege-4.0.2.tar.gz

#安装openssl,参考 openssl安装文档
which openssl

#解压缩.tar.gz程序包
tar zxvf siege-4.0.2.tar.gz

#进入主文件目录
cd siege-4.0.2

#删除上次产生的obj及可执行文件,如重复安装,可执行该命令
make clean

#校验配置和环境信息
./configure --prefix=/opt/siege4.0 --with-ssl=/opt/openssl1.0

#编译和安装
make && make install

siege命令参数

SIEGE 4.0.2
Usage: siege [options]
siege [options] URL
siege -g URL
Options:
-V, --version VERSION, prints the version number.
-h, --help HELP, prints this section.
-C, --config CONFIGURATION, show the current config.
-v, --verbose VERBOSE, prints notification to screen.
-q, --quiet QUIET turns verbose off and suppresses output.
-g, --get GET, pull down HTTP headers and display the
transaction. Great for application debugging.
-c, --concurrent=NUM CONCURRENT users, default is 10
-r, --reps=NUM REPS, number of times to run the test.
-t, --time=NUMm TIMED testing where "m" is modifier S, M, or H
ex: --time=1H, one hour test.
-d, --delay=NUM Time DELAY, random delay before each requst
-b, --benchmark BENCHMARK: no delays between requests.
-i, --internet INTERNET user simulation, hits URLs randomly.
-f, --file=FILE FILE, select a specific URLS FILE.
-R, --rc=FILE RC, specify an siegerc file
-l, --log[=FILE] LOG to FILE. If FILE is not specified, the
default is used: PREFIX/var/siege.log
-m, --mark="text" MARK, mark the log file with a string.
between .001 and NUM. (NOT COUNTED IN STATS)
-H, --header="text" Add a header to request (can be many)
-A, --user-agent="text" Sets User-Agent in request
-T, --content-type="text" Sets Content-Type in request

 

参数项使用说明
-c 100 指定并发数 100
-r 10 指定测试次数 10
-f urls.txt 指定url文件
-i internet系统,随机发送url
-b 请求无需等待 -d NUM 延迟多少秒
-t 5 持续测试5分钟 -t3600S, -t60M, -t1H
-v 输出详细信息
-l 记录压测日志信息到指定文件
# -r和-t一般不同时使用

例如:
cd /opt/siege4.0/bin
./siege -c 10 -b -t 10 www.xxx.com

指定http请求头 文档类型
./siege -H "Content-Type:application/json" -v -c 10 -r 10 -f urls.txt -i -d 1 -t20s

读入文件方式:
post中的参数可以放到一个文件,再通过以上方式来使用
./siege -c 2 -r 2 -b -t 10 www.xxx.com post <./purlx.txt

在文件中,可以定义变量。类似shell的方式,使用${}或$()。
host=www.xxx.com http://${host}/index.html

文件urls.txt中的地址:
http://www.xxx.com/index.html
http://www.xxx.com/xxx.jsp
http://www.xxx.com/xxx.do?key=value
http://www.xxx.com/xxx.do post key=value
http://www.xxx.com/xxxx.do post key1=value&key2=value2

1,发送post请求时,url格式为:http://www.xxx.com/ post p1=v1&p2=v2
2,如果url中含有中文和空格,需先进行encode编码。


结果说明:
Transactions: 16 hits 处理的次数
Availability: 100.00 % 成功的请求/总的请求的百分比
Elapsed time: 9.95 secs 运行的时间,单位秒
Data transferred: 0.55 MB 传输的数据量
Response time: 0.83 secs 响应时间
Transaction rate: 1.61 trans/sec 平均每秒完成的事务数
Throughput: 0.05 MB/sec 平均每秒传送的数据量
Concurrency: 1.33 实际最高并发链接数
Successful transactions: 19 成功处理的次数
Failed transactions: 0 失败处理的次数
Longest transaction: 2.28 最长请求处理的时间
Shortest transaction: 0.25 最短请求处理时间

#url post
http://www.xxx.com post userId=xxx&name=xxx


#当用siege压测并发2万时,可通过shell方式来处理,避免siege出错
sh loadForum.sh 2 4 600s forum01.txt 2
agent="Siege 1.0"
rcconfig="/opt/siege4.0/etc/siegerc"
usernumber=$1
threadnumber=$2
vtime=$3
url=$4

for vthread in `seq 1 $threadnumber`
do
if(($5==1))
then
`nohup /opt/siege4.0/bin/siege -c $usernumber -t $vtime -i -b -f $url -R $rcconfig -A "$agent" >/dev/null &`
#echo $runTime
else
/opt/siege4.0/bin/siege -c $usernumber -t $vtime -i -b -f $url -R $rcconfig -A "$agent" &
#echo $runTime
fi
done

#一次杀掉所有进程
ps aux|grep siege|grep -v grep|awk '{print $2}'|xargs kill -9


#单独命令运行
/opt/siege4.0/bin/siege -c 500 -t 600s -i -b -f /opt/siege4.0/etc/website.txt -R /opt/siege4.0/etc/siegerc -A Siege 1.0 &

posted on 2017-10-09 12:20  新美好时代  阅读(217)  评论(0编辑  收藏  举报