码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Apache Bench(ab )压力测试


    目录

    • 参数说明
    • 示例1:压力测试
    • 示例2:测试post接口
      • post数据文件该如何编写?
    • apr_pollset_poll: The timeout specified has expired (70007)
    • apr_socket_recv: Connection reset by peer (104)
    • 参考

    参数说明

    官方文档参考这里。

    ab -c 100 -n 10000 -k -r https://www.baidu.com/
    
    • 1
    • -c:concurrency,每次发送的请求次数,默认一次一个。如:-c 100 表示每次发送100个请求,模拟100人同时访问。
    • -n:requests,本次测试的总请求数。
    • 上面命令的含义:每次发送100个请求,共发送10000个请求。

    示例1:压力测试

    shell> ab -c 100 -n 10000 -k -r https://www.baidu.com/
    This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking www.baidu.com (be patient)
    Completed 1000 requests
    Completed 2000 requests
    Completed 3000 requests
    Completed 4000 requests
    Completed 5000 requests
    Completed 6000 requests
    Completed 7000 requests
    Completed 8000 requests
    Completed 9000 requests
    Completed 10000 requests
    Finished 10000 requests
    
    
    Server Software:        BWS/1.1
    Server Hostname:        www.baidu.com
    Server Port:            443
    SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
    Server Temp Key:        ECDH P-256 256 bits
    TLS Server Name:        www.baidu.com
    
    Document Path:          /
    Document Length:        227 bytes
    
    Concurrency Level:      100
    Time taken for tests:   6.655 seconds
    Complete requests:      10000
    Failed requests:        0
    Keep-Alive requests:    0
    Total transferred:      13929176 bytes
    HTML transferred:       2270000 bytes
    Requests per second:    1502.72 [#/sec] (mean)
    Time per request:       66.546 [ms] (mean)
    Time per request:       0.665 [ms] (mean, across all concurrent requests)
    Transfer rate:          2044.11 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:       36   51   4.4     51     200
    Processing:    12   15   4.6     14     205
    Waiting:       12   14   4.1     13     205
    Total:         54   66   6.1     65     267
    
    Percentage of the requests served within a certain time (ms)
      50%     65
      66%     66
      75%     67
      80%     68
      90%     69
      95%     71
      98%     75
      99%     78
     100%    267 (longest request)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58

    示例2:测试post接口

    ab -c 100 -n 1000 -r -k -p postdata_001_001.txt -T 'application/json'  https://xxx.xxx.xxx/api
    
    • 1
    • postdata_001_001.txt 为post数据文件。post数据文件中的内容与接口所需参数保持一致。

    post数据文件该如何编写?

    可能是这样

    uid=1&data={"username": "admin", "msg":"并发测试","type": "txt", "file": "","time":"2021-12-22
    
    • 1

    也可能是这样

    {
    "address":"124",
    "amount":125
    }
    
    • 1
    • 2
    • 3
    • 4

    如果不能确定是什么样,可以先用接口测试工具测通,从接口测试工具中将post数据导出并保存成post数据文件。以apifox为例:
    在这里插入图片描述

    apr_pollset_poll: The timeout specified has expired (70007)

    加个-k参数

    apr_socket_recv: Connection reset by peer (104)

    加个-r参数

    参考

    http://httpd.apache.org/docs/2.2/programs/ab.html
    Apache Bench(ab 压力测试工具)的安装与使用
    https://www.cnblogs.com/yoyoketang/p/10255100.html

  • 相关阅读:
    PAT 1014 福尔摩斯的约会
    【Flutter】解决报错 Cannot not find minSdk from android/app/build.gradle or android/local.propertiesSpecif
    Shiro【散列算法、过滤器 、Shiro会话、会话管理器、权限表设计】(三)-全面详解(学习总结---从入门到深化)
    Weblogic SSRF 漏洞复现
    使用Python爬虫和C++搭建离线IP库
    redis笔记补充
    [附源码]计算机毕业设计JAVA疫情背景下社区公共卫生服务系统
    APT和Javapoet的精彩联动
    2023下半年软件设计师考试知识点大全思维导图
    《流畅的Python》 读书笔记 231007(第二章第一部分)
  • 原文地址:https://blog.csdn.net/sayyy/article/details/136344477
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号