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:'
