Skip to content

Commit

Permalink
Add connection logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Aug 5, 2023
1 parent 55813df commit ded95e5
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 99 deletions.
46 changes: 23 additions & 23 deletions GrpcDotNetNamedPipes.PerfTests/GrpcPerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,42 @@ public class GrpcPerformanceTests
{
private const int Timeout = 60_000;

private readonly ITestOutputHelper _testOutputHelper;
private readonly ITestOutputHelper _output;

public GrpcPerformanceTests(ITestOutputHelper testOutputHelper)
public GrpcPerformanceTests(ITestOutputHelper output)
{
_testOutputHelper = testOutputHelper;
_output = output;
}

[Theory(Timeout = Timeout)]
[ClassData(typeof(MultiChannelWithAspNetClassData))]
public async Task ServerStreamingManyMessagesPerformance(ChannelContextFactory factory)
{
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
var stopwatch = Stopwatch.StartNew();
var call = ctx.Client.ServerStreaming(new RequestMessage { Value = 100_000 });
while (await call.ResponseStream.MoveNext())
{
}

stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
[ClassData(typeof(MultiChannelWithAspNetClassData))]
public void UnarySequentialChannelsPerformance(ChannelContextFactory factory)
{
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
var stopwatch = Stopwatch.StartNew();
for (int i = 0; i < 1_000; i++)
{
var client = factory.CreateClient();
var client = factory.CreateClient(_output);
client.SimpleUnary(new RequestMessage());
}

stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
Expand All @@ -67,44 +67,44 @@ public async Task UnaryParallelChannelsPerformance(ChannelContextFactory factory
#if NET8_0_OR_GREATER
if (factory is AspNetPipeContextFactory)
{
_testOutputHelper.WriteLine("Skipped (ASP.NET named pipes fail with too many parallel channels)");
_output.WriteLine("Skipped (ASP.NET named pipes fail with too many parallel channels)");
return;
}
#endif
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
var stopwatch = Stopwatch.StartNew();
var tasks = new Task[1_000];
for (int i = 0; i < tasks.Length; i++)
{
var client = factory.CreateClient();
var client = factory.CreateClient(_output);
tasks[i] = client.SimpleUnaryAsync(new RequestMessage()).ResponseAsync;
}

await Task.WhenAll(tasks);
stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
[ClassData(typeof(MultiChannelWithAspNetClassData))]
public void UnarySequentialCallsPerformance(ChannelContextFactory factory)
{
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
var stopwatch = Stopwatch.StartNew();
for (int i = 0; i < 1_000; i++)
{
ctx.Client.SimpleUnary(new RequestMessage());
}

stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
[ClassData(typeof(MultiChannelWithAspNetClassData))]
public async Task UnaryParallelCallsPerformance(ChannelContextFactory factory)
{
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
var stopwatch = Stopwatch.StartNew();
var tasks = new Task[1_000];
for (int i = 0; i < tasks.Length; i++)
Expand All @@ -114,20 +114,20 @@ public async Task UnaryParallelCallsPerformance(ChannelContextFactory factory)

await Task.WhenAll(tasks);
stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
[ClassData(typeof(MultiChannelWithAspNetClassData))]
public void UnaryLargePayloadPerformance(ChannelContextFactory factory)
{
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
var bytes = new byte[100 * 1024 * 1024];
var byteString = ByteString.CopyFrom(bytes);
var stopwatch = Stopwatch.StartNew();
ctx.Client.SimpleUnary(new RequestMessage { Binary = byteString });
stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
Expand All @@ -136,21 +136,21 @@ public void ChannelColdStartPerformance(ChannelContextFactory factory)
{
// Note: This test needs to be run on its own for accurate cold start measurements.
var stopwatch = Stopwatch.StartNew();
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
ctx.Client.SimpleUnary(new RequestMessage());
stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}

[Theory(Timeout = Timeout)]
[ClassData(typeof(MultiChannelWithAspNetClassData))]
public void ChannelWarmStartPerformance(ChannelContextFactory factory)
{
using var tempChannel = factory.Create();
using var tempChannel = factory.Create(_output);
var stopwatch = Stopwatch.StartNew();
using var ctx = factory.Create();
using var ctx = factory.Create(_output);
ctx.Client.SimpleUnary(new RequestMessage());
stopwatch.Stop();
_testOutputHelper.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
_output.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AspNetHttpContextFactory : ChannelContextFactory
{
private int _port;

public override ChannelContext Create()
public override ChannelContext Create(ITestOutputHelper output)
{
var builder = WebApplication.CreateBuilder();
builder.Services.AddGrpc(opts => opts.MaxReceiveMessageSize = int.MaxValue);
Expand All @@ -54,12 +54,12 @@ public override ChannelContext Create()
return new ChannelContext
{
Impl = new TestServiceImpl(), // TODO: Match instance
Client = CreateClient(),
Client = CreateClient(output),
OnDispose = () => app.StopAsync()
};
}

public override TestService.TestServiceClient CreateClient()
public override TestService.TestServiceClient CreateClient(ITestOutputHelper output)
{
var httpHandler = new HttpClientHandler();
httpHandler.ServerCertificateCustomValidationCallback =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AspNetPipeContextFactory : ChannelContextFactory
{
private string _pipe;

public override ChannelContext Create()
public override ChannelContext Create(ITestOutputHelper output)
{
_pipe = $"pipe/{Guid.NewGuid()}";
var builder = WebApplication.CreateBuilder();
Expand All @@ -48,12 +48,12 @@ public override ChannelContext Create()
return new ChannelContext
{
Impl = new TestServiceImpl(), // TODO: Match instance
Client = CreateClient(),
Client = CreateClient(output),
OnDispose = () => app.StopAsync()
};
}

public override TestService.TestServiceClient CreateClient()
public override TestService.TestServiceClient CreateClient(ITestOutputHelper output)
{
var connectionFactory = new NamedPipesConnectionFactory(_pipe);
var socketsHttpHandler = new SocketsHttpHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AspNetUdsContextFactory : ChannelContextFactory
{
private string _path;

public override ChannelContext Create()
public override ChannelContext Create(ITestOutputHelper output)
{
_path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var builder = WebApplication.CreateBuilder();
Expand All @@ -49,12 +49,12 @@ public override ChannelContext Create()
return new ChannelContext
{
Impl = new TestServiceImpl(), // TODO: Match instance
Client = CreateClient(),
Client = CreateClient(output),
OnDispose = () => app.StopAsync()
};
}

public override TestService.TestServiceClient CreateClient()
public override TestService.TestServiceClient CreateClient(ITestOutputHelper output)
{
var udsEndPoint = new UnixDomainSocketEndPoint(_path);
var connectionFactory = new UnixDomainSocketsConnectionFactory(udsEndPoint);
Expand Down
Loading

0 comments on commit ded95e5

Please sign in to comment.