diff --git a/perf/BenchmarkApp/PerformanceTest.Client/Program.cs b/perf/BenchmarkApp/PerformanceTest.Client/Program.cs index 7fcb0fc32..1c3024c63 100644 --- a/perf/BenchmarkApp/PerformanceTest.Client/Program.cs +++ b/perf/BenchmarkApp/PerformanceTest.Client/Program.cs @@ -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; @@ -197,6 +198,7 @@ async Task 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}"), }; @@ -312,8 +314,7 @@ IEnumerable GetRunScenarios(ScenarioType scenario) return scenario switch { ScenarioType.All => Enum.GetValues().Where(x => x != ScenarioType.All && x != ScenarioType.CI && x != ScenarioType.CIFull), - ScenarioType.CI => Enum.GetValues().Where(x => x == ScenarioType.Unary || x == ScenarioType.StreamingHub), - ScenarioType.CIFull => Enum.GetValues().Where(x => x == ScenarioType.Unary || x == ScenarioType.StreamingHub || x == ScenarioType.PingpongStreamingHub), + ScenarioType.CI => Enum.GetValues().Where(x => x == ScenarioType.Unary || x == ScenarioType.StreamingHub || x == ScenarioType.ServerStreaming), _ => [scenario], }; } diff --git a/perf/BenchmarkApp/PerformanceTest.Client/Properties/launchSettings.json b/perf/BenchmarkApp/PerformanceTest.Client/Properties/launchSettings.json index d9316a1c7..eca05a01c 100644 --- a/perf/BenchmarkApp/PerformanceTest.Client/Properties/launchSettings.json +++ b/perf/BenchmarkApp/PerformanceTest.Client/Properties/launchSettings.json @@ -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", @@ -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", diff --git a/perf/BenchmarkApp/PerformanceTest.Client/ScenarioType.cs b/perf/BenchmarkApp/PerformanceTest.Client/ScenarioType.cs index a6c435aba..d8553fa2d 100644 --- a/perf/BenchmarkApp/PerformanceTest.Client/ScenarioType.cs +++ b/perf/BenchmarkApp/PerformanceTest.Client/ScenarioType.cs @@ -26,6 +26,5 @@ public enum ScenarioType StreamingHubLargePayload32K, StreamingHubLargePayload64K, - PingpongStreamingHub, - PingpongCachedStreamingHub, + ServerStreaming, } diff --git a/perf/BenchmarkApp/PerformanceTest.Client/ServerStreamingScenario.cs b/perf/BenchmarkApp/PerformanceTest.Client/ServerStreamingScenario.cs new file mode 100644 index 000000000..d645980b0 --- /dev/null +++ b/perf/BenchmarkApp/PerformanceTest.Client/ServerStreamingScenario.cs @@ -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(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; + } +} diff --git a/perf/BenchmarkApp/PerformanceTest.Server/PerfTestService.cs b/perf/BenchmarkApp/PerformanceTest.Server/PerfTestService.cs index 4617de1f4..c75e3c563 100644 --- a/perf/BenchmarkApp/PerformanceTest.Server/PerfTestService.cs +++ b/perf/BenchmarkApp/PerformanceTest.Server/PerfTestService.cs @@ -57,4 +57,17 @@ public UnaryResult UnaryComplexAsync(string arg1, int arg2, int { return UnaryResult.FromResult(ComplexResponse.Cached); } + + public async Task> ServerStreamingAsync() + { + var response = SimpleResponse.Cached; + var stream = GetServerStreamingContext(); + + while(!stream.ServiceContext.CallContext.CancellationToken.IsCancellationRequested) + { + await stream.WriteAsync(response); + } + + return stream.Result(); + } } diff --git a/perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestService.cs b/perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestService.cs index 596b2acc2..a56530903 100644 --- a/perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestService.cs +++ b/perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestService.cs @@ -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 { + // Unary UnaryResult UnaryParameterless(); UnaryResult UnaryArgRefReturnRef(string arg1, int arg2, int arg3); UnaryResult UnaryArgDynamicArgumentTupleReturnRef(string arg1, int arg2, int arg3, int arg4); UnaryResult 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 UnaryComplexAsync(string arg1, int arg2, int arg3, int arg4); + + // ServerStreaming + Task> ServerStreamingAsync(); }