其他分享
首页 > 其他分享> > 2. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml

2. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml

作者:互联网

目录

  1. 堪比JMeter的.Net压测工具 - Crank 入门篇
  2. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml
  3. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识bombardier
  4. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识wrk、wrk2
  5. 堪比JMeter的.Net压测工具 - Crank 实战篇 - 接口以及场景压测
  6. 堪比JMeter的.Net压测工具 - Crank 实战篇 - 收集诊断跟踪信息与如何分析瓶颈
  7. 堪比JMeter的.Net压测工具 - Crank 总结篇 - crank带来了什么

1. 前言

入门篇我们已经成功运行hello.benchmarks.yml并输出测试结果,本篇我们就hello.benchmarks.yml、以及运行的shell脚本详细解读下其中的含义

2. 剖析hello.benchmarks.yml

2.1. job

    repository:https://github.com/doddgu/crank.git # 仓库源
    branchOrCommit:sample # 分支
    project: samples/hello/hello.csproj # 项目
      repository: https://github.com/doddgu/crank.git
      branchOrCommit: sample
      project: src/Microsoft.Crank.Jobs.Bombardier/Microsoft.Crank.Jobs.Bombardier.csproj
      sourceKey: bombardier # 服务器使用它来重用相同的源文件夹。
      noBuild: true # 定义 SourceKey时,指示是否仍应进行构建

2.2. scenarios

2.3. variables 变量

2.4. profiles 配置

2.5. arguments 参数

-c {{connections}} -w {{warmup}} -d {{duration}} -n {{requests}} --insecure -l {% if rate != 0 %} --rate {{ rate }} {% endif %} {% if transport %} --{{ transport}} {% endif %} {{headers[presetHeaders]}} {% for h in customHeaders %}{% assign s = h | split : ':' %}--header \"{{ s[0] }}: {{ s[1] | strip }}\" {% endfor %} {% if serverUri == blank or serverUri == empty %} {{serverScheme}}://{{serverAddress}}:{{serverPort}}{{path}} {% else %} {{serverUri}}:{{serverPort}}{{path}} {% endif %} {% if bodyFile != blank and bodyFile != empty %} -f {{bodyFile}} {% endif %}  {% if verb != blank and verb != empty %} -m {{verb}} {% endif %}

3. 改造hello.benchmarks.yml

改造hello.benchmarks.yml,不考虑重用,最原始的代码如下

variables:
  headers:
    none: ''
    plaintext: '--header "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7" --header "Connection: keep-alive"'
    html: '--header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" --header "Connection: keep-alive"'
    json: '--header "Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7" --header "Connection: keep-alive"'
    connectionclose: '--header "Connection: close"'
  presetHeaders: none

jobs:
  bombardier:
    source:
      repository: https://github.com/dotnet/crank.git
      branchOrCommit: main
      project: src/Microsoft.Crank.Jobs.Bombardier/Microsoft.Crank.Jobs.Bombardier.csproj
      sourceKey: bombardier
      noBuild: true
    readyStateText: Bombardier Client
    waitForExit: true
    variables:
      connections: 256
      warmup: 15
      duration: 15
      requests: 0
      rate: 0
      transport: fasthttp # | http1 | http2
      serverScheme: http
      serverAddress: localhost
      serverPort: 5000
      path: 
      bodyFile: # path or url for a file to use as the body content
      verb: # GET when nothing is specified
      customHeaders: [ ] # list of headers with the format: '<name1>: <value1>', e.g. [ 'content-type: application/json' ]
    arguments: "-c {{connections}} -w {{warmup}} -d {{duration}} -n {{requests}} --insecure -l {% if rate != 0 %} --rate {{ rate }} {% endif %} {% if transport %} --{{ transport}} {% endif %} {{headers[presetHeaders]}} {% for h in customHeaders %}{% assign s = h | split : ':' %}--header \"{{ s[0] }}: {{ s[1] | strip }}\" {% endfor %} {% if serverUri == blank or serverUri == empty %} {{serverScheme}}://{{serverAddress}}:{{serverPort}}{{path}} {% else %} {{serverUri}}:{{serverPort}}{{path}} {% endif %} {% if bodyFile != blank and bodyFile != empty %} -f {{bodyFile}} {% endif %}  {% if verb != blank and verb != empty %} -m {{verb}} {% endif %}"
    onConfigure: 
      # - job.timeout = Number(job.variables.duration) + Number(job.variables.warmup) + 10;    
    endpoints: 
      - http://localhost:5010
  
  server:
    source:
      repository: https://github.com/doddgu/crank
      branchOrCommit: sample
      project: samples/hello/hello.csproj
    readyStateText: Application started.
    endpoints: 
      - http://localhost:5010

scenarios:
  hello:
    application:
      job: server
    load:
      job: bombardier
      variables:
        serverPort: 5000
        path: /

4. 解读crank shell

之前我们通过shell执行:

查看crank更多文档

5. 疑问

6. 结尾

通过上面的学习,我们也已经完全的了解了各配置的作用,但对bombardier.yml与开源项目bombardier存在什么样的联系还不清楚,以及为什么叫做bombardier.yml而不是其他名字,并且是如何实现性能指标的输出,接下来就会讲到bombardier.yml与开源项目bombardier的关系,以及wrk.yml与wrk的关系

源码地址:https://github.com/doddgu/crank/tree/sample

开源地址

MASA.BuildingBlocks:https://github.com/masastack/MASA.BuildingBlocks

MASA.Contrib:https://github.com/masastack/MASA.Contrib

MASA.Utils:https://github.com/masastack/MASA.Utils

MASA.EShop:https://github.com/masalabs/MASA.EShop

MASA.Blazor:https://github.com/BlazorComponent/MASA.Blazor

如果你对我们的 MASA Framework 感兴趣,无论是代码贡献、使用、提 Issue,欢迎联系我们

16373211753064.png

标签:application,堪比,hello,进阶篇,Crank,--,bombardier,yml
来源: https://www.cnblogs.com/doddgu/p/crank-2.html