Linxu AB 命令:测试服务器性能的利器(linux ab 命令)
Linux AB 命令是由Apache设计,主要用途是用来测试某个网络服务器的性能。AB 命令不仅可以测试HTTP 服务,它也可以用来测试FTP、SMTP等服务的性能。
Linux AB 命令的使用非常简单,只需要一行命令就可以实现:
#ab -n 10000 -c 100 http://www.example.com/
其中,参数 -n 后面接的是请求数,参数 -c 后面接的是并发数,请求的资源是http://www.example.co m/。
运行 ab 后,它会自动执行多次测试,并将统计结果打印出来,如下:
#ab -n 10000 -c 100 http://www.example.com/
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.example.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.4.41
Server Hostname: www.example.com
Server Port: 80
Document Path: /
# Concurrency Level: 100
Time taken for tests: 0.942 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 4130000 bytes
HTML transferred: 3800000 bytes
Requests per second: 10643.76 [#/sec] (mean)
Time per request: 9.424 [ms] (mean)
Time per request: 0.094 [ms] (mean, across all concurrent requests)
Transfer rate: 4250.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 9
Processing: 1 9 5.2 8 51
Waiting: 0 9 5.1 8 47
Total: 1 9 5.2 8 51
Percentage of the requests served within a certain time (ms)
50% 8
66% 9
75% 10
80% 10
90% 10
95% 11
98% 12
99% 12
100% 51 (longest request)
从上面统计结果中可以看出,该服务器的性能很不错,每秒请求数量可达到10643.76,最大响应时间为51ms,最短响应时间只有8ms。
实际上,Linux AB 命令还有许多其他参数可选,可以根据测试的需求来进行设置,具体参数可以参照AB命令的man 文档来查看。
综上所述,Linux AB 命令是一款能有效测试各种服务器性能的工具,只需要一行命令即可实现,使用非常方便快捷。它所给出的性能数据非常可靠,是优化服务器性能的利器。