您好,登錄后才能下訂單哦!
這篇文章主要介紹“.Net性能測(cè)試框架Crank怎么使用”,在日常操作中,相信很多人在.Net性能測(cè)試框架Crank怎么使用問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”.Net性能測(cè)試框架Crank怎么使用”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
Crank 是微軟新出的一個(gè)性能測(cè)試框架,集成了多種基準(zhǔn)測(cè)試工具,如bombardier、wrk等。
Crank通過統(tǒng)一的配置,可以轉(zhuǎn)換成不同基準(zhǔn)測(cè)試工具命令進(jìn)行測(cè)試。
運(yùn)行如下兩個(gè)命令分別安裝Crank
的cli(Controller)
和Agent
。
dotnet tool update Microsoft.Crank.Controller --version "0.2.0-*" --global dotnet tool update Microsoft.Crank.Agent--version "0.2.0-*" --global
需要.Net SDK 5.0環(huán)境
安裝完成后執(zhí)行命令crank
,會(huì)打印出如下可以配置的參數(shù)和介紹,或者github查看相關(guān)參數(shù)介紹。
PS C:\Users\Stack\Desktop> crank Crank Benchmarks Controller The Crank controller orchestrates benchmark jobs on Crank agents. Usage: Crank [command] [options] Options: -?|-h|--help Show help information -c|--config Configuration file or url -s|--scenario Scenario to execute -j|--job Name of job to define --profile Profile name --script Execute a named script available in the configuration files. Can be used multiple times. -j|--json Saves the results as json in the specified file. --csv Saves the results as csv in the specified file. --compare An optional filename to compare the results to. Can be used multiple times. --variable Variable --sql Connection string of the SQL Server Database to store results in --table Table name of the SQL Database to store results in --session A logical identifier to group related jobs. --description A string describing the job. -p|--property Some custom key/value that will be added to the results, .e.g. --property arch=arm --property os=linux
執(zhí)行crank-agent
,啟動(dòng)基準(zhǔn)測(cè)試所需的代理服務(wù)。github查看相關(guān)參數(shù)介紹。
PS C:\Users\Stack\Desktop> crank-agent Hosting environment: Production Content root path: C:\Users\Stack\.dotnet\tools\.store\microsoft.crank.agent\0.2.0-alpha.21567.1\microsoft.crank.agent\0.2.0-alpha.21567.1\tools\net5.0\any\ Now listening on: http://[::]:5010
配置文件參考官方hello.benchmarks.yml示例
示例文件中引入了bombardier.yml
,由于大環(huán)境對(duì)githubusercontent.com域名不太友好,可以考慮將bombardier.yml
下載到本地,imports
引入本地路徑或者直接將文件內(nèi)容加入到新建的配置文件。
imports: -https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml
生產(chǎn)中使用推薦imports文件的方式,crank配置文件中做少量配置就可以完成基準(zhǔn)測(cè)試,并且可以引入不同的Microsoft.Crank.Jobs.XXX/XXX.yml,基于不同的基準(zhǔn)測(cè)試工具進(jìn)行測(cè)試。
其他測(cè)試工具配置文件都在https://github.com/dotnet/crank/blob/main/src/Microsoft.Crank.XXX下。
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 #設(shè)置連接數(shù) warmup: 15 #設(shè)置測(cè)試預(yù)熱次數(shù) duration: 15 #設(shè)置測(cè)試時(shí)間 requests: 0 #設(shè)置測(cè)試請(qǐng)求實(shí)例數(shù) rate: 0 #設(shè)置每秒請(qǐng)求頻率 transport: fasthttp # | http1 | http2 設(shè)置使用golang的fasthttp庫發(fā)送http請(qǐng)求 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; server: source: #指定需要測(cè)試的項(xiàng)目,本文直接使用本地路徑 localFolder: . project: crank_demo.csproj readyStateText: Application started. # source: 指定測(cè)試項(xiàng)目的遠(yuǎn)程倉庫地址,并通過branchOrCommit指定分支 # repository: https://github.com/dotnet/crank # branchOrCommit: main # project: samples/hello/hello.csproj # readyStateText: Application started. scenarios: #配置基準(zhǔn)測(cè)試場(chǎng)景 crank_demo: #定義方案名,執(zhí)行crank命令時(shí)指定該名稱 application: job: server # 指定測(cè)試項(xiàng)目為上面定義的server load: job: bombardier # 指定測(cè)試工具bombardier variables: serverPort: 5000 #配置http服務(wù)端口 path: / #配置http服務(wù)地址 profiles: local: variables: serverAddress: localhost jobs: application: endpoints: - http://localhost:5010 load: endpoints: - http://localhost:5010
啟動(dòng)agent
后執(zhí)行crank
,會(huì)有一個(gè)如下安裝sdk的動(dòng)作
[09:29:05.261] Runtime: 6.0.0 (Current) [09:29:05.262] SDK: 6.0.100 (Current) [09:29:05.263] ASP.NET: 6.0.0 (Current) [09:29:05.265] Creating custom global.json [09:29:05.266] Desktop: 6.0.0 (Current) [09:29:05.266] Installing SDK '6.0.100' ...
所以啟動(dòng)agent
時(shí)多指定一個(gè)dotnethome
參數(shù),避免重復(fù)安裝sdk。
crank-agent --dotnethome 'C:\Program Files\dotnet'
crank --config .\demo.benchmarks.yml --scenario crank_demo --profile local
--scenario crank_demo
: 指定定義的測(cè)試場(chǎng)景
--profile local
:設(shè)置輸出結(jié)果到本地,即控制臺(tái)輸出
可以通過參數(shù)指定結(jié)果輸出到本地json文件(--output results.json )或者數(shù)據(jù)庫(--sql [connection-string] --table [table-name])
這里省略壓測(cè)期間的日志輸出,直接列出結(jié)果。
| application | | | --------------------- | ------------- | | CPU Usage (%) | 56 | | Cores usage (%) | 447 | | Working Set (MB) | 140 | | Private Memory (MB) | 157 | | Build Time (ms) | 7,232 | | Start Time (ms) | 501 | | Published Size (KB) | 91,292 | | .NET Core SDK Version | 6.0.100 | | ASP.NET Core Version | 6.0.0+ae1a6cb | | .NET Runtime Version | 6.0.0+4822e3c | | load | | | --------------------- | -------------- | | CPU Usage (%) | 46 | | Cores usage (%) | 370 | | Working Set (MB) | 29 | | Private Memory (MB) | 30 | | Build Time (ms) | 11,891 | | Start Time (ms) | 226 | | Published Size (KB) | 68,228 | | .NET Core SDK Version | 3.1.415 | | ASP.NET Core Version | 3.1.21+458d974 | | .NET Runtime Version | 3.1.21+df8abc0 | | First Request (ms) | 185 | | Requests | 912,005 | | Bad responses | 0 | | Mean latency (us) | 4,207 | | Max latency (us) | 138,999 | | Requests/sec | 60,305 | | Requests/sec (max) | 128,523 |
到此,關(guān)于“.Net性能測(cè)試框架Crank怎么使用”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。