惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - 那只狐狸

线程与GC 神奇的Task.WaitALl Redis的淘汰策略 C#的Lock可以锁什么? SqlServer高性能批量插入 二叉树 二叉搜索树 AVL树 红黑树 关于GC 线上bug线下很难重现时的一次处理 自动化测试和联调的工具---apifox 事务管理思考 sleep、yield、wait的区别 线程异常 线程 JAVA线程中断 volatile synchronized在线程安全上的区别 jms amqp activemq rabbitmq的区别 servlet不是线程安全的 雪花算法 mysql在海量数据时的处理方案
压测工具k6
那只狐狸 · 2022-11-12 · via 博客园 - 那只狐狸

k6是什么?

js脚本写用例的压测工具,简单、快速、报告详细

使用方法

1. 安装(windows下)

choco install k6

2. 写测试脚本

import {check} from 'k6';
import http from 'k6/http';

export const options = {
    vus:10,
    duration:'1m',
    insecureSkipTLSVerify:true
};

export default ()=>{
    const url = 'http://localhost:7257/weather';
    const payload = JSON.stringify({fullname:"nick"});
    const params = {
        headers:{
            'Content-Type':'application/json'
        }
    }
    
    const res = http.get(url);
    
    check(res,{
        'is status 400':(r)=>r.status === 400,
    });
}

3.脚本所在目录 打开命令行,并执行

4.报告结果

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: .\stresstest.js
     output: -

  scenarios: (100.00%) 1 scenario, 10 max VUs, 1m30s max duration (incl. graceful stop):
           * default: 10 looping VUs for 1m0s (gracefulStop: 30s)


running (1m00.0s), 00/10 VUs, 25657 complete and 0 interrupted iterations
default ✓ [======================================] 10 VUs  1m0s

     ✗ is status 400
      ↳  0% — ✓ 0 / ✗ 25657

     checks.........................: 0.00%  ✓ 0          ✗ 25657
     data_received..................: 4.3 MB 72 kB/s
     data_sent......................: 2.2 MB 37 kB/s
     http_req_blocked...............: avg=4.46µs  min=0s med=0s      max=7.84ms   p(90)=0s       p(95)=0s
     http_req_connecting............: avg=273ns   min=0s med=0s      max=1ms      p(90)=0s       p(95)=0s
     http_req_duration..............: avg=22.99ms min=0s med=21.14ms max=99.26ms  p(90)=34.6ms   p(95)=35.91ms
       { expected_response:true }...: avg=22.99ms min=0s med=21.14ms max=99.26ms  p(90)=34.6ms   p(95)=35.91ms
     http_req_failed................: 0.00%  ✓ 0          ✗ 25657
     http_req_receiving.............: avg=74.07µs min=0s med=0s      max=5.34ms   p(90)=249.16µs p(95)=608.73µs
     http_req_sending...............: avg=11.74µs min=0s med=0s      max=3.24ms   p(90)=0s       p(95)=0s
     http_req_tls_handshaking.......: avg=0s      min=0s med=0s      max=0s       p(90)=0s       p(95)=0s
     http_req_waiting...............: avg=22.9ms  min=0s med=21.03ms max=99.26ms  p(90)=34.5ms   p(95)=35.83ms
     http_reqs......................: 25657  427.448837/s
     iteration_duration.............: avg=23.38ms min=0s med=21.63ms max=111.07ms p(90)=34.98ms  p(95)=36.32ms
     iterations.....................: 25657  427.448837/s
     vus............................: 10     min=10       max=10
     vus_max........................: 10     min=10       max=10

 5. 附被测代码

[HttpGet("weather")]
   [BetterServiceFilter<LoggingFilter>(Order = 1)] 
    public IEnumerable<int> Index()
    {
        using (var _ = _logger.TimedOperation("begin {-1}", nameof(Index)))
        {
            return Enumerable.Range(1, 5);
        }
    }