Siege
Siege是一个HTTP基准测试工具。除了负载测试功能外,它还有一个很方便的-g选项,这非常类似于curl的-iL,只是这里Siege也会输出请求header。这里是针对Google的一个例子(为了简洁我拿掉了一些header)
$ siege -g www.google.com
GET / HTTP/1.1
Host: www.google.com
User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
Connection: close
HTTP/1.1 302 Found
Location: http://www.google.co.uk/
Content-Type: text/html; charset=UTF-8
Server: gws
Content-Length: 221
Connection: close
GET / HTTP/1.1
Host: www.google.co.uk
User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
Connection: close
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
X-XSS-Protection: 1; mode=block
Connection: close
GET / HTTP/1.1
Host: www.google.com
User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
Connection: close
HTTP/1.1 302 Found
Location: http://www.google.co.uk/
Content-Type: text/html; charset=UTF-8
Server: gws
Content-Length: 221
Connection: close
GET / HTTP/1.1
Host: www.google.co.uk
User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
Connection: close
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
X-XSS-Protection: 1; mode=block
Connection: close
Siege真正在行的是服务器的负载测试。就像ab(一款Apache HTTP服务基准测试工具)一样,你可以向站点发送并发请求,并查看它如何处理流量。用下面的命令,我们会在30秒内向Google发起20个并发连接,最后会得到一个漂亮的测试报告。
$ siege -c20 www.google.co.uk -b -t30s
...
Lifting the server siege... done.
Transactions: 1400 hits
Availability: 100.00 %
Elapsed time: 29.22 secs
Data transferred: 13.32 MB
Response time: 0.41 secs
Transaction rate: 47.91 trans/sec
Throughput: 0.46 MB/sec
Concurrency: 19.53
Successful transactions: 1400
Failed transactions: 0
Longest transaction: 4.08
Shortest transaction: 0.08
...
Lifting the server siege... done.
Transactions: 1400 hits
Availability: 100.00 %
Elapsed time: 29.22 secs
Data transferred: 13.32 MB
Response time: 0.41 secs
Transaction rate: 47.91 trans/sec
Throughput: 0.46 MB/sec
Concurrency: 19.53
Successful transactions: 1400
Failed transactions: 0
Longest transaction: 4.08
Shortest transaction: 0.08
Siege最有用的一个特性是它可以把一个记录URL的文件作为输入,然后“点击”这些URL,而不是只处理一个单独的页面。这对于负载测试来说很有用,因为你可以对站点重现真实的流量并观察站点如何处理,而不必一遍又一遍重复点击同一个URL。下面是你用Siege来重现Apache对另一台服务器的日志记录,以做负载测试的例子:
$ cut -d ' ' -f7 /var/log/apache2/access.log > urls.txt
$ siege -c<concurrency rate> -b -f urls.txt
$ siege -c<concurrency rate> -b -f urls.txt