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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 那只狐狸

线程与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);
        }
    }