当前位置: 首页 > 科技观察

.NetCrank性能测试介绍

时间:2023-03-13 02:41:58 科技观察

Crank是微软新发布的性能测试框架,集成了多种基准测试工具,如bombardier、wrk等,Crank可以通过统一转换成不同的基准工具命令进行测试配置。请参阅庞巴迪作业实施。安装Crank,运行以下两条命令分别安装Crank的cli(Controller)和Agent。dotnettoolupdateMicrosoft.Crank.Controller--version"0.2.0-*"--globaldotnettoolupdateMicrosoft.Crank.Agent--version"0.2.0-*"--globalrequires.NetSDK5.0环境安装完成后执行命令crank会打印可以配置的参数和介绍如下,也可以在github上查看相关参数介绍。PSC:\Users\Stack\Desktop>crankCrankBenchmarksControllerTheCrankcontrollerorchestratesbenchmarkjobsonCrankagents.Usage:Crank[command][options]选项:-?|-h|--helpShowhelpinformation-c|--configConfigurationfileorurl-s|--scenarioScenariotoexecute-j|--jobNameofjobtodefine--profileProfilename--scriptExecuteanamedscriptavailableintheconfigurationfiles.Canbeusedmultipletimes.-j|--jsonSavestheresultsasjsoninthespecifiedfile.--csvSavestheresultsascsvinthespecifiedfile.--compareAnoptionalfilenametocomparetheresultsto.Canbeusedmultipletimes.--variableVariable--sqlConnectionstringoftheSQLServerDatabasetostoreresultsin--tableTablenameoftheSQLDatabasetostoreresultsin--sessionAlogicalidentifiertogrouprelatedjobs.--descriptionAstringdescribingthejob.-p|--propertySomecustomkey/valuethatwillbeaddedtotheresults,.e.g.--propertyarch=arm--propertyos=linux执行crank-agent,启动基准测试所需的代理服务。github查询相关参数介绍。PSC:\Users\Stack\Desktop>crank-agentHostingenvironment:ProductionContentrootpath: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\Nowlisteningon:http://[::]:5010创建Crank配置文件配置文件参考官方hello.benchmarks.ymlsamplesample文件介绍了bombardier。yml,由于一般环境对githubusercontent.com域名不太友好,可以考虑下载bombardier.yml到本地,导入到本地路径或者直接将文件内容添加到新建的配置文件中。imports:-https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml生产中使用推荐的imports文件,少量配置即可在crank配置文件中基准测试完成,可以根据不同的基准测试工具引入不同的Microsoft.Crank.Jobs.XXX/XXX.yml进行测试。其他测试工具配置文件在https://github.com/dotnet/crank/blob/main/src/Microsoft.Crank.XXX下。变量: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:BombardierClientwaitForExit:truevariables:connections:256#设置连接数warmup:15#SetthetestpreHottimesduration:15#设置测试时间requests:0#设置测试请求实例数rate:0#设置每秒请求频率transport:fasthttp#|http1|http2设置使用golangfasthttp库发送http请求serverScheme:httpserverAddress:localhostserverPort:5000path:bodyFile:#pathorurrlforafiletouseasthebodycontentverb:#GETwhennothingisspecifiedcustomHeaders:[]#listofheaderswiththeformat:':',例如['content-type:application/json']arguments:"-c{{connections}}-w{{warmup}}-d{{duration}}-n{{requests}}--insecure-l{%ifrate!=0%}--rate{{rate}}{%endif%}{%iftransport%}--{{transport}}{%endif%}{{headers[presetHeaders]}}{%forhincustomHeaders%}{%assigns=h|split:':'%}--header\"{{s[0]}}:{{s[1]|strip}}\"{%endfor%}{%ifserverUri==blankorserverUri==empty%}{{serverScheme}}://{{serverAddress}}:{{serverPort}}{{path}}{%else%}{{serverUri}}:{{serverPort}}{{path}}{%endif%}{%ifbodyFile!=blankandbodyFile!=empty%}-f{{bodyFile}}{%endif%}{%ifverb!=blankandverb!=empty%}-m{{verb}}{%endif%}"onConfigure:#-job.timeout=Number(job.variables.duration)+Number(job.variables.warmup)+10;server:source:#指定要测试的项目,本文直接使用本地本地文件夹路径r:.project:crank_demo.csprojreadyStateText:Applicationstarted.#source:指定测试项目的远程仓库地址,通过branchOrCommit#repository指定分支:https://github.com/dotnet/crank#branchOrCommit:main#project:samples/hello/hello.csproj#readyStateText:Applicationstarted.scenarios:#配置benchmark测试场景crank_demo:#定义scheme名称,执行crank命令时指定名称application:job:server#指定测试项目为serverload上面定义:job:bombardier#指定测试工具bombardiervariables:serverPort:5000#配置http服务端口路径:/#配置http服务地址profiles:local:variables:serverAddress:localhostjobs:application:endpoints:-http://localhost:5010load:endpoints:-http://localhost:5010启动Crank-Agent启动agent后,执行crank,会有安装sdk的动作如下[09:29:05.261]Runtime:6.0.0(Current)[09:29:05.262]SDK:6.0.100(当前)[09:29:05.263]ASP.NET:6.0.0(Current)[09:29:05.265]Creatingcustomglobal.json[09:29:05.266]Desktop:6.0.0(Current)[09:29:05.266]InstallingSDK'6.0.100'...所以指定一个dotnethome启动代理时的参数,避免重复安装sdkcrank-agent--dotnethome'C:\ProgramFiles\dotnet'startCrankcrank--config.\demo.benchmarks.yml--scenariocrank_demo--profilelocal--scenariocrank_demo:指定定义的测试场景--profilelocal:setting将结果输出到本地,即控制台输出可以输出到本地json文件(--outputresults.json)或者数据库(--sql[connection-string]--table[table-name])此处通过参数指定结果输出省略压测时的日志输出,直接列出结果。|应用程序|||--------------------|------------||CPUUsage(%)|56||Coresusage(%)|447||WorkingSet(MB)|140||PrivateMemory(MB)|157||BuildTime(ms)|7,232||StartTime(ms)|501||PublishedSize(KB)|91,292||.NETCoreSDKVersion|6.0.100||ASP.NETCoreVersion|6.0.0+ae1a6cb||.NETRuntimeVersion|6.0.0+4822e3c||load|||----------------------|----------------||CPUUsage(%)|46||Coresusage(%)|370||WorkingSet(MB)|29||PrivateMemory(MB)|30||BuildTime(ms)|11,891||StartTime(ms)|226||PublishedSize(KB)|68,228||.NETCoreSDKVersion|3.1.415||ASP.NETCoreVersion|3.1.21+458d974||.NETRuntimeVersion|3.1.21+df8abc0||FirstRequest(ms)|185||Requests|912,005||Badresponses|0||Meanlatency(us)|4,207||Maxlatency(us)|138,999||Requests/sec|60,305||Requests/sec(max)|128,523|更多crankreadme:https://github.com/dotnet/crank/blob/main/docs/README.mdBenchmarkscrank是Benchmarks的重构版本本文示例代码:https://github.com/MayueCif/crank_demo