Skip to content

Commit

Permalink
chore: Benchmark ServerStreaming Scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Oct 30, 2024
1 parent ca024f9 commit 94d34e1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 18 deletions.
5 changes: 3 additions & 2 deletions perf/BenchmarkApp/PerformanceTest.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MagicOnion.Serialization;
using MagicOnion.Serialization.MemoryPack;
using MagicOnion.Serialization.MessagePack;
using PerformanceTest.Client;
using PerformanceTest.Shared;
using PerformanceTest.Shared.Reporting;

Expand Down Expand Up @@ -197,6 +198,7 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
ScenarioType.StreamingHubLargePayload16K => () => new StreamingHubLargePayload16KScenario(),
ScenarioType.StreamingHubLargePayload32K => () => new StreamingHubLargePayload32KScenario(),
ScenarioType.StreamingHubLargePayload64K => () => new StreamingHubLargePayload64KScenario(),
ScenarioType.ServerStreaming => () => new ServerStreamingScenario(),
_ => throw new Exception($"Unknown Scenario: {scenario}"),
};

Expand Down Expand Up @@ -312,8 +314,7 @@ IEnumerable<ScenarioType> GetRunScenarios(ScenarioType scenario)
return scenario switch
{
ScenarioType.All => Enum.GetValues<ScenarioType>().Where(x => x != ScenarioType.All && x != ScenarioType.CI && x != ScenarioType.CIFull),
ScenarioType.CI => Enum.GetValues<ScenarioType>().Where(x => x == ScenarioType.Unary || x == ScenarioType.StreamingHub),
ScenarioType.CIFull => Enum.GetValues<ScenarioType>().Where(x => x == ScenarioType.Unary || x == ScenarioType.StreamingHub || x == ScenarioType.PingpongStreamingHub),
ScenarioType.CI => Enum.GetValues<ScenarioType>().Where(x => x == ScenarioType.Unary || x == ScenarioType.StreamingHub || x == ScenarioType.ServerStreaming),
_ => [scenario],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@
"commandName": "Project",
"commandLineArgs": "-u https://localhost:5000 --protocol h3 -s CI --rounds 3 --channels 28 --streams 70 --clientauth true"
},
"PerformanceTest.Client (PingpongStreamingHub 1x1)": {
"PerformanceTest.Client (ServerStreaming 1x1)": {
"commandName": "Project",
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s PingpongStreamingHub --channels 1 --streams 1"
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s ServerStreaming --channels 1 --streams 1"
},
"PerformanceTest.Client (PingpongStreamingHub 1x28)": {
"PerformanceTest.Client (ServerStreaming 1x28)": {
"commandName": "Project",
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s PingpongStreamingHub --channels 28 --streams 1"
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s ServerStreaming --channels 28 --streams 1"
},
"PerformanceTest.Client (PingpongStreamingHub 70x1)": {
"PerformanceTest.Client (ServerStreaming 70x1)": {
"commandName": "Project",
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s PingpongStreamingHub --channels 1 --streams 70"
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s ServerStreaming --channels 1 --streams 70"
},
"PerformanceTest.Client (PingpongStreamingHub 70x28)": {
"PerformanceTest.Client (ServerStreaming 70x28)": {
"commandName": "Project",
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s PingpongStreamingHub --channels 28 --streams 70"
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s ServerStreaming --channels 28 --streams 70"
},
"PerformanceTest.Client (StreamingHub 1x1)": {
"commandName": "Project",
Expand Down Expand Up @@ -132,9 +132,9 @@
"commandName": "Project",
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s Unary --channels 28 --streams 70"
},
"PerformanceTest.Client (PingpongStreamingHub 1x28, MemoryPack)": {
"PerformanceTest.Client (ServerStreaming 1x28, MemoryPack)": {
"commandName": "Project",
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s PingpongStreamingHub --channels 28 --streams 1 --serialization MemoryPack"
"commandLineArgs": "-u http://localhost:5000 --protocol h2c -s ServerStreaming --channels 28 --streams 1 --serialization MemoryPack"
},
"PerformanceTest.Client (StreamingHub 1x28, MemoryPack)": {
"commandName": "Project",
Expand Down
3 changes: 1 addition & 2 deletions perf/BenchmarkApp/PerformanceTest.Client/ScenarioType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ public enum ScenarioType
StreamingHubLargePayload32K,
StreamingHubLargePayload64K,

PingpongStreamingHub,
PingpongCachedStreamingHub,
ServerStreaming,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Grpc.Net.Client;
using MagicOnion.Client;
using PerformanceTest.Shared;

namespace PerformanceTest.Client;

public class ServerStreamingScenario : IScenario
{
IPerfTestService client = default!;
readonly TimeProvider timeProvider = TimeProvider.System;

public ValueTask PrepareAsync(GrpcChannel channel)
{
this.client = MagicOnionClient.Create<IPerfTestService>(channel);
return ValueTask.CompletedTask;
}

public async ValueTask RunAsync(int connectionId, PerformanceTestRunningContext ctx, CancellationToken cancellationToken)
{
var stream = await client.ServerStreamingAsync();
while(!cancellationToken.IsCancellationRequested)
{
ctx.Increment();
var begin = timeProvider.GetTimestamp();
//_ = stream.ResponseStream.Current;
await stream.ResponseStream.MoveNext(cancellationToken);
ctx.Latency(connectionId, timeProvider.GetElapsedTime(begin));
}
}

public Task CompleteAsync()
{
return Task.CompletedTask;
}
}
13 changes: 13 additions & 0 deletions perf/BenchmarkApp/PerformanceTest.Server/PerfTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@ public UnaryResult<ComplexResponse> UnaryComplexAsync(string arg1, int arg2, int
{
return UnaryResult.FromResult(ComplexResponse.Cached);
}

public async Task<ServerStreamingResult<SimpleResponse>> ServerStreamingAsync()
{
var response = SimpleResponse.Cached;
var stream = GetServerStreamingContext<SimpleResponse>();

while(!stream.ServiceContext.CallContext.CancellationToken.IsCancellationRequested)
{
await stream.WriteAsync(response);
}

return stream.Result();
}
}
8 changes: 4 additions & 4 deletions perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestService.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using MagicOnion;
using MessagePack;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime;
using MemoryPack;

namespace PerformanceTest.Shared;

public interface IPerfTestService : IService<IPerfTestService>
{
// Unary
UnaryResult<Nil> UnaryParameterless();
UnaryResult<string> UnaryArgRefReturnRef(string arg1, int arg2, int arg3);
UnaryResult<string> UnaryArgDynamicArgumentTupleReturnRef(string arg1, int arg2, int arg3, int arg4);
UnaryResult<int> UnaryArgDynamicArgumentTupleReturnValue(string arg1, int arg2, int arg3, int arg4);
UnaryResult<(int StatusCode, byte[] Data)> UnaryLargePayloadAsync(string arg1, int arg2, int arg3, int arg4, byte[] arg5);
UnaryResult<ComplexResponse> UnaryComplexAsync(string arg1, int arg2, int arg3, int arg4);

// ServerStreaming
Task<ServerStreamingResult<SimpleResponse>> ServerStreamingAsync();
}

0 comments on commit 94d34e1

Please sign in to comment.