关于后端:2-堪比JMeter的Net压测工具-Crank-进阶篇-认识yml

4次阅读

共计 5078 个字符,预计需要花费 13 分钟才能阅读完成。

1. 前言

入门篇咱们曾经胜利运行 hello.benchmarks.yml 并输入测试后果,本篇咱们就 hello.benchmarks.yml、以及运行的 shell 脚本具体解读下其中的含意

2. 分析 hello.benchmarks.yml

2.1. job

  • 在 hello.benchmarks.yml 中咱们定义了一个新的 job: server,并指定了仓库信息 (近程仓库):
    repository:https://github.com/doddgu/crank.git # 仓库源
    branchOrCommit:sample # 分支
    project: samples/hello/hello.csproj # 我的项目 
  • 并通过 import 导入了 bombardier.yml,其中定义了另外一个 job: bombardier,并指定了仓库信息 (近程仓库):
      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

  • 在 hello.benchmarks.yml 中咱们定义了场景: hello,并为此场景指定了两个工作:

    • 第一个工作名为 application,应用的是我的项目 server
    • 第二个工作名为 load,并指定应用我的项目 bombardier

2.3. variables 变量

  • 在 bombardier.yml 中

    • 定义了全局变量: headers、presetHeaders(预设 header)
    • 定义了局部变量: connections、warmup、duration、requests、rate、transport、serverScheme 等等
  • 在 hello.benchmarks.yml 中为 load 定义了局部变量 serverPort、path

2.4. profiles 配置

  • 在 hello.benchmarks.yml 中咱们

    • 定义了配置 local
    • 并指定了局部变量: serverAddress = localhost
    • 为工作 application、load 指定了部署作业的 endpoint 是 http://localhost:5010(指定执行工作的 Agent 地址)

2.5. arguments 参数

  • 在 bombardier.yml 中与 variables 同级的配置: arguments,此参数是在启动 job 后传递的参数,其中定义的全局参数、局部参数信息也都是为构建残缺的参数做筹备,bombardier 实在的参数信息是:
-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 –config hello.benchmarks.yml –scenario hello –profile local –load.framework net5.0 –application.framework net5.0

    • 其中 crank 是固定的、代表:Crank Controller
    • –config:固定的配置,指执行哪个 yml 配置,每次仅能指定一个 yml 配置
    • –scenario:固定的配置,设置场景是 hello
    • –profile:固定的配置,非必选,可屡次设置,指定以后 Crank 命令申请的配置是 local,应用 local 下配置的所有信息
    • –load.framework: 格局:< 工作名 >.framework,为工作 load 指定 framework 的运行框架版本是 net5.0、–application.framework 同理
  • 革新 hello.benchmarks.yml,因为移除了 profile,所以执行: crank –config hello.yml –scenario hello –load.framework net5.0 –application.framework net5.0 即可

查看 crank 更多文档

5. 疑难

  • 为什么启动 crank 时要减少 –application.framework net5.0?

    • 装置 crank 要求必须有 net5.0 的环境,所以指定 net5.0 不须要再独自装置框架环境
  • 为什么启动 crank 时不指定 framework 时默认是 netcore3.1 呢?

    • 应用记事本关上 hello.csproj、Microsoft.Crank.Jobs.Bombardier.csproj 即可理解
  • scenarios 节点下 application 以及 load 两个节点名称能够更换吗?只能有两个节点?

    • 节点名称不固定,能够更换,也没有限度必须是两个节点,具体多少个节点依据本人的须要来

6. 结尾

通过下面的学习,咱们也曾经齐全的理解了各配置的作用,但对 bombardier.yml 与开源我的项目 bombardier 存在什么样的分割还不分明,以及为什么叫做 bombardier.yml 而不是其余名字,并且是如何实现性能指标的输入,接下来就会讲到 bombardier.yml 与开源我的项目 bombardier 的关系,以及 wrk.yml 与 wrk 的关系

源码地址:https://github.com/doddgu/cra…

开源地址

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

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

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

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

MASA.Blazor:https://github.com/BlazorComp…

如果你对咱们的 MASA Framework 感兴趣,无论是代码奉献、应用、提 Issue,欢送分割咱们

正文完
 0