码农知识堂 - 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

  • 相关阅读:
    《算法通关村—进制转换问题处理模板》
    基于ssm框架的高校班级管理系统设计与实现
    计算机毕业设计ssm基于J2EE的山西旅游网站的设计与实现iiqmx系统+程序+源码+lw+远程部署
    【机器学习基础】机器学习的基本术语
    敦煌考古,招不到人了?看数字化技术如何破圈
    PHP反射:探索、修改和实例化
    asp.net老年大学信息VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio计算机毕业设计
    ptmalloc源码分析 - malloc/free函数的实战篇(12)
    同一个浏览器不同窗口登录不同账号,窗口切换时,页面刷新账号变更为最后一次登录的账号
    springboot-scanBasePackages包扫描
  • 原文地址:https://blog.csdn.net/sayyy/article/details/136344477
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号