zoukankan      html  css  js  c++  java
  • 【转】Apache ab压力测试

    一、什么是ab

    ab,即Apache Benchmark,是一种用于测试Apache超文本传输协议(HTTP)服务器的工具。

    ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。

    ab命令对发出负载的计算机要求很低,既不会占用很高CPU,也不会占用很多内存,但却会给目标服务器造成巨大的负载,其原理类似CC攻击。

    二、ab的安装

    安装了Apache,就能够在Apache的安装目录中找到它。它的居住地址是Apache安装目录/bin/ab.exe

    没有安装apache可以直接安装包

    yum -y install httpd-tools
    ab -V
    

    在使用之前我们先来学习一下ab的用法。然后键入帮助命令ab -h,就可以看到如下的用法介绍界面。

    [root@localhost ~]# ab -h
    Usage: ab [options] [http[s]://]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//超时,默认每个response 30s
                        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 for POST/PUT data, 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 //在HTML表格中打印结果
        -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.
        -q              Do not show progress when doing more than 150 requests
        -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
                        (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
    

    三、ab的使用

    虽然ab可以配置的参数选项比较多,但是,一般情况下我们只需要使用形如ab -n 数字 -c 数字 url路径的命令即可。比如,测试总次数为1000,并发数为10(相当于10个用户同时访问,他们总共访问1000次)。

    [root@localhost ~]# ab -n1000 -c10  http://www.163.com/
    
    Benchmarking www.163.com (be patient).....done
    
    
    Server Software:        nginx			#被测试服务器软件名称
    Server Hostname:        www.163.com		#服务器主机名
    Server Port:            80
    
    Document Path:          /				#请求的URL中的根绝对路径
    Document Length:        20600 bytes		#页面的大小
    
    Concurrency Level:      10				#并发数
    Time taken for tests:   1.384 seconds	#整个测试耗时
    Complete requests:      100				#总共完成的请求数量
    Failed requests:        0				#失败数
    Write errors:           0				#失败数
    Total transferred:      2097300 bytes	#测试过程中产生的网络传输总量
    HTML transferred:       2060000 bytes	#测试过程中产生的HTML传输量
    Requests per second:    72.23 [#/sec] (mean)#表示服务器吞吐量,每秒事务数,括号中的 mean 表示这是一个平均值
    Time per request:       138.441 [ms] (mean)#表示用户请求的平均响应时间,后面括号中的mean表示这是一个平均值
    Time per request:       13.844 [ms] (mean, across all concurrent requests)#表示服务器请求平均处理时间,即实际运行时间的平均值
    Transfer rate:          1479.44 [Kbytes/sec] received#表示这些请求在单位时间内从服务器获取的数据长度,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
    
    #网络上消耗的时间的分解,表示这些请求在单位时间内从服务器获取的数据长度
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:       27   34   4.7     33      45	#socket链路建立消耗,代表网络状况好
    Processing:    71   90  10.3     91     126	#写入缓冲区消耗+链路消耗+服务器消耗
    Waiting:       44   55   7.4     55      86 #写入缓冲区消耗+链路消耗+服务器消耗+读取数据消耗
    Total:         99  123  14.1    125     165 #单个事务总时间
    
    #整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于125毫秒,60%的用户响应时间小于133毫秒,
    #最大的响应时间小于165 毫秒
    Percentage of the requests served within a certain time (ms)
      50%    125
      66%    133
      75%    135
      80%    137
      90%    141
      95%    145
      98%    148
      99%    165
     100%    165 (longest request)
    

    总结

    1.ab 判断成功与否只是判断响应码,不接收服务器的返回值,所以同样的响应ab测试支持的并发数大于Locust和Jemter,TPS的响应值也会比较大

    2.ab运行的测试并发数与ab所运行的机器的cpu的颗粒度有很大的关系,cpu颗粒度越大,测试结果支持的并发数越大

    3.ab适合测试HTTP协议的URL的连接并发,特别是Web系统的首页

    参考

    性能测试工具AB的使用

    https://www.cnblogs.com/ailiailan/p/10239849.html
    

    JMeter是久经考验的性能框架之一,其第一个版本大约在20年前发布。 它是用纯Java语言编写的。 最初,JMeter开发用于执行Web和FTP应用程序的负载测试。 但是,现在它允许测试几乎所有应用程序和协议,使用户能够使用与任何OS平台兼容的桌面应用程序来创建测试。

    https://github.com/apache/jmeter 3000+星
    

    Locust是Python编写的相对新颖的性能框架,在过去的五年中广为人知。 该框架的主要特点是它允许您使用纯Python编写性能脚本。具有高度可扩展性,因为它基于事件的完全实现。 由于这些事实,Locust拥有一个广泛且快速发展的社区,他们比JMeter更喜欢这个框架。

    https://github.com/locustio/locust 10000+星
  • 相关阅读:
    eclipse导入项目后出现红色叉号
    java.lang.ArithmeticException: Non-terminating decimal expansion
    IDEA 2020 注册码
    最新调查:游戏女性玩家群体达3亿!这意味着什么,嘻嘻......
    Linux安装配置Nginx服务器
    mysql/mariadb 远程登陆
    redis 集群 新增 master 节点 与 slave 挂靠命令
    RedisCluster 集群 之 Ruby 安装
    Linux CentOS 7 关闭防火墙
    springcloud 与 springboot 对应关系
  • 原文地址:https://www.cnblogs.com/sentangle/p/12673883.html
Copyright © 2011-2022 走看看