Skip to content

Commit

Permalink
Add StreamingHubComplex
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Jan 16, 2023
1 parent 1f764cf commit 50c602c
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 107 deletions.
1 change: 1 addition & 0 deletions perf/BenchmarkApp/PerformanceTest.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async Task<PerformanceResult> RunScenarioAsync(ScenarioType scenario, ScenarioCo
ScenarioType.UnaryLargePayload32K => () => new UnaryLargePayload32KScenario(),
ScenarioType.UnaryLargePayload64K => () => new UnaryLargePayload64KScenario(),
ScenarioType.StreamingHub => () => new StreamingHubScenario(),
ScenarioType.StreamingHubComplex => () => new StreamingHubComplexScenario(),
ScenarioType.StreamingHubLargePayload1K => () => new StreamingHubLargePayload1KScenario(),
ScenarioType.StreamingHubLargePayload2K => () => new StreamingHubLargePayload2KScenario(),
ScenarioType.StreamingHubLargePayload4K => () => new StreamingHubLargePayload4KScenario(),
Expand Down
3 changes: 2 additions & 1 deletion perf/BenchmarkApp/PerformanceTest.Client/ScenarioType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public enum ScenarioType
UnaryLargePayload64K,

StreamingHub,
StreamingHubComplex,
StreamingHubLargePayload1K,
StreamingHubLargePayload2K,
StreamingHubLargePayload4K,
StreamingHubLargePayload8K,
StreamingHubLargePayload16K,
StreamingHubLargePayload32K,
StreamingHubLargePayload64K,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async ValueTask RunAsync(PerformanceTestRunningContext ctx, CancellationT

while (!cancellationToken.IsCancellationRequested)
{
_ = await client.CallMethodLargePayloadAsync("Foo", 123, data);
_ = await client.CallMethodLargePayloadAsync("FooBarBaz🚀こんにちは世界", 123, 4567, 891011, data);
ctx.Increment();
}
}
Expand Down Expand Up @@ -69,4 +69,4 @@ public class StreamingHubLargePayload64KScenario : StreamingHubLargePayloadScena
{
public StreamingHubLargePayload64KScenario() : base(1024 * 64)
{}
}
}
23 changes: 21 additions & 2 deletions perf/BenchmarkApp/PerformanceTest.Client/StreamingHubScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,27 @@ public async ValueTask RunAsync(PerformanceTestRunningContext ctx, CancellationT
{
while (!cancellationToken.IsCancellationRequested)
{
await client.CallMethodAsync("Foo", 123);
await client.CallMethodAsync("FooBarBaz🚀こんにちは世界", 123, 4567, 891011);
ctx.Increment();
}
}
}
}

public class StreamingHubComplexScenario : IScenario, IPerfTestHubReceiver
{
IPerfTestHub client = default!;

public async ValueTask PrepareAsync(GrpcChannel channel)
{
this.client = await StreamingHubClient.ConnectAsync<IPerfTestHub, IPerfTestHubReceiver>(channel, this);
}

public async ValueTask RunAsync(PerformanceTestRunningContext ctx, CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
await client.CallMethodComplexAsync("FooBarBaz🚀こんにちは世界", 123, 4567, 891011);
ctx.Increment();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async ValueTask RunAsync(PerformanceTestRunningContext ctx, CancellationT

while (!cancellationToken.IsCancellationRequested)
{
_ = await client.UnaryLargePayloadAsync("Foo", 123, data);
_ = await client.UnaryLargePayloadAsync("FooBarBaz🚀こんにちは世界", 123, 4567, 891011, data);
ctx.Increment();
}
}
Expand Down Expand Up @@ -70,4 +70,4 @@ public class UnaryLargePayload64KScenario : UnaryLargePayloadScenarioBase
{
public UnaryLargePayload64KScenario() : base(1024 * 64)
{}
}
}
6 changes: 3 additions & 3 deletions perf/BenchmarkApp/PerformanceTest.Client/UnaryScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async ValueTask RunAsync(PerformanceTestRunningContext ctx, CancellationT
{
while (!cancellationToken.IsCancellationRequested)
{
await client.UnaryArgDynamicArgumentTupleReturnValue("Foo", 123);
await client.UnaryArgDynamicArgumentTupleReturnValue("FooBarBaz🚀こんにちは世界", 123, 4567, 891011);
ctx.Increment();
}
}
Expand All @@ -36,8 +36,8 @@ public async ValueTask RunAsync(PerformanceTestRunningContext ctx, CancellationT
{
while (!cancellationToken.IsCancellationRequested)
{
await client.UnaryComplexAsync("Foo", 1234567);
await client.UnaryComplexAsync("FooBarBaz🚀こんにちは世界", 123, 4567, 891011);
ctx.Increment();
}
}
}
}
13 changes: 9 additions & 4 deletions perf/BenchmarkApp/PerformanceTest.Server/PerfTestHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ namespace PerformanceTest.Server;

public class PerfTestHub : StreamingHubBase<IPerfTestHub, IPerfTestHubReceiver>, IPerfTestHub
{
public Task<int> CallMethodAsync(string arg1, int arg2)
public Task<int> CallMethodAsync(string arg1, int arg2, int arg3, int arg4)
{
return Task.FromResult(0);
}

public Task<(int StatusCode, byte[] Data)> CallMethodLargePayloadAsync(string arg1, int arg2, byte[] arg3)
public Task<ComplexResponse> CallMethodComplexAsync(string arg1, int arg2, int arg3, int arg4)
{
return Task.FromResult((123, arg3));
return Task.FromResult(ComplexResponse.Cached);
}
}

public Task<(int StatusCode, byte[] Data)> CallMethodLargePayloadAsync(string arg1, int arg2, int arg3, int arg4, byte[] arg5)
{
return Task.FromResult((123, arg5));
}
}
12 changes: 6 additions & 6 deletions perf/BenchmarkApp/PerformanceTest.Server/PerfTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ public UnaryResult<Nil> UnaryParameterless()
return new UnaryResult<Nil>(Nil.Default);
}

public UnaryResult<string> UnaryArgRefReturnRef(string arg1)
public UnaryResult<string> UnaryArgRefReturnRef(string arg1, int arg2, int arg3)
{
return new UnaryResult<string>(arg1);
}

public UnaryResult<string> UnaryArgDynamicArgumentTupleReturnRef(string arg1, int arg2)
public UnaryResult<string> UnaryArgDynamicArgumentTupleReturnRef(string arg1, int arg2, int arg3, int arg4)
{
return new UnaryResult<string>(arg1 + arg2);
}

public UnaryResult<int> UnaryArgDynamicArgumentTupleReturnValue(string arg1, int arg2)
public UnaryResult<int> UnaryArgDynamicArgumentTupleReturnValue(string arg1, int arg2, int arg3, int arg4)
{
return new UnaryResult<int>(arg2);
}

public UnaryResult<(int StatusCode, byte[] Data)> UnaryLargePayloadAsync(string arg1, int arg2, byte[] arg3)
public UnaryResult<(int StatusCode, byte[] Data)> UnaryLargePayloadAsync(string arg1, int arg2, int arg3, int arg4, byte[] arg5)
{
return UnaryResult.FromResult((123, arg3));
return UnaryResult.FromResult((123, arg5));
}

public UnaryResult<ComplexResponse> UnaryComplexAsync(string arg1, int arg2)
public UnaryResult<ComplexResponse> UnaryComplexAsync(string arg1, int arg2, int arg3, int arg4)
{
return UnaryResult.FromResult(ComplexResponse.Cached);
}
Expand Down
88 changes: 88 additions & 0 deletions perf/BenchmarkApp/PerformanceTest.Shared/ComplexResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using MemoryPack;
using MessagePack;

namespace PerformanceTest.Shared;

[MessagePackObject]
[MemoryPackable]
public partial class ComplexResponse
{
public static ComplexResponse Cached { get; } = new ComplexResponse
{
Value1 = true,
Value2 = 1234567,
Value3 = new InnerObject1
{
Value1 = 987654321,
Value2 = "FooBarBaz🚀こんにちは世界",
Value3 = 1234567890123,
Value4 = true,
Value5 = 123456789,
Value6 = 0,
Value7 = 20,
Value8 = 256,
Value9 = DateTimeOffset.Now,
},
Value4 = new InnerObject2[]
{
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
new InnerObject2 { Value1 = 123456789, Value2 = 123, Value3 = 4567, Value4 = 89101112 },
},
};

[Key(0)]
public bool Value1 { get; set; }
[Key(1)]
public int Value2 { get; set; }
[Key(2)]
public InnerObject1 Value3 { get; set; } = default!;
[Key(3)]
public IReadOnlyList<InnerObject2> Value4 { get; set; } = default!;
}

[MessagePackObject]
[MemoryPackable]
public partial class InnerObject1
{
[Key(0)]
public int Value1 { get; set; }
[Key(1)]
public string Value2 { get; set; } = default!;
[Key(2)]
public long Value3 { get; set; }
[Key(3)]
public bool Value4 { get; set; }
[Key(4)]
public int Value5 { get; set; }
[Key(5)]
public int Value6 { get; set; }
[Key(6)]
public int Value7 { get; set; }
[Key(7)]
public int Value8 { get; set; }
[Key(8)]
public DateTimeOffset Value9 { get; set; }
}

[MessagePackObject]
[MemoryPackable]
public partial struct InnerObject2
{
[Key(0)]
public long Value1 { get; set; }
[Key(1)]
public int Value2 { get; set; }
[Key(2)]
public int Value3 { get; set; }
[Key(3)]
public int Value4 { get; set; }
}
5 changes: 3 additions & 2 deletions perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace PerformanceTest.Shared
{
public interface IPerfTestHub : IStreamingHub<IPerfTestHub, IPerfTestHubReceiver>
{
Task<int> CallMethodAsync(string arg1, int arg2);
Task<(int StatusCode, byte[] Data)> CallMethodLargePayloadAsync(string arg1, int arg2, byte[] arg3);
Task<int> CallMethodAsync(string arg1, int arg2, int arg3, int arg4);
Task<ComplexResponse> CallMethodComplexAsync(string arg1, int arg2, int arg3, int arg4);
Task<(int StatusCode, byte[] Data)> CallMethodLargePayloadAsync(string arg1, int arg2, int arg3, int arg4, byte[] arg5);
}

public interface IPerfTestHubReceiver
Expand Down
90 changes: 5 additions & 85 deletions perf/BenchmarkApp/PerformanceTest.Shared/IPerfTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public interface IPerfTestService : IService<IPerfTestService>
{
UnaryResult<ServerInformation> GetServerInformationAsync();
UnaryResult<Nil> UnaryParameterless();
UnaryResult<string> UnaryArgRefReturnRef(string arg1);
UnaryResult<string> UnaryArgDynamicArgumentTupleReturnRef(string arg1, int arg2);
UnaryResult<int> UnaryArgDynamicArgumentTupleReturnValue(string arg1, int arg2);
UnaryResult<(int StatusCode, byte[] Data)> UnaryLargePayloadAsync(string arg1, int arg2, byte[] arg3);
UnaryResult<ComplexResponse> UnaryComplexAsync(string arg1, int arg2);
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);
}

[MessagePackObject(true)]
Expand Down Expand Up @@ -53,83 +53,3 @@ public ServerInformation(string machineName, string? magicOnionVersion, string?
IsAttached = isAttached;
}
}

[MessagePackObject]
[MemoryPackable]
public partial class ComplexResponse
{
public static ComplexResponse Cached { get; } = new ComplexResponse
{
Value1 = true,
Value2 = 1234567,
Value3 = new InnerObject1
{
Value1 = 987654321,
Value2 = "FooBarBazQux",
Value3 = 1234567890123,
Value4 = true,
Value5 = 123456789,
Value6 = 0,
Value7 = 20,
Value8 = 256,
Value9 = DateTimeOffset.Now,
},
Value4 = new InnerObject2[]
{
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
new InnerObject2 { Value1 = 123456789, Value2 = 123 },
},
};

[Key(0)]
public bool Value1 { get; set; }
[Key(1)]
public int Value2 { get; set; }
[Key(2)]
public InnerObject1 Value3 { get; set; } = default!;
[Key(3)]
public IReadOnlyList<InnerObject2> Value4 { get; set; } = default!;
}

[MessagePackObject]
[MemoryPackable]
public partial class InnerObject1
{
[Key(0)]
public int Value1 { get; set; }
[Key(1)]
public string Value2 { get; set; } = default!;
[Key(2)]
public long Value3 { get; set; }
[Key(3)]
public bool Value4 { get; set; }
[Key(4)]
public int Value5 { get; set; }
[Key(5)]
public int Value6 { get; set; }
[Key(6)]
public int Value7 { get; set; }
[Key(7)]
public int Value8 { get; set; }
[Key(8)]
public DateTimeOffset Value9 { get; set; }
}

[MessagePackObject]
[MemoryPackable]
public partial class InnerObject2
{
[Key(0)]
public long Value1 { get; set; }
[Key(1)]
public int Value2 { get; set; }
}

0 comments on commit 50c602c

Please sign in to comment.