zoukankan      html  css  js  c++  java
  • httpd的压力测试工具-ab工具使用案例

                      httpd的压力测试工具-ab工具使用案例

                                              作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

     

    一.httpd自带的工具程序

      事实上,在我们安装完Apache之后,它默认就会给我们安装上很多命令行工具,这个是httpd自带的工具。

    1>.htpasswd

      为基本认证创建和更新用户认证文件,如basic认证基于文件实现时,用到的账号密码文件生成工具
    [root@node101.yinzhengjie.org.cn ~]# htpasswd -c /etc/httpd/conf.d/httpdpasswd jason          #创建第一个用户时需要使用"-c"选项创建的用户的同时会自动创建文件,若文件已经存在则清空文件所有内容重新写入咱们新创建的用户。
    New password: 
    Re-type new password: 
    Adding password for user jason
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/httpdpasswd 
    -rw-r--r-- 1 root root 44 Dec  9 06:15 /etc/httpd/conf.d/httpdpasswd
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# date 
    Mon Dec  9 06:15:33 CST 2019
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# htpasswd -s /etc/httpd/conf.d/httpdpasswd jay            #创建第二个用户时千万别在使用"-c"选项哟,不过咱们可以使用-s指定加密算法为sha格式加密哟~
    New password: 
    Re-type new password: 
    Adding password for user jay
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# chmod 600 /etc/httpd/conf.d/httpdpasswd                 #为了安全起见,可以将文件权限改小点。
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /etc/httpd/conf.d/httpdpasswd 
    -rw------- 1 root root 82 Dec  9 06:20 /etc/httpd/conf.d/httpdpasswd
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/httpdpasswd 
    jason:$apr1$fnoHrDaP$Q0ZGtsOj9D4W3xHzIKm9E/
    jay:{SHA}o78nbN18sxTgXokaJRMEYOxV5b8=
    [root@node101.yinzhengjie.org.cn ~]# 
    htpasswd命令使用案例

    2>.apachectl

      httpd自带的服务控制脚本,支持start和stop
    [root@node107.yizhengjie.org.cn ~]# which apachectl  
    /usr/sbin/apachectl
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# file `which apachectl`
    /usr/sbin/apachectl: POSIX shell script, ASCII text executable            #这是一个脚本文件。
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                         Local Address:Port                                        Peer Address:Port              
    LISTEN      0      128                                        *:80                                                     *:*                  
    LISTEN      0      128                                        *:22                                                     *:*                  
    LISTEN      0      128                                       :::22                                                    :::*                  
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# apachectl stop
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                         Local Address:Port                                        Peer Address:Port              
    LISTEN      0      128                                        *:22                                                     *:*                  
    LISTEN      0      128                                       :::22                                                    :::*                  
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# apachectl start
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                         Local Address:Port                                        Peer Address:Port              
    LISTEN      0      128                                        *:80                                                     *:*                  
    LISTEN      0      128                                        *:22                                                     *:*                  
    LISTEN      0      128                                       :::22                                                    :::*                  
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# 
    apachectl命令使用案例

    3>.rotatelogs

      不关闭 Apache 而切换日志文件。用于日志滚动的工具。 

    4>.suexec

      执行外部程序前切换用户

    5>.logresolve

      将Apache日志文件中的IP地址解析到主机名称。

    6>.httxt2dbm

      为RewriteMap创建dbm文件。

    7>.htdbm

      操作DBM密码数据库。

    8>.htdigest

      为摘要认证创建和更新用户认证文件。

    9>.htcacheclean

      清理磁盘缓存

    10>.dbmmanage

      为基本认证创建和更新DBM格式的用户认证文件

    11>.configure

      配置源代码

    12>.apxs 

      Apache扩展工具,用于编译第三方模块或是开发第三方模块时会用到它

    二.httpd的压力测试工具

    ab, webbench, http_load, seige
    
    Jmeter:
      开源
    Loadrunner:
      商业,有相关认证
    tcpcopy:
      网易,复制生产环境中的真实请求,并将之保存

    三.Apache HTTP服务器性能测试基准工具ab工具(来自httpd-tools包)

    1>.常用参数

    语法格式:
      ab [OPTIONS] URL
    
    常用参数:
      -n:总请求数
      -c:模拟的并行数
      -k:以持久连接模式测试

    2>.ab命令使用案例

    [root@yinzhengjie ~]# ab -c 100 -n 50000 http://www.yinzhengjie.org.cn/index.html             ----->注意, -c 模拟的并发数,-n 模拟的总请求数, 一般并发数应该小于等于请求数。
    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 www.yinzhengjie.org.cn (be patient)
    Completed 5000 requests    ----->告诉我们测试以及完成了5000个请求,下面一次是执行进度。
    Completed 10000 requests
    Completed 15000 requests
    Completed 20000 requests
    Completed 25000 requests
    Completed 30000 requests
    Completed 35000 requests
    Completed 40000 requests
    Completed 45000 requests
    Completed 50000 requests
    Finished 50000 requests        ------->这就说明任务完成了。
    
    
    Server Software:        Apache/2.2.15            ----->服务器程序及版本;
    Server Hostname:        www.yinzhengjie.org.cn    ----->服务器的主机名;
    Server Port:            80                        ------>访问服务器的端口;
    
    Document Path:          /index.html                ------->请求资源的路径;
    Document Length:        7152 bytes                ------->请求资源的大小;
    
    Concurrency Level:      100                    -------->并发级别为100个;
    Time taken for tests:   9.013 seconds            --------->测试所经历的市场;
    Complete requests:      50000                    --------->完成的请求个数;
    Failed requests:        0                        --------->失败的请求个数;
    Write errors:           0                        ---------->发送的失败个数;
    Total transferred:      372761652 bytes            ---------->一共传输的355M,默认单位为字节;
    HTML transferred:       358043424 bytes            ---------->所传输的HTML大小为341M,上面的值包括请求首部等,因此上面的值会大于该值,该项只只包含文档实体本身;
    Requests per second:    5547.74 [#/sec] (mean)    ----------->每秒钟完成的请求数;
    Time per request:       18.025 [ms] (mean)        ----------->表示总的并发数需要的时间;
    Time per request:       0.180 [ms] (mean, across all concurrent requests)    ------>表示单个请求所需的时间。总的并发数是100,就用总的时间除以100就会得到这个数字;
    Transfer rate:          40390.33 [Kbytes/sec] received    -------->每秒钟传输的字节数;
    
    Connection Times (ms)    ----->处理时间,单位是毫秒。
                  min  mean[+/-sd] median   max
    Connect:        0    4   4.1      2      47        ---->连接时间
    Processing:     2   14   4.1     14      58        ----->处理进程(请求)总的时间
    Waiting:        0   12   3.6     13      49        ----->处理请求的等待的时间
    Total:          3   18   4.4     16      68            ------>整体花费的时间
    
    Percentage of the requests served within a certain time (ms)
      50%     16                 ------>表示完成50%的请求需要的时间是16ms,就是做一个评估。
      66%     18
      75%     19
      80%     19
      90%     20
      95%     26
      98%     33
      99%     37
     100%     68 (longest request)        ------>表示完成100%的请求需要的时间为68ms;
    You have new mail in /var/spool/mail/root
    [root@yinzhengjie ~]#

    3>.总结

      我这里测试是在本机测试的,效果是相当的好,实际生产环境中建议要跨主机测试,还有就是测试的时候不能光等测试结果,在进行压力测试的同时还要手动去打开这个网页,观察网页是否能够正常打开,如果不能正常打开就不是压力测试了,而成了崩溃测试啦,哈哈~尽管你满足了以上两点,ab的测试也并不准确,因为我们这里只是测试一个页面,而在生产实际环境中,我们打开的页面也不止一个哟。我们这里主要介绍ab的用法。ab只是可以用来做参考,不能真正用来作为实际生产环境中服务器可以承载的压力,除了ab的测试压力工具还有很多,比如http_load,webbench,seige等等,这些模拟测试工具都不精确。新环境上线之前,我们可以用tcp_copy来进行压力测试,它的可靠性会强一些。
  • 相关阅读:
    【CSS】CSS 页面布局:盒子模型(内容区、边框、内边距、外边距)
    压缩/解压文件
    WebApiClient.JIT
    并行+异步执行操作
    JSON输出时不输出某些属性值
    ASP.NET MVC中Filter过滤器的使用
    使用git克隆github上的项目失败,报错error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
    C# 实现WebSocket通信
    写日志
    list随机生成数值
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/6204049.html
Copyright © 2011-2022 走看看