-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e03368f
commit b647975
Showing
13 changed files
with
160 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,55 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"--project", | ||
"${workspaceFolder}/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj" | ||
], | ||
"problemMatcher": "$msCompile" | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"--project", | ||
"${workspaceFolder}/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "build ClientBenchmarkApp", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/Benchmarks/ClientBenchmarkApp/ClientBenchmarkApp.csproj" | ||
], | ||
"problemMatcher": "$msCompile", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace ClientBenchmarkApp; | ||
|
||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Engines; | ||
|
||
using HiveMQtt.Client; | ||
using HiveMQtt.Client.Options; | ||
using HiveMQtt.MQTT5; | ||
using HiveMQtt.MQTT5.ReasonCodes; | ||
using HiveMQtt.MQTT5.Types; | ||
|
||
[SimpleJob(RunStrategy.Monitoring, iterationCount: 10, id: "MonitoringJob")] | ||
public class ClientBenchmarks : IDisposable | ||
{ | ||
private readonly string smallPayload = new string(/*lang=json,strict*/ "{\"interference\": \"1029384\"}"); | ||
|
||
private HiveMQClient client; | ||
|
||
[GlobalSetup] | ||
public async Task SetupAsync() | ||
{ | ||
var options = new HiveMQClientOptions | ||
{ | ||
Host = "127.0.0.1", | ||
Port = 1883, | ||
}; | ||
|
||
this.client = new HiveMQClient(options); | ||
Console.WriteLine($"Connecting to {options.Host} on port {options.Port}..."); | ||
await this.client.ConnectAsync().ConfigureAwait(false); | ||
|
||
if (this.client.IsConnected()) | ||
{ | ||
Console.WriteLine("HiveMQ client connected."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Client failed to connect!"); | ||
} | ||
} | ||
|
||
[GlobalCleanup] | ||
public async Task CleanUpAsync() | ||
{ | ||
Console.WriteLine("Disconnecting from HiveMQ..."); | ||
await this.client.DisconnectAsync().ConfigureAwait(false); | ||
} | ||
|
||
[Benchmark(Description = "Publish a QoS 0 messages to the broker.")] | ||
public async Task PublishQoS0MessageAsync() | ||
{ | ||
await this.client.PublishAsync("benchmarks/PublishQoS0Messages", this.smallPayload).ConfigureAwait(false); | ||
} | ||
|
||
[Benchmark(Description = "Publish a QoS 1 messages to the broker.")] | ||
public async Task PublishQoS1MessageAsync() | ||
{ | ||
await this.client.PublishAsync("benchmarks/PublishQoS1Messages", this.smallPayload, QualityOfService.AtLeastOnceDelivery).ConfigureAwait(false); | ||
} | ||
|
||
[Benchmark(Description = "Publish a QoS 2 messages to the broker.")] | ||
public async Task PublishQoS2MessageAsync() | ||
{ | ||
await this.client.PublishAsync("benchmarks/PublishQoS1Messages", this.smallPayload, QualityOfService.ExactlyOnceDelivery).ConfigureAwait(false); | ||
} | ||
|
||
public void Dispose() => GC.SuppressFinalize(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
<ProjectReference Include="..\..\Source\HiveMQtt\HiveMQtt.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace ClientBenchmarkApp; | ||
|
||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
=> BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Benchmarks | ||
|
||
The benchmarks are built with [BenchmarkDotNet](https://benchmarkdotnet.org) and can be run with: | ||
|
||
`dotnet run ClientBenchmarkApp.csproj -c Release` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters