This is an automated email from the ASF dual-hosted git repository.
aaronai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/master by this push:
new 0cdffebe Polish the example of ProducerBenchmark
0cdffebe is described below
commit 0cdffebe610af1d86c9685412524e27d1351f1b7
Author: Aaron Ai <[email protected]>
AuthorDate: Wed Mar 8 18:45:35 2023 +0800
Polish the example of ProducerBenchmark
---
csharp/examples/ProducerBenchmark.cs | 33 ++++++--
.../rocketmq-client-csharp.csproj | 99 +++++++++-------------
2 files changed, 66 insertions(+), 66 deletions(-)
diff --git a/csharp/examples/ProducerBenchmark.cs
b/csharp/examples/ProducerBenchmark.cs
index fc8d3b98..7e2679aa 100644
--- a/csharp/examples/ProducerBenchmark.cs
+++ b/csharp/examples/ProducerBenchmark.cs
@@ -16,7 +16,7 @@
*/
using System;
-using System.Collections.Generic;
+using System.Collections.Concurrent;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -30,8 +30,10 @@ namespace examples
private static readonly Logger Logger =
MqLogManager.Instance.GetCurrentClassLogger();
private static readonly SemaphoreSlim Semaphore = new(0);
- private const int TpsLimit = 1;
- private static long _counter = 0;
+ private const int TpsLimit = 300;
+ private static long _successCounter;
+ private static long _failureCounter;
+ private static readonly BlockingCollection<Task<ISendReceipt>> Tasks =
new();
private static void DoStats()
{
@@ -48,10 +50,27 @@ namespace examples
{
while (true)
{
- Logger.Info($"Send {Interlocked.Exchange(ref _counter, 0)}
messages successfully.");
+ Logger.Info($"{Interlocked.Exchange(ref _successCounter,
0)} success, " +
+ $"{Interlocked.Exchange(ref _failureCounter,
0)} failure.");
await Task.Delay(TimeSpan.FromSeconds(1));
}
});
+
+ Task.Run(async () =>
+ {
+ foreach (var task in Tasks.GetConsumingEnumerable())
+ {
+ try
+ {
+ await task;
+ Interlocked.Increment(ref _successCounter);
+ }
+ catch (Exception)
+ {
+ Interlocked.Increment(ref _failureCounter);
+ }
+ }
+ });
}
internal static async Task QuickStart()
@@ -88,16 +107,12 @@ namespace examples
.Build();
DoStats();
- var tasks = new List<Task>();
while (true)
{
await Semaphore.WaitAsync();
- Interlocked.Increment(ref _counter);
var task = producer.Send(message);
- tasks.Add(task);
+ Tasks.Add(task);
}
-
- Task.WhenAll(tasks).Wait();
}
}
}
\ No newline at end of file
diff --git a/csharp/rocketmq-client-csharp/rocketmq-client-csharp.csproj
b/csharp/rocketmq-client-csharp/rocketmq-client-csharp.csproj
index 754cd133..bff3801b 100644
--- a/csharp/rocketmq-client-csharp/rocketmq-client-csharp.csproj
+++ b/csharp/rocketmq-client-csharp/rocketmq-client-csharp.csproj
@@ -1,62 +1,47 @@
<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <PackageId>RocketMQ.Client</PackageId>
+ <PackageVersion>0.0.11-SNAPSHOT</PackageVersion>
+ <Version>$(PackageVersion)</Version>
- <PropertyGroup>
- <PackageId>RocketMQ.Client</PackageId>
- <!-- Please keep the same with PackageVersion -->
- <Version>0.0.9-SNAPSHOT</Version>
+ <Authors>RocketMQ Authors</Authors>
+ <Company>Apache Software Foundation</Company>
+ <TargetFramework>net5.0</TargetFramework>
+ <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
+ <RootNamespace>Org.Apache.Rocketmq</RootNamespace>
+ <PackageReadmeFile>README.md</PackageReadmeFile>
+ <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+ <Description>.NET Client for Apache RocketMQ</Description>
+
<PackageProjectUrl>https://github.com/apache/rocketmq-clients</PackageProjectUrl>
+
<RepositoryUrl>https://github.com/apache/rocketmq-clients</RepositoryUrl>
+ <PackageIcon>logo.png</PackageIcon>
+ </PropertyGroup>
- <Authors>RocketMQ Authors</Authors>
- <Company>Apache Software Foundation</Company>
- <TargetFramework>net5.0</TargetFramework>
- <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
- <RootNamespace>Org.Apache.Rocketmq</RootNamespace>
- <PackageReadmeFile>README.md</PackageReadmeFile>
- <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
- <Description>.NET Client for Apache RocketMQ</Description>
-
<PackageProjectUrl>https://github.com/apache/rocketmq-clients</PackageProjectUrl>
- <RepositoryUrl>https://github.com/apache/rocketmq-clients</RepositoryUrl>
- <!-- Please keep the same with Version -->
- <PackageVersion>0.0.9-SNAPSHOT</PackageVersion>
- <PackageIcon>logo.png</PackageIcon>
- </PropertyGroup>
-
- <ItemGroup>
- <None Include="..\README.md" Pack="true" PackagePath="\" />
- <PackageReference Include="Crc32.NET" Version="1.2.0" />
- <PackageReference Include="Google.Protobuf" Version="3.19.4" />
- <PackageReference Include="Grpc.Net.Client" Version="2.43.0" />
- <PackageReference Include="Grpc.Tools" Version="2.43.0">
- <IncludeAssets>runtime; build; native; contentfiles; analyzers;
buildtransitive</IncludeAssets>
- <PrivateAssets>all</PrivateAssets>
- </PackageReference>
- <PackageReference Include="NLog" Version="4.7.13" />
- <PackageReference Include="OpenTelemetry" Version="1.3.1" />
- <PackageReference Include="OpenTelemetry.Api" Version="1.3.1" />
- <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol"
Version="1.3.1" />
-
- <Protobuf Include="Protos\apache\rocketmq\v2\definition.proto"
ProtoRoot="Protos" GrpcServices="Client" />
- <Protobuf Include="Protos\google\rpc\code.proto" ProtoRoot="Protos"
GrpcServices="Client" />
- <Protobuf Include="Protos\google\rpc\error_details.proto"
ProtoRoot="Protos" GrpcServices="Client" />
- <Protobuf Include="Protos\google\rpc\status.proto" ProtoRoot="Protos"
GrpcServices="Client" />
- <Protobuf Include="Protos\apache\rocketmq\v2\service.proto"
ProtoRoot="Protos" GrpcServices="Client">
- <Link>Protos\apache\rocketmq\v2\definition.proto</Link>
- <Link>Protos\google\rpc\status.proto</Link>
- <Link>Protos\google\rpc\error_details.proto</Link>
- </Protobuf>
- <None Update="logo.png">
- <Pack>True</Pack>
- <PackagePath></PackagePath>
- </None>
- </ItemGroup>
-
- <ItemGroup>
- <None Update="rocketmq-client-csharp.nlog">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- </ItemGroup>
-
- <ItemGroup>
- <Compile Remove="ClientManagerFactory.cs" />
- </ItemGroup>
+ <ItemGroup>
+ <None Include="..\README.md" Pack="true" PackagePath="\"/>
+ <PackageReference Include="Crc32.NET" Version="1.2.0"/>
+ <PackageReference Include="Google.Protobuf" Version="3.19.4"/>
+ <PackageReference Include="Grpc.Net.Client" Version="2.43.0"/>
+ <PackageReference Include="Grpc.Tools" Version="2.43.0">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers;
buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ <PackageReference Include="NLog" Version="4.7.13"/>
+ <PackageReference Include="OpenTelemetry" Version="1.3.1"/>
+ <PackageReference Include="OpenTelemetry.Api" Version="1.3.1"/>
+ <PackageReference
Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.3.1"/>
+ <Protobuf Include="Protos\apache\rocketmq\v2\definition.proto"
ProtoRoot="Protos" GrpcServices="Client"/>
+ <Protobuf Include="Protos\google\rpc\code.proto" ProtoRoot="Protos"
GrpcServices="Client"/>
+ <Protobuf Include="Protos\google\rpc\error_details.proto"
ProtoRoot="Protos" GrpcServices="Client"/>
+ <Protobuf Include="Protos\google\rpc\status.proto" ProtoRoot="Protos"
GrpcServices="Client"/>
+ <Protobuf Include="Protos\apache\rocketmq\v2\service.proto"
ProtoRoot="Protos" GrpcServices="Client">
+ <Link>Protos\apache\rocketmq\v2\definition.proto</Link>
+ <Link>Protos\google\rpc\status.proto</Link>
+ <Link>Protos\google\rpc\error_details.proto</Link>
+ </Protobuf>
+ <None Update="logo.png" PackagePath="">
+ <Pack>True</Pack>
+ </None>
+ </ItemGroup>
</Project>