侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Apache AB性能测试工具使用教程

linux  /  管理员 发布于 7年前   191

服务器负载太大而影响程序效率是很常见的,Apache服务器自带有一个叫ab(ApacheBench)的工具,在bin目录下。ab专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求,使用这个轻巧的工具我们可以对服务器进行负载测试。

今天在公司也用它作一些测试,现在整理了下它的一些东西分享下。

首先我们要得到Apache服务器的目录下bin的路径,我电脑中的路径是D:\wamp\bin\apache\Apache2.2.21\bin,打开cmd,转到这个目录下,在其中输入:ab -n 10 -c 10 /// 这条指令,这条指令的意思是:ab -n 全部请求数 -c 并发数 测试URL。这里值得注意的是,如果你的测试URL是一个网站的网址,请记得在其后加上/,否则会无法工作。

以下是我运行的结果:
复制代码 代码如下:
D:\wamp\bin\apache\Apache2.2.21\bin>ab -n 10 -c 10 ///

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 (be patient)…..done

Server Software:        Microsoft-IIS/6.0  //Microsoft-IIS服务器版本6.0

Server Hostname:          //服务器主机名

Server Port:            80  //服务器端口
Document Path:          /  //测试的页面文档

Document Length:        32639 bytes  //文档大小
Concurrency Level:      10  //并发数

Time taken for tests:   13.548 seconds  //整个测试持续的时间

Complete requests:      10  //完成的请求数量

Failed requests:        0  //失败的请求数量

Write errors:           0

Total transferred:      331070 bytes  //整个场景中的网络传输量

HTML transferred:       326390 bytes  //整个场景中的HTML内容传输量

Requests per second:    0.74 [#/sec] (mean)  //每秒事务数 ,后面括号中的 mean 表示这是一个平均值

Time per request:       13547.775 [ms] (mean)  //平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值

Time per request:       1354.777 [ms] (mean, across all concurrent requests)  //每个请求实际运行时间的平均值

Transfer rate:          23.86 [Kbytes/sec] received  //平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Connection Times (ms)  //网络上消耗的时间的分解

              min  mean[+/-sd] median   max

Connect:        1    2   0.8      2       3

Processing:  2163 3981 3420.2   2957   13540

Waiting:     1305 3204 3595.3   2096   13169

Total:       2164 3983 3420.0   2959   13541

//以下是整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于2959毫秒,66% 的用户响应时间小于3074毫秒,最大的响应时间小于13541 毫秒。由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数。

Percentage of the requests served within a certain time (ms)

  50%   2959

  66%   3074

  75%   3974

  80%   4008

  90%  13541

  95%  13541

  98%  13541

  99%  13541

 100%  13541 (longest request)

下面是ab的指令中参数的介绍:

复制代码 代码如下:

-n requests     全部请求数

-c concurrency  并发数

-t timelimit    最传等待回应时间

-p postfile     POST数据文件

-T content-type POST Content-type

-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    加入cookie, eg. ‘Apache=1234. (repeatable)

-H attribute    加入http头, eg. ‘Accept-Encoding: gzip'

                Inserted after all normal header lines. (repeatable)

-A attribute    http验证,分隔传递用户名及密码

-P attribute    Add Basic Proxy Authentication, the attributes

                are a colon separated username and password.

-X proxy:port   代理服务器

复制代码 代码如下:

-V              查看ab版本

-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

-h              Display usage information (this message)


  • 上一条:
    80端口被Pid为4的未知程序占用导致Apache不能启动的解决方法
    下一条:
    Apache限制IP并发数和流量控制的方法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客