ab-性能测试工具

ab-http服务器性能测试工具

可以测试某个端口  ab -n10  -c10 http://127.0.0.1:9999/
可以测试某个接口  ab -n10  -c10 http://127.0.0.1:9999/index.php

apache的ab工具 apache bench

查看是否已安装
ab -V

如果没安装则先安装
yum install -y httpd-tools
which ab
	/usr/bin/ab

使用
ab -n 请求数 -c 并发数 url
只要请求的url有http响应就行,不管url是端口还是文件
-k 表示 keep-alive 就是可以复用连接,如果连接还在的话,减小了服务端的连接消耗,以及响应时间。
其工作原理是发送一个简短的http请求头,然后等待响应。

ab -n 10000 -c 100 http://192.168.1.8:9501/index,php

表示,总共有10000个请求,由100个线程并发来消费这10000个请求,host需要带上反斜线

请求数多的话,会被按批量来发出

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:        swoole-http-server
Server Hostname:        192.168.1.8
Server Port:            9501

Document Path:          /
Document Length:        164 bytes

Concurrency Level:      100
Time taken for tests:   5.633 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3410000 bytes
HTML transferred:       1640000 bytes
Requests per second:    1775.32 [#/sec] (mean)
Time per request:       56.328 [ms] (mean)
Time per request:       0.563 [ms] (mean, across all concurrent requests)
Transfer rate:          591.19 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   21  11.0     20      64
Processing:     6   35  14.4     36      67
Waiting:        5   35  14.3     35      67
Total:          7   56  24.1     57     100

Percentage of the requests served within a certain time (ms)
  50%     57
  66%     71
  75%     78
  80%     82
  90%     87
  95%     90
  98%     93
  99%     96
 100%    100 (longest request)



解释:
	443 https的端口
	Server Software 服务器
	Time taken for tests 总共花的时间,秒
	Requests per second 平均每秒完成的请求数 QPS
	Time per request 一个请求的时间 毫秒

压力测试对比
	1、easyswoole - easyswoole创建的web服务
	2、swoole - swoole创建的web服务
	3、纯php脚本 - nginx

	2 > 1 > 3
	1,2相差不多,却高出3一倍多

top工具查看系统性能

你可能感兴趣的:(Linux)