Webbench 安装 支持POST方式
•
Webbench
下载
git clone https://github.com/winshining/webbench-plus-post.git
cd webbench-plus-post
安装编译环境
yum install -y gcc ctags
编译
make & make install
=> 如果遇到如下问题:
install: cannot create regular file '/usr/local/man/man1': No such file or directory make: *** [install] Error 1
查看man目录是存在,不存在,创建:
mkdir /usr/local/man
如man目录已存在,那问题只可能是权限了,修改好权限,问题解决:
chmod 777 /usr/local/man
测试
GET
比如测试百度, 启动100个客户端同时请求百度首页,持续60S:
webbench -t 60 -c 100 http://www.baidu.com/
webbench [option]... URL -f|--force Don't wait for reply from server. -r|--reload Send reload request - Pragma: no-cache. -t|--time <sec> Run benchmark for <sec> seconds. Default 30. -p|--proxy <server:port> Use proxy server for request. -c|--clients <n> Run <n> HTTP clients at once. Default one. -9|--http09 Use HTTP/0.9 style requests. -1|--http10 Use HTTP/1.0 protocol. -2|--http11 Use HTTP/1.1 protocol. --get Use GET request method. --head Use HEAD request method. --options Use OPTIONS request method. --trace Use TRACE request method. -?|-h|--help This information. -V|--version Display program version.
- -t:time是benchmark持续多久
- -c:clients是指time时间内请求多少次
- -f :不等待返回结果
POST
1、Content-Type: application/x-www-form-urlencoded
webbench --post content --header header1:value1 --header header2:value2 -t time -c number http://host/url
例子:
webbench --post "email=jason@163.com&password=S2FwLjIwMjAwMQ%3D%3D" -t 10 -c 10 http://www.baidu.com/login/check_login_ajax
2、Content-Type: multipart/form-data; boundary=random_bytes_or_numbers
webbench --post filename --file --header header1:value1 --header header2:value2 -t time -c number http://host/url
webbench
webbench是一款轻量级的web服务器压力测试工具,目前网上能找到的最新版本是webbench-1.5,原作者已经于2004年停止维护。
基本原理
webbench首先fork出多个子进程,每个子进程都循环做web访问测试。子进程把访问的结果通过pipe告诉父进程,父进程做最终的统计结果。
总结
- webbench 做压力测试时,该软件自身也会消耗CPU和内存资源,为了测试准确,请将 webbench 安装在别的服务器上;
- 压力测试工作应该放到产品上线之前,而不是上线以后;
- 测试时并发应当由小逐渐加大,比如并发100时观察一下网站负载是多少、打开页面是否流畅,并发200时又是多少、网站打开缓慢时并发是多少、网站打不开时并发又是多少;
- 更详细的进行某个页面测试,如电商网站可以着重测试购物车、推广页面等,因为这些页面占整个网站访问量比重较大。
解决webbench攻击的方法
最简单的方法,是把ip用iptables封掉,但是攻击者只要换个ip依然可以用这种方法攻击你。于是我采取了另外一种方法,禁止webbench压力测试。
在网站配置文件中,加入如下代码:
if ($http_user_agent ~ “WebBench”) { set $block_user_agents 1; }
锁掉所有来自webbench的用户访问,解决问题了呢。当然,也可以用于屏蔽掉ApacheBench等压力测试工具的这种恶意攻击。