zoukankan      html  css  js  c++  java
  • 网站压力测试之ApacheBench

        ApacheBench是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求。使用yum安装apache,ab工具在/usr/bin目录下:

    [root@test ~]# ls /usr/bin/ab*
    /usr/bin/ab

    使用方法:

    ab -n 1000 -c 10 http://192.168.80.157/

    若目标地址需用户认证,可加 -A 参数。

    ab 命令的常用参数:
    -n 数值: 发起测试的请求数
    -c 数值: 发起测试的同时连接数
    -A 用户名:密码

     结果分析:

    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 192.168.80.157 (be patient) 
    Completed 400 requests 
    Completed 800 requests 
    Completed 1200 requests 
    Completed 1600 requests 
    Completed 2000 requests 
    Completed 2400 requests 
    Completed 2800 requests 
    Completed 3200 requests 
    Completed 3600 requests 
    Completed 4000 requests 
    Finished 4000 requests
    
    Server Software: Apache/2.2.15 
    Server Hostname: 192.168.80.157 
    Server Port: 80
    
    Document Path: /phpinfo.php 
    #测试的页面 
    Document Length: 50797 bytes 
    #页面大小
    
    Concurrency Level: 1000 
    #测试的并发数 
    Time taken for tests: 11.846 seconds 
    #整个测试持续的时间 
    Complete requests: 4000 
    #完成的请求数量 
    Failed requests: 0 
    #失败的请求数量 
    Write errors: 0 
    Total transferred: 204586997 bytes 
    #整个过程中的网络传输量 
    HTML transferred: 203479961 bytes 
    #整个过程中的HTML内容传输量 
    Requests per second: 337.67 [#/sec] (mean) 
    #最重要的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值 
    Time per request: 2961.449 [ms] (mean) 
    #最重要的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值 
    Time per request: 2.961 [ms] (mean, across all concurrent requests) 
    #每个连接请求实际运行时间的平均值 
    Transfer rate: 16866.07 [Kbytes/sec] received 
    #平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题 
    Connection Times (ms) 
    min mean[+/-sd] median max 
    Connect: 0 483 1773.5 11 9052 
    Processing: 2 556 1459.1 255 11763 
    Waiting: 1 515 1459.8 220 11756 
    Total: 139 1039 2296.6 275 11843 
    #网络上消耗的时间的分解,各项数据的具体算法还不是很清楚
    
    Percentage of the requests served within a certain time (ms) 
    50% 275 
    66% 298 
    75% 328 
    80% 373 
    90% 3260 
    95% 9075 
    98% 9267 
    99% 11713 
    100% 11843 (longest request) 
    #整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于275毫秒,66%的用户响应时间小于298毫秒,最大的响应时间小于11843毫秒。对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数。

    测试过程遇到的问题:

     1.apr_socket_recv: Connection reset by peer (104)

    [root@test ~]# ab -n 1000 -c 1000  http://192.168.1.78/iwebshop/index.php 
    This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking 192.168.1.78 (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    apr_socket_recv: Connection reset by peer (104)
    Total of 435 requests completed

    解决方法:增加参数 -r  (Don't exit on socket receive errors.)

    [root@test ~]# ab -n 1000 -c 1000 -r  http://192.168.1.78/iwebshop/index.php 

    2.socket: Too many open files (24)

    解决方法:查看当前要以打开的文件个数

    [root@test ~]# ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 14802
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 14802
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited

    调整可以打开的文件数

    [root@test ~]# ulimit -n 65535

    重新执行该命令:

    [root@test ~]# ab -n 1000 -c 1000 -r  http://192.168.1.78/iwebshop/index.php 

    总结:在远程对web服务器进行压力测试,往往效果不理想(因为网络延时过大),建议使用内网的另一台或者多台服务器通过内网进行测试,这样得出的数据,准确度会

    高很多。如果只有单独的一台服务器,可以直接本地测试,比远程测试效果要准确。

  • 相关阅读:
    python学习笔记(五)os、sys模块
    Lepus_天兔的安装
    python学习笔记(四)random 、json模块
    python学习笔记(三)函数
    Jenkins的安装及邮件配置
    Nginx+tomcat配置负载均衡集群
    python学习笔记(二)文件操作和集合
    python练习
    Jmeter(十)Linux下配置安装Jmeter及执行测试任务
    Jmeter(九)压力测试
  • 原文地址:https://www.cnblogs.com/BuildingHome/p/4671981.html
Copyright © 2011-2022 走看看