.Net Crank性能测试入门
Crank 是微软新出的一个性能测试框架,集成了多种基准测试工具,如bombardier、wrk等。
Crank通过统一的配置,可以转换成不同基准测试工具命令进行测试。可参考Bombardier Job实现。
安装Crank
运行如下两个命令分别安装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环境
安装完成后执行命令crank,会打印出如下可以配置的参数和介绍,或者github查看相关参数介绍。
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
执行crank-agent,启动基准测试所需的代理服务。github查看相关参数介绍。
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
创建Crank配置文件
配置文件参考官方hello.benchmarks.yml示例
示例文件中引入了bombardier.yml,由于大环境对githubusercontent.com域名不太友好,可以考虑将bombardier.yml下载到本地,imports引入本地路径或者直接将文件内容加入到新建的配置文件。
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下。
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 设置使用golang的fasthttp库发送http请求
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: #指定需要测试的项目,本文直接使用本地路径
localFolder: .
project: crank_demo.csproj
readyStateText: Application started.
# source: 指定测试项目的远程仓库地址,并通过branchOrCommit指定分支
# repository: https://github.com/dotnet/crank
# branchOrCommit: main
# project: samples/hello/hello.csproj
# readyStateText: Application started.
scenarios: #配置基准测试场景
crank_demo: #定义方案名,执行crank命令时指定该名称
application:
job: server # 指定测试项目为上面定义的server
load:
job: bombardier # 指定测试工具bombardier
variables:
serverPort: 5000 #配置http服务端口
path: / #配置http服务地址
profiles:
local:
variables:
serverAddress: localhost
jobs:
application:
endpoints:
- http://localhost:5010
load:
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 (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' ...
所以启动agent时多指定一个dotnethome参数,避免重复安装sdk。
crank-agent --dotnethome 'C:\Program Files\dotnet'
启动Crank
crank --config .\demo.benchmarks.yml --scenario crank_demo --profile local
--scenario crank_demo: 指定定义的测试场景
--profile local :设置输出结果到本地,即控制台输出
可以通过参数指定结果输出到本地json文件(--output results.json )或者数据库(--sql [connection-string] --table [table-name])
结果输出
这里省略压测期间的日志输出,直接列出结果。
| 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 |
更多内容参考:
crank readme
Benchmarks crank为Benchmarks重构版本
.Net Crank性能测试入门的更多相关文章
- Jmeter性能测试入门(链接收藏)
Jmeter性能测试入门: http://www.cnblogs.com/TankXiao/p/4045439.html
- 【转载】Jmeter 性能测试入门
[转载]Jmeter性能测试 入门 Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率. 熟练使用Jmeter后, 能用Jmete ...
- Jmeter性能测试 入门--转载
转载: Jmeter性能测试 入门 Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率. 熟练使用Jmeter后, 能用Jmete ...
- Jmeter Web 性能测试入门 (六):Jmeter 解析 response 并传递 value
解析response中的内容,并把获取到的value传递到后续的request中,常用的方法就是在想要解析response的request上添加后置处理器 本章介绍两种常用的组件 BeanShell ...
- Jmeter Web 性能测试入门 (五):Jmeter 参数化 Request
用来参数化的常用方法: 添加配置元件:用户定义的变量 使用函数助手 添加配置元件:CSV Data Set Config 添加前置处理器:BeanShell PreProcessor 添加配置元件:用 ...
- Jmeter Web 性能测试入门 (四):一个小实例带你学会 Jmeter 脚本编写
测试场景: 模拟并发100个user,在TesterHome 站内搜索VV00CC 添加线程组 添加HTTP信息头管理器 添加HTTP Sampler 填写HTTP Sampler中的信息 添加监听器 ...
- Jmeter Web 性能测试入门 (三):Jmeter 常用组件说明
线程组:用来设置并发的数量和模式.是用来模拟用户并发的组件.JMeter 的每个任务都是用线程来处理的. 线程数:要并发的请求数量. Ramp-Up Period: 在多次时间内把这些并发的请求发送完 ...
- Jmeter Web 性能测试入门 (二):Fiddler 抓取 http/https 请求
jmeter自带了拦截request的功能,并且也有对应的tool:badboy 可以用.但由于我经常做移动端的项目,个人还是习惯用fiddler来收集request. 官网下载并安装Fiddler ...
- Jmeter Web 性能测试入门 (七):Performance 测试中踩过 Jmeter 的坑
脚本运行的过程中,大量request抛error,但没有地方能够查看request是因为什么error的. 原因:Jmeter默认禁掉了运行过程中每个request的具体response信息收集,只保 ...
随机推荐
- 【UE4 C++ 基础知识】<15> 智能指针 TSharedPtr、UniquePtr、TWeakPtr、TSharedRef
基本概念 UE4 对 UObject 对象提供垃圾回收 UE4 对原生对象不提供垃圾回收,需要手动进行清理 方式 malloc / free new / delete new与malloc的区别在于, ...
- Coursera Deep Learning笔记 深度卷积网络
参考 1. Why look at case studies 介绍几个典型的CNN案例: LeNet-5 AlexNet VGG Residual Network(ResNet): 特点是可以构建很深 ...
- 【二食堂】Beta - Scrum Meeting 9
Scrum Meeting 9 例会时间:5.24 20:00~20:20 进度情况 组员 当前进度 今日任务 李健 1. 文本导入.保存部分未完成issue 2. 知识图谱导出的前端issue3. ...
- GitHub Universe 2021|MS Reactor 邀你共聚年度盛会
GitHub Universe 2021 将于2021年10月27-28日(PDT)在线直播,MS Reactor 将与 CSDN 合作进行转播,与你一同观看这场全球开发者盛会. 关于 GitHub ...
- numpy中的nan和常用方法
1.数组的拼接 import numpy as np t1 = np.array([[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]]) t2 = np.array([ ...
- AXI协议中的模棱两可的含义的解释(Cachable和Bufferable)
转载:https://blog.csdn.net/hit_shaoqi/article/details/53243173 Cachable和Bufferable 一个Master发出一个读写的requ ...
- Python ImportError: No module named '_tkinter', please install the python3-tk package
ImportError: No module named '_tkinter', please install the python3-tk package 这个问题的原因是使用的python3环境内 ...
- Oracle 扩容表空间
system用户登陆oracle https://blog.csdn.net/zyingpei/article/details/88870693 首先查看表空间对应的数据文件位置以及大小 select ...
- Linux 启动/关闭 oracle 数据库
1.启动 1.1 启动监听 :lsnrctl start 1.2 启动数据库:sqlplus /nolog conn /as sysdba(或者两句一起:sqlplus sys/ as sysd ...
- 理解前端blob和ArrayBuffer,前端接受文件损坏的问题
1 downloadTemplate().then(res =>{ 2 3 const data = res.data 4 const url = window.URL.createObject ...