Java必备技能之环境搭建篇 (linux ab压力测试)

-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 for POSTing, eg.

‘application/x-www-form-urlencoded’

Default is ‘text/plain’

-v verbosity How much troubleshooting info to print

-w Print out results in HTML tables

-i Use HEAD instead of GET

-x attributes String to insert as table attributes

-y attributes String to insert as tr attributes

-z attributes String to insert as td or th attributes

-C attribute Add cookie, eg. 'Apache=1234. (repeatable)

-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’

Inserted after all normal header lines. (repeatable)

-A attribute Add Basic WWW Authentication, the attributes

are a colon separated username and password.

-P attribute Add Basic Proxy Authentication, the attributes

are a colon separated username and password.

-X proxy:port Proxyserver and port number to use

-V Print version number and exit

-k Use HTTP KeepAlive feature

-d Do not show percentiles served table.

-S Do not show confidence estimators and warnings.

-g filename Output collected data to gnuplot format file.

-e filename Output CSV file with percentages served

-r Don’t exit on socket receive errors.

-h Display usage information (this message)

-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)

-f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

详情说明:

-n在测试会话中所执行的请求个数。默认时,仅执行一个请求。请求的总数量

-c一次产生的请求个数。默认是一次一个。请求的用户量

-t测试所进行的最大秒数。其内部隐含值是-n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

-V显示版本号并退出。

测试之前关心的性能指标:

1吞吐量(Requests per second)

服务器并发处理能力的量化描述,单位是reqs/s,指的是在某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。

记住:吞吐率是基于并发用户数的。这句话代表了两个含义:

a、吞吐率和并发用户数相关

b、不同的并发用户数下,吞吐率一般是不同的

计算公式:总请求数/处理完成这些请求数所花费的时间,即

Request per second=Complete requests/Time taken for tests

必须要说明的是,这个数值表示当前机器的整体性能,值越大越好。

2 并发连接数(The number of concurrent connections)

并发连接数指的是某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。

3 并发用户数(Concurrency Level)

要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。在HTTP/1.1下,IE7支持两个并发连接,IE8支持6个并发连接,FireFox3支持4个并发连接,所以相应的,我们的并发用户数就得除以这个基数。

4 用户平均请求等待时间(Time per request)

计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数),即:

Time per request=Time taken for tests/(Complete requests/Concurrency Level)

5 服务器平均请求等待时间(Time per request:across all concurrent requests)

计算公式:处理完成所有请求数所花费的时间/总请求数,即:

Time taken for/testsComplete requests

可以看到,它是吞吐率的倒数。

同时,它也等于用户平均请求等待时间/并发用户数,即

Time per request/Concurrency Level

5、测试

ab压测 Nginx默认页做为演示:

ab的命令参数比较多,我们经常使用的是-c和-n参数。

[root@localhost usr]# ab -c 100 -n 10000 http://127.0.0.1/index.html

#同时处理1000个请求并运行10次index.html

#-c100表示并发用户数为100

#-n10000表示请求总数为10000

#简单使用说明

.``/ab -c 100 -n 10000 http:``//127``.0.0.1``/index``.html

#-c 100 即:每次并发100个

#-n 10000 即: 共发送10000个请求

6、解释

[root@zhy html]# ab -n100 -c10 127.0.0.1/index.html

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)…done

Server Software: Apache #测试服务器的名字

Server Hostname: 127.0.0.1 #请求的URL主机名

Server Port: 80 #web服务器监听的端口

Document Path: /index.php #请求的URL中的根绝对路径

Document Length: 211 bytes #HTTP响应数据的正文长度

Concurrency Level: 10 # 并发用户数,即-c10

Time taken for tests: 0.010 seconds #所有这些请求被处理完成所花费的总时间 单位秒

Complete requests: 100 # 总请求数量,即-n100

Failed requests: 0 # 表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况

Write errors: 0

Non-2xx responses: 100

Total transferred: 41000 bytes #所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度

HTML transferred: 21100 bytes # 所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度

Requests per second: 9994.00 [#/sec] (mean) #吞吐率,计算公式:Complete requests/Time taken for tests 总请求数/处理完成这些请求数所花费的时间

Time per request: 1.001 [ms] (mean) # 用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level),处理完成所有请求数所花费的时间/(总请求数/并发用户数)

Time per request: 0.100 [ms] (mean, across all concurrent requests) #服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level

Transfer rate: 4001.51 [Kbytes/sec] received #表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 0 0.0 0 0

Processing: 1 1 0.1 1 1

Waiting: 0 1 0.1 1 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值