Skip to content

Commit 543c363

Browse files
authored
Add HTTP event source logging to gRPC benchmark server (#1773)
1 parent 2c175e0 commit 543c363

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

perf/benchmarkapps/GrpcAspNetCoreServer/GrpcAspNetCoreServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2929
</None>
3030

31+
<Compile Include="..\..\..\test\Shared\HttpEventSourceListener.cs" Link="HttpEventSourceListener.cs" />
3132
<Compile Include="..\Shared\BenchmarkConfigurationHelpers.cs" Link="BenchmarkConfigurationHelpers.cs" />
3233
<Compile Include="..\Shared\BenchmarkServiceImpl.cs" Link="Services\BenchmarkServiceImpl.cs" />
3334
<Compile Include="..\Shared\ServiceProvidersMiddleware.cs" Link="ServiceProvidersMiddleware.cs" />

perf/benchmarkapps/GrpcAspNetCoreServer/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endregion
1818

1919
using System.Reflection;
20+
using System.Runtime;
2021
using Common;
2122
using Microsoft.AspNetCore.Server.Kestrel.Core;
2223
using Microsoft.AspNetCore.Server.Kestrel.Https;
@@ -32,12 +33,19 @@ public static void Main(string[] args)
3233

3334
public static IHostBuilder CreateHostBuilder(string[] args)
3435
{
36+
var runtimeVersion = typeof(object).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "Unknown";
37+
var isServerGC = GCSettings.IsServerGC;
38+
var processorCount = Environment.ProcessorCount;
39+
3540
Console.WriteLine();
3641
Console.WriteLine("ASP.NET Core gRPC Benchmarks");
3742
Console.WriteLine("----------------------------");
3843
Console.WriteLine($"Args: {string.Join(' ', args)}");
3944
Console.WriteLine($"Current directory: {Directory.GetCurrentDirectory()}");
4045
Console.WriteLine($"WebHostBuilder loading from: {typeof(WebHostBuilder).GetTypeInfo().Assembly.Location}");
46+
Console.WriteLine($"NetCoreAppVersion: {runtimeVersion}");
47+
Console.WriteLine($"{nameof(GCSettings.IsServerGC)}: {isServerGC}");
48+
Console.WriteLine($"{nameof(Environment.ProcessorCount)}: {processorCount}");
4149

4250
var config = new ConfigurationBuilder()
4351
.AddJsonFile("hosting.json", optional: true)

perf/benchmarkapps/GrpcAspNetCoreServer/Startup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Text;
2121
using Grpc.Shared;
2222
using Grpc.Testing;
23+
using Grpc.Tests.Shared;
2324
#if NET5_0_OR_GREATER
2425
using Microsoft.AspNetCore.Authentication.Certificate;
2526
#endif
@@ -74,6 +75,12 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat
7475
// Required to notify performance infrastructure that it can begin benchmarks
7576
applicationLifetime.ApplicationStarted.Register(() => Console.WriteLine("Application started."));
7677

78+
var loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
79+
if (loggerFactory.CreateLogger<Startup>().IsEnabled(LogLevel.Trace))
80+
{
81+
_ = new HttpEventSourceListener(loggerFactory);
82+
}
83+
7784
app.UseRouting();
7885

7986
#if NET5_0_OR_GREATER

perf/benchmarkapps/GrpcClient/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ private static ChannelBase CreateChannel(string target)
476476

477477
if (_options.Protocol == "h3")
478478
{
479+
// Stop gRPC channel from creating TCP socket.
480+
httpClientHandler.ConnectCallback = (context, cancellationToken) => throw new InvalidOperationException("Should never be called for H3.");
481+
482+
// Force H3 on all requests.
479483
httpMessageHandler = new Http3DelegatingHandler(httpMessageHandler);
480484
}
481485

0 commit comments

Comments
 (0)