吞吐率指的是单位时间内服务器处理的请求数,通常使用 reqs/s (服务器每秒处理的请求数量)来表示。
吞吐率只描述了服务器在实际运行期间单位时间内处理的请求数,而我们更加关心的是服务器并发处理能力的上限,即单位时间内服务器能够处理的最大请求数(即最大吞吐率)。但在测试时,很难调动足够多的人测试服务器的最大吞吐率。所以,需要使用某些方法模拟足够数目的并发用户数,这种方法称为“压力测试”。
压力测试的工具很多,如LoadRunner、JMeter和ab等。由于LoadRunner和JMeter使用起来过于复杂,故这里我们介绍一种比较简单的压力测试工具ab。
ab(Apache Bench)是Apache附带的一个压力测试软件。它操作起来比较简单,功能基本能够满足我们的要求。
打开cmd,切换至Apache的bin目录(如:我的是
E:\xampp\apache\bin )
cd
E:\xampp\apache\bin
ab -h // 打印出ab工具的使用信息
Usage: ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header to use f