2. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml
1. 前言
入門篇我們已經(jīng)成功運(yùn)行hello.benchmarks.yml并輸出測(cè)試結(jié)果,本篇我們就hello.benchmarks.yml、以及運(yùn)行的shell腳本詳細(xì)解讀下其中的含義
2. 剖析hello.benchmarks.yml
2.1. job
在hello.benchmarks.yml中我們定義了一個(gè)新的job: server,并指定了倉(cāng)庫(kù)信息 ( 遠(yuǎn)程倉(cāng)庫(kù) ):
并通過import導(dǎo)入了bombardier.yml,其中定義了另外一個(gè)job: bombardier,并指定了倉(cāng)庫(kù)信息 ( 遠(yuǎn)程倉(cāng)庫(kù) ):
2.2. scenarios
在hello.benchmarks.yml中我們定義了場(chǎng)景: hello,并為此場(chǎng)景指定了兩個(gè)任務(wù):
第一個(gè)任務(wù)名為application,使用的是項(xiàng)目server
第二個(gè)任務(wù)名為load,并指定使用項(xiàng)目bombardier
2.3. variables 變量
在bombardier.yml中
定義了全局變量: headers、presetHeaders(預(yù)設(shè)header)
定義了局部變量: connections、warmup、duration、requests、rate、transport、serverScheme等等
在hello.benchmarks.yml中為load定義了局部變量serverPort、path
2.4. profiles 配置
在hello.benchmarks.yml中我們
定義了配置local
并指定了局部變量: serverAddress = localhost
為任務(wù)application、load指定了部署作業(yè)的endpoint 是 http://localhost:5010 (指定執(zhí)行任務(wù)的Agent地址)
2.5. arguments 參數(shù)
在bombardier.yml中與variables同級(jí)的配置: arguments,此參數(shù)是在啟動(dòng)job后傳遞的參數(shù),其中定義的全局參數(shù)、局部參數(shù)信息也都是為構(gòu)建完整的參數(shù)做準(zhǔn)備,bombardier真實(shí)的參數(shù)信息是:
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: nonejobs:bombardier:source:repository: https://github.com/dotnet/crank.gitbranchOrCommit: mainproject: src/Microsoft.Crank.Jobs.Bombardier/Microsoft.Crank.Jobs.Bombardier.csprojsourceKey: bombardiernoBuild: truereadyStateText: Bombardier ClientwaitForExit: truevariables:connections: 256warmup: 15duration: 15requests: 0rate: 0transport: fasthttp # | http1 | http2serverScheme: httpserverAddress: localhostserverPort: 5000path: bodyFile: # path or url for a file to use as the body contentverb: # GET when nothing is specifiedcustomHeaders: [ ] # 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:5010server:source:repository: https://github.com/doddgu/crankbranchOrCommit: sampleproject: samples/hello/hello.csprojreadyStateText: Application started.endpoints: - http://localhost:5010scenarios:hello:application:job: serverload:job: bombardiervariables:serverPort: 5000path: /4. 解讀crank shell
之前我們通過shell執(zhí)行:
crank --config hello.benchmarks.yml --scenario hello --profile local --load.framework net5.0 --application.framework net5.0
其中crank 是固定的、代表:Crank Controller
--config:固定的配置,指執(zhí)行哪個(gè)yml配置,每次僅能指定一個(gè)yml配置
--scenario:固定的配置,設(shè)置場(chǎng)景是hello
--profile:固定的配置,非必選,可多次設(shè)置,指定當(dāng)前Crank命令申請(qǐng)的配置是local,使用local下配置的所有信息
--load.framework: 格式:<任務(wù)名>.framework,為任務(wù)load指定framework的運(yùn)行框架版本是net5.0、--application.framework同理
改造hello.benchmarks.yml,因?yàn)橐瞥藀rofile,所以執(zhí)行: crank --config hello.yml --scenario hello --load.framework net5.0 --application.framework net5.0 即可
查看crank更多文檔
5. 疑問
為什么啟動(dòng)crank時(shí)要增加--application.framework net5.0?
安裝crank要求必須有net5.0的環(huán)境,所以指定net5.0不需要再單獨(dú)安裝框架環(huán)境
為什么啟動(dòng)crank時(shí)不指定framework時(shí)默認(rèn)是netcore3.1呢?
使用記事本打開hello.csproj、Microsoft.Crank.Jobs.Bombardier.csproj 即可了解
scenarios節(jié)點(diǎn)下application以及l(fā)oad兩個(gè)節(jié)點(diǎn)名稱可以更換嗎?只能有兩個(gè)節(jié)點(diǎn)?
節(jié)點(diǎn)名稱不固定,可以更換,也沒有限制必須是兩個(gè)節(jié)點(diǎn),具體多少個(gè)節(jié)點(diǎn)根據(jù)自己的需要來
6. 結(jié)尾
通過上面的學(xué)習(xí),我們也已經(jīng)完全的了解了各配置的作用,但對(duì)bombardier.yml與開源項(xiàng)目bombardier存在什么樣的聯(lián)系還不清楚,以及為什么叫做bombardier.yml而不是其他名字,并且是如何實(shí)現(xiàn)性能指標(biāo)的輸出,接下來就會(huì)講到bombardier.yml與開源項(xiàng)目bombardier的關(guān)系,以及wrk.yml與wrk的關(guān)系
源碼地址: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
如果你對(duì)我們的 MASA Framework 感興趣,無論是代碼貢獻(xiàn)、使用、提 Issue,歡迎聯(lián)系我們
總結(jié)
以上是生活随笔為你收集整理的2. 堪比JMeter的.Net压测工具 - Crank 进阶篇 - 认识yml的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何理解 ListT和 Dictiona
- 下一篇: Avalonia跨平台入门第四篇之Pop