Skip to content

Commit

Permalink
Merge pull request #791 from Cysharp/vNext
Browse files Browse the repository at this point in the history
MagicOnion 7.0
  • Loading branch information
mayuki authored Jun 17, 2024
2 parents ab77e02 + 02bf1ed commit cff3524
Show file tree
Hide file tree
Showing 272 changed files with 10,770 additions and 2,839 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- vNext
tags:
- "!*" # not a tag push
paths-ignore:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- vNext
tags:
- "!*" # not a tag push
paths-ignore:
Expand All @@ -13,6 +14,7 @@ on:
pull_request:
branches:
- main
- vNext
paths-ignore:
- '**.md'
- .github/**
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>6.1.3</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
Expand Down
8 changes: 7 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<MessagePackVersion>2.5.129</MessagePackVersion>
<MicrosoftCodeAnalysisVersion>4.3.1</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisVersionUnity>3.9.0</MicrosoftCodeAnalysisVersionUnity>
<MulticasterVersion>0.1.11</MulticasterVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
<PackageVersion Include="Grpc" Version="$(GrpcCCoreVersion)" />
<PackageVersion Include="Grpc.AspNetCore" Version="$(GrpcVersion)" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="$(GrpcVersion)" />
Expand All @@ -20,7 +22,11 @@
<PackageVersion Include="MessagePack" Version="$(MessagePackVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics" Version="8.0.0" />
<PackageVersion Include="Multicaster" Version="$(MulticasterVersion)" />
<PackageVersion Include="Multicaster.Distributed.Redis" Version="$(MulticasterVersion)" />
<PackageVersion Include="Multicaster.Distributed.Nats" Version="$(MulticasterVersion)" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<PackageVersion Include="PolySharp" Version="1.13.2" />
Expand All @@ -46,4 +52,4 @@
<PackageVersion Include="JetBrains.Profiler.Api" Version="1.4.3" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
</ItemGroup>
</Project>
</Project>
17 changes: 17 additions & 0 deletions MagicOnion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicOnion.Serialization.Me
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicOnion.Abstractions.Tests", "tests\MagicOnion.Abstractions.Tests\MagicOnion.Abstractions.Tests.csproj", "{D340EFB8-128A-4B49-A47A-F00A905D10AC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatApp.Console", "samples\ChatApp\ChatApp.Console\ChatApp.Console.csproj", "{AF21B7BD-7399-41B7-B0D4-08ACDC952E50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microbenchmark", "Microbenchmark", "{F1FD52DD-E8A4-4CF0-A857-1A22443A0324}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microbenchmark.Client", "perf\Microbenchmark\Microbenchmark.Client\Microbenchmark.Client.csproj", "{CDBB141A-E0A9-4FD8-8260-1FB1E95C4E80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -266,6 +272,14 @@ Global
{D340EFB8-128A-4B49-A47A-F00A905D10AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D340EFB8-128A-4B49-A47A-F00A905D10AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D340EFB8-128A-4B49-A47A-F00A905D10AC}.Release|Any CPU.Build.0 = Release|Any CPU
{AF21B7BD-7399-41B7-B0D4-08ACDC952E50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF21B7BD-7399-41B7-B0D4-08ACDC952E50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF21B7BD-7399-41B7-B0D4-08ACDC952E50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF21B7BD-7399-41B7-B0D4-08ACDC952E50}.Release|Any CPU.Build.0 = Release|Any CPU
{CDBB141A-E0A9-4FD8-8260-1FB1E95C4E80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDBB141A-E0A9-4FD8-8260-1FB1E95C4E80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDBB141A-E0A9-4FD8-8260-1FB1E95C4E80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDBB141A-E0A9-4FD8-8260-1FB1E95C4E80}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -312,6 +326,9 @@ Global
{2996029B-D329-499F-8525-69614A820135} = {1987061F-8970-4018-8D58-6932961C9EB4}
{701E193F-587D-4C20-8970-6E215B0634F8} = {7ACC27E8-8FBE-4807-B91F-B89AF3CFF7E0}
{D340EFB8-128A-4B49-A47A-F00A905D10AC} = {7ACC27E8-8FBE-4807-B91F-B89AF3CFF7E0}
{AF21B7BD-7399-41B7-B0D4-08ACDC952E50} = {FEE2B9AB-A1D0-41BA-A172-FC95935542DF}
{F1FD52DD-E8A4-4CF0-A857-1A22443A0324} = {A0CED9FB-5B18-4EE3-859F-CE3A6F90A82A}
{CDBB141A-E0A9-4FD8-8260-1FB1E95C4E80} = {F1FD52DD-E8A4-4CF0-A857-1A22443A0324}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D5B2E7E3-B727-40A1-BE68-7BAC9B9DE2FE}
Expand Down
2 changes: 1 addition & 1 deletion perf/BenchmarkApp/PerformanceTest.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async Task Main(
// Create a control channel
using var channelControl = GrpcChannel.ForAddress(config.Url);
var controlServiceClient = MagicOnionClient.Create<IPerfTestControlService>(channelControl);
controlServiceClient.SetMemoryProfilerCollectAllocations(true);
await controlServiceClient.SetMemoryProfilerCollectAllocationsAsync(true);

ServerInformation serverInfo;
WriteLog("Gathering the server information...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public UnaryResult<ServerInformation> GetServerInformationAsync()
ApplicationInformation.Current.IsAttached));
}

public UnaryResult SetMemoryProfilerCollectAllocations(bool enable)
public UnaryResult SetMemoryProfilerCollectAllocationsAsync(bool enable)
{
MemoryProfiler.CollectAllocations(enable);
return UnaryResult.CompletedResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IPerfTestControlService : IService<IPerfTestControlService>
{
UnaryResult<ServerInformation> GetServerInformationAsync();

UnaryResult SetMemoryProfilerCollectAllocations(bool enable);
UnaryResult SetMemoryProfilerCollectAllocationsAsync(bool enable);
UnaryResult CreateMemoryProfilerSnapshotAsync(string name);
}

Expand Down
1 change: 1 addition & 0 deletions perf/Microbenchmark/Microbenchmark.Client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BenchmarkDotNet.Artifacts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Runtime.CompilerServices;
using System.Threading.Channels;
using Grpc.Core;

namespace Microbenchmark.Client;

class ChannelAsyncStreamReader<T> : IAsyncStreamReader<T>
{
readonly ChannelReader<T> reader;

public T Current { get; private set; } = default!;

public ChannelAsyncStreamReader(Channel<T> channel)
{
reader = channel.Reader;
}

public Task<bool> MoveNext(CancellationToken cancellationToken)
{
return MoveNextCore(cancellationToken).AsTask();
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
async ValueTask<bool> MoveNextCore(CancellationToken cancellationToken)
{
if (await reader.WaitToReadAsync())
{
if (reader.TryRead(out var item))
{
Current = item;
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Threading.Channels;
using Grpc.Core;

namespace Microbenchmark.Client;

class ChannelClientStreamWriter<T> : IClientStreamWriter<T>
{
readonly ChannelWriter<T> writer;

public WriteOptions? WriteOptions { get; set; }

public ChannelClientStreamWriter(ChannelWriter<T> writer)
{
this.writer = writer;
}

public Task CompleteAsync()
{
writer.Complete();
return Task.CompletedTask;
}

public Task WriteAsync(T message)
{
writer.TryWrite(message);
return Task.CompletedTask;
}
}
82 changes: 82 additions & 0 deletions perf/Microbenchmark/Microbenchmark.Client/HubMethodBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using BenchmarkDotNet.Attributes;
using MagicOnion.Client.DynamicClient;

namespace Microbenchmark.Client;

[MemoryDiagnoser, RankColumn]
[ShortRunJob]
public class HubMethodBenchmarks
{
readonly StreamingHubClientTestHelper<ITestHub, ITestHubReceiver> helper;
readonly Task responseTask;
readonly ITestHub client;

static ReadOnlySpan<byte> IntResponse => [0xcd, 0x30, 0x39 /* 12345 (int) */];
static ReadOnlySpan<byte> NilResponse => [0xc0 /* Nil */];
static ReadOnlySpan<byte> StringResponse => [0xa6, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21 /* "Hello!" (string) */];

public HubMethodBenchmarks()
{
this.helper = new StreamingHubClientTestHelper<ITestHub, ITestHubReceiver>(new TestHubReceiver(), DynamicStreamingHubClientFactoryProvider.Instance);
this.responseTask = Task.Run(async () =>
{
while (true)
{
var req = await helper.ReadRequestNoDeserializeAsync();
if (req.MethodId is -2087943100 or 1273874383)
{
// Parameter_Zero_Return_ValueType, Parameter_Many_Return_ValueType
helper.WriteResponse(req.MessageId, req.MethodId, IntResponse);
}
else if (req.MethodId is -1841486598)
{
// ValueTask_Parameter_Zero_NoReturn
helper.WriteResponse(req.MessageId, req.MethodId, NilResponse);
}
else if (req.MethodId is -440496944 or -1110031569)
{
// Parameter_Zero_Return_RefType, Parameter_Many_Return_RefType
helper.WriteResponse(req.MessageId, req.MethodId, StringResponse);
}
}
});
this.client = helper.ConnectAsync().GetAwaiter().GetResult();
}

[Benchmark]
public Task Void_Parameter_Zero_NoReturn()
{
client.Void_Parameter_Zero_NoReturn();
return Task.CompletedTask;
}

[Benchmark]
public async Task ValueTask_Parameter_Zero_NoReturn()
{
await client.ValueTask_Parameter_Zero_NoReturn();
}

[Benchmark]
public async Task Parameter_Zero_Return_ValueType()
{
var value = await client.Parameter_Zero_Return_ValueType();
}

[Benchmark]
public async Task Parameter_Many_Return_ValueType()
{
var value = await client.Parameter_Many_Return_ValueType("Hello", 12345, true);
}

[Benchmark]
public async Task Parameter_Zero_Return_RefType()
{
var value = await client.Parameter_Zero_Return_RefType();
}

[Benchmark]
public async Task Parameter_Many_Return_RefType()
{
var value = await client.Parameter_Many_Return_RefType("Hello", 12345, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using BenchmarkDotNet.Attributes;
using MagicOnion.Client.DynamicClient;

namespace Microbenchmark.Client;

[MemoryDiagnoser, RankColumn]
[ShortRunJob]
public class HubReceiverBroadcastBenchmarks
{
StreamingHubClientTestHelper<ITestHub, ITestHubReceiver> helper = default!;
ITestHub client = default!;
TestHubReceiver receiver = default!;

static ReadOnlySpan<byte> BroadcastMessage_Parameter_Zero => [0x92, 0xce, 0x76, 0xe4, 0x37, 0x1b /* 1994667803 */, 0xc0 /* Nil */]; // [MethodId(int), SerializedArgument]
static ReadOnlySpan<byte> BroadcastMessage_Parameter_Many => [0x92, 0xce, 0x4c, 0xb8, 0x83, 0xca /* 1287160778 */, 0x93, 0xa6, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xcd, 0x30, 0x39, 0xc3 /* [ "Hello", 12345, true ] */]; // [MethodId(int), SerializedArgument]

void Setup()
{
this.receiver = new TestHubReceiver();
this.helper = new StreamingHubClientTestHelper<ITestHub, ITestHubReceiver>(receiver, DynamicStreamingHubClientFactoryProvider.Instance);
this.client = helper.ConnectAsync().GetAwaiter().GetResult();
}

[GlobalSetup(Targets = [nameof(Parameter_Zero), nameof(Parameter_Many)])]
public void UnsetSynchronizationContext()
{
SynchronizationContext.SetSynchronizationContext(null);
Setup();
}

[GlobalSetup(Targets = [nameof(Parameter_Zero_With_SynchronizationContext), nameof(Parameter_Many_With_SynchronizationContext)])]
public void SetSynchronizationContext()
{
SynchronizationContext.SetSynchronizationContext(new MySynchronizationContext());
Setup();
}

[Benchmark]
public void Parameter_Zero()
{
helper.WriteResponseRaw(BroadcastMessage_Parameter_Zero);
receiver.Received.Wait();
}

[Benchmark]
public void Parameter_Many()
{
helper.WriteResponseRaw(BroadcastMessage_Parameter_Many);
receiver.Received.Wait();
}

[Benchmark]
public void Parameter_Zero_With_SynchronizationContext()
{
helper.WriteResponseRaw(BroadcastMessage_Parameter_Zero);
receiver.Received.Wait();
}

[Benchmark]
public void Parameter_Many_With_SynchronizationContext()
{
helper.WriteResponseRaw(BroadcastMessage_Parameter_Many);
receiver.Received.Wait();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\src\MagicOnion\opensource.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\MagicOnion.Client\MagicOnion.Client.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit cff3524

Please sign in to comment.