当前位置: 首页 > news >正文

grafana K6压测

文章目录

    • install and run
    • script.js
      • options
        • 最佳实践
    • report 解析

https://grafana.com/docs/k6/latest/get-started

install and run

  1. install
# mac
brew install k6
  1. 当前目录下生成压测脚本
# create file script.js
k6 new [filename]     # create file ‘script.js’ in the current directory

3 run

k6 run script.js
  1. reports
    默认情况下,k6 将总结结果打印到 stdout 。

script.js

import http from 'k6/http';
import { check, sleep } from 'k6';export const options = {vus: 10,duration: '30s',
};export default function () {const res = http.get('http://test.k6.io');check(res, { 'status was 200': (r) => r.status == 200 });sleep(1);
}

options

https://grafana.com/docs/k6/latest/using-k6/k6-options/reference/

  • vus
    虚拟用户数
  • duration
    持续时间
  • rps
    每秒请求数量

请求总数 = vus * rps * durance(s)

import http from 'k6/http';
import { check, sleep } from 'k6';export const options = {maxRedirects: 4,duration: '300s',vus: 10,rps: 300
};// stages : 逐步提升/降低 
export const options = {stages: [{ target: 200, duration: '30s' },{ target: 0, duration: '30s' },],
};export const options = {stages: [{ duration: '10s', target: 100 },{ duration: '5m', target: 100 },{ duration: '10s', target: 0 },],rps: 100,
};
最佳实践

VUs太大的情况下, 直接启动所有 VUs 会几乎同时发起请求,导致请求的瞬间激增。这样的突发性负载可能会导致系统未能及时响应,进而出现错误。
改为 分阶段增加 VUs , 系统逐步适应增加的负载

report 解析

默认report

         /\      Grafana   /‾‾/  /\  /  \     |\  __   /  /   /  \/    \    | |/ /  /   ‾‾\ /          \   |   (  |  ()  |/ __________ \  |_|\_\  \_____/ execution: localscript: script.jsoutput: -scenarios: (100.00%) 1 scenario, 2000 max VUs, 1m15s max duration (incl. graceful stop):* default: Up to 2000 looping VUs for 45s over 6 stages (gracefulRampDown: 30s, gracefulStop: 30s)✓ status is 200checks.........................: 100.00% 191878 out of 191878data_received..................: 160 MB  3.5 MB/sdata_sent......................: 20 MB   443 kB/shttp_req_blocked...............: avg=5.84µs   min=0s    med=1µs      max=9.49ms  p(90)=4µs      p(95)=7µs     http_req_connecting............: avg=2.71µs   min=0s    med=0s       max=9.43ms  p(90)=0s       p(95)=0s      http_req_duration..............: avg=246.16ms min=383µs med=103.16ms max=6.91s   p(90)=617.17ms p(95)=979.14ms{ expected_response:true }...: avg=246.16ms min=383µs med=103.16ms max=6.91s   p(90)=617.17ms p(95)=979.14mshttp_req_failed................: 0.00%   0 out of 191878http_req_receiving.............: avg=40.53µs  min=5µs   med=18µs     max=65.69ms p(90)=74µs     p(95)=102.14µshttp_req_sending...............: avg=10.06µs  min=1µs   med=3µs      max=53.75ms p(90)=15µs     p(95)=23µs    http_req_tls_handshaking.......: avg=0s       min=0s    med=0s       max=0s      p(90)=0s       p(95)=0s      http_req_waiting...............: avg=246.11ms min=373µs med=103.09ms max=6.91s   p(90)=617.11ms p(95)=979.11mshttp_reqs......................: 191878  4263.707029/siteration_duration.............: avg=246.24ms min=406µs med=103.26ms max=6.91s   p(90)=617.2ms  p(95)=979.24msiterations.....................: 191878  4263.707029/svus............................: 7       min=7                max=1990vus_max........................: 2000    min=2000             max=2000running (0m45.0s), 0000/2000 VUs, 191878 complete and 0 interrupted iterations
default ✓ [======================================] 0000/2000 VUs  45s

总请求量 191878, 持续时间 45.0s
p(95)=979.14ms : 95% 的请求响应时间在 979.14ms 以内

http://www.lryc.cn/news/542742.html

相关文章:

  • Vue的组合式API和选项式API有什么区别
  • ubuntu 安全策略(等保)
  • c/c++蓝桥杯经典编程题100道(22)最短路径问题
  • AI工具集合
  • CSDN 博客:CC++ 内存管理详解
  • 表单制作代码,登录动画背景前端模板
  • 嵌入式项目:STM32刷卡指纹智能门禁系统
  • LeetCode 热题100 141. 环形链表
  • 以绘图(绘制点、直线、圆、椭圆、多段线)为例子 通过设计模式中的命令模式实现
  • 鹏哥c语言数组(初阶数组)
  • 利用go-migrate实现MySQL和ClickHouse的数据库迁移
  • 计算机毕业设计SpringBoot+Vue.js企业客户管理系统(源码+LW文档+PPT+讲解+开题报告)
  • jmeter 如何做移动端的测试 特别是兼容性测试
  • 深度学习技术全景图:从基础架构到工业落地的超级进化指南
  • vllm部署LLM(qwen2.5,llama,deepseek)
  • 基于SpringBoot的“古城景区管理系统”的设计与实现(源码+数据库+文档+PPT)
  • 如何防止 Docker 注入了恶意脚本
  • 使用python接入腾讯云DeepSeek
  • 【MySQL】服务正在启动或停止中,请稍候片刻后再试一次【解决方案】
  • 测试工程师玩转DeepSeek之Prompt
  • 【PyTorch】2024保姆级安装教程-Python-(CPU+GPU详细完整版)-
  • 精选案例展 | 智己汽车—全栈可观测驱动智能化运营与成本优化
  • MySQL 使用 `WHERE` 子句时 `COUNT(*)`、`COUNT(1)` 和 `COUNT(column)` 的区别解析
  • Linux运维——网络管理
  • STM32CUBEIDE FreeRTOS操作教程(十三):task api 任务访问函数
  • Jmeter+Jenkins接口压力测试持续集成
  • 深入浅出ES6:现代JavaScript的基石
  • 实现使用RBF(径向基函数)神经网络模拟二阶电机数学模型中的非线性干扰,以及使用WNN(小波神经网络)预测模型中的非线性函数来抵消迟滞影响的功能
  • 潜水泵,高效排水,守护城市与农田|深圳鼎跃
  • 易基因:RNA甲基化修饰和R-loop的交叉调控:从分子机制到临床意义|深度综述