⚠️ 本文写于 2014 年,操作可能已过时,仅供参考。
闲
闲得没事对所用 VPS 来个压力测试。现在所用的 VPS 是去年年付的一个,配置挺低的:
内存 256MB 且无突发,硬盘 30G,月流量 500G,操作系统 ubuntu 13.10 32bit。
一般常用压力测试用的软件是 webbench 或者是 http_load,我以前也用过,这两个网上一搜一大堆文章。这次懒得用了,换其它的试试玩玩。用的是 siege 和 HttpBench,记录一下:
Siege
Sigeg 官方主页:http://www.joedog.org/siege-home/
官方说明:
Siege 官方英文说明(点击展开)
What Is It?
Siege is an open source stress / regression test and benchmark utility. It can stress a single URL with a user defined number of simulated users or it can read many URLs into memory and stress them simultaneously. The program reports the total number of hits recorded, bytes transferred, response time, concurrency, and return status. Most features are configurable with command line options which also include default values to minimize the complexity of the program’s invocation. Siege allows you to stress a web server with n number of users t number of times, where n and t are defined by the user. It records the duration time of the test as well as the duration of each single transaction. It reports the number of transactions, elapsed time, bytes transferred, response time, transaction rate, concurrency and the number of times the server responded OK, that is status code 200. Siege was designed and implemented by Jeffrey Fulmer in his position as Webmaster for Armstrong World Industries. It was modeled in part after Lincoln Stein’s torture.pl and it’s data reporting is almost identical. But torture.pl does not allow one to stress many URLs simultaneously; out of that need siege was born… When a httpd server is being hit by the program, it is said to be “under siege.”
最新版本下载地址:http://download.joedog.org/siege/siege-latest.tar.gz
下载安装
root 登陆 vps,然后
mkdir toolscd tools#还是建个tools目录放这些东西好一点#下载并解压
wget http://download.joedog.org/siege/siege-latest.tar.gztar zxvf siege-latest.tar.gz这个时候可以输入个ls命令查看目录,最新的版本是 3.0.6,于是
cd siege-3.0.6./configuremake && make install#进入siege-3.0.6目录并编译安装没什么问题的话完成后就会出现 siege 的各种参数使用说明。
参数设置
除了看上面完成后的参数设置按常规还可以输入siege -h来查看。
测试命令:siege [options] URL
[options]是各种参数,一般会用到:
-c //并发数,默认是10。
-t //测试时间,单位是分钟,-t 10表示持续10分钟。
-f //对应内容为一行一个url的文件来测试。
-r //重复次数。更多用法详见参数,siege -h
URL就是需要测试的 ip 地址,对应域名也可以。
测试一下
先温柔点:
siege https://clearsky.me -c 100 -t 3 #并发数100,持续3分钟实时感受,打开网站基本没什么变化,没明显感觉慢,最后完成后出现了个:
[error]unable to create log file: No such file or directory
如果出现这个问题直接在/usr/local目录下新建个var目录就可以了,
结果输出:
Transactions: 1508 hits //总共完成处理次数Availability: 100.00 % //成功率Elapsed time: 179.91 secs //总耗时Data transferred: 5.01 MB //总共传输数据大小Response time: 10.98 secs //响应时间Transaction rate: 8.38 trans/sec //平均每秒处理次数Throughput: 0.03 MB/sec //每秒传输数据大小Concurrency: 92.05 //最高并发数Successful transactions: 1508 //成功次数Failed transactions: 0 //失败次数Longest transaction: 12.59 //每次最长时间Shortest transaction: 0.72 //每次最短时间加重一点:
siege https://clearsky.me -c 500 -t 5 #并发数500,持续5分钟出现:
[fatal] unable to allocate memory for 500 simulated browser: Cannot allocate memory
搜索了一下:找到这样解释:via:Siege 使用笔记
性能测试过程中,当并发数达到一定情况下可能会遇到“FATAL: unable to allocate memory for ** simulated browser: Cannot allocate memory”类似错误,这是由于 linux 系统配置限制导致的,可通过”ulimit -a”查看, 修改参数来进行调试(但总会受限于硬件设备)
于是我减小到 300,感觉打开已经很慢了,卡卡的,测试结果如下:
Transactions: 174 hits //总共完成处理次数Availability: 12.86 % //成功率Elapsed time: 20.96 secs //总耗时Data transferred: 0.76 MB //总共传输数据大小Response time: 10.76 secs //响应时间Transaction rate: 8.30 trans/sec //平均每秒处理次数Throughput: 0.04 MB/sec //每秒传输数据大小Concurrency: 89.34 //最高并发数Successful transactions: 174 //成功次数Failed transactions: 1179 //失败次数Longest transaction: 17.88 //每次最长时间Shortest transaction: 0.02 //每次最短时间Httpbench
这个是我以前在 hostloc 上看到有人发的,挺小巧的,也相对简单。
官方地址:https://code.google.com/p/httpbench/
下载地址:https://httpbench.googlecode.com/files/httpbench-0.11.tar.gz
官方简单说明:
Requirement:
linux with kernel 2.6 or higher
Install:
make && make install
Usage:
httpbench thread-numbers url
先是下载安装,root 登陆终端后:
下载解压
wget https://httpbench.googlecode.com/files/httpbench-0.11.tar.gztar zxvf httpbench-0.11.tar.gz然后:
进入目录并安装
cd httpbenchmake && make install完成后测试
httpbench 200 / #不要忘了后面的斜杠“/”运行之后随时Ctrl + C终止,终止后就看到简单的数据:
Speed=83323 pages/min, 452984 bytes/sec.Requests: 45628 susceed, 200 failed.结束小小小小小总结
话说 200 就搞得 nginx 挂了,我这 vps 得有多搓,好了,就到这了。
评论
GitHub 登录后可评论。
评论区会在滚动到这里时自动加载。