Skip to content

Commit

Permalink
Reduce logger allocations by not using generic CreateLogger (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Aug 26, 2023
1 parent 3db1683 commit 6429ae2
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/DnsResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public DnsResolver(Uri address, int defaultPort, ILoggerFactory loggerFactory, T
_dnsAddress = addressParsed.Host;
_port = addressParsed.Port == -1 ? defaultPort : addressParsed.Port;
_refreshInterval = refreshInterval;
_logger = loggerFactory.CreateLogger<DnsResolver>();
_logger = loggerFactory.CreateLogger(typeof(DnsResolver));
}

protected override void OnStarted()
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Balancer/Internal/BalancerHttpHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -45,7 +45,7 @@ public BalancerHttpHandler(HttpMessageHandler innerHandler, ConnectionManager ma
: base(innerHandler)
{
_manager = manager;
_logger = manager.LoggerFactory.CreateLogger<BalancerHttpHandler>();
_logger = manager.LoggerFactory.CreateLogger(typeof(BalancerHttpHandler));
}

internal static bool IsSocketsHttpHandlerSetup(SocketsHttpHandler socketsHttpHandler)
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/Internal/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal ConnectionManager(
_resolverStartedTcs = new TaskCompletionSource<object?>(TaskCreationOptions.RunContinuationsAsynchronously);
_channelId = _channelIdProvider.GetNextChannelId();

Logger = loggerFactory.CreateLogger<ConnectionManager>();
Logger = loggerFactory.CreateLogger(typeof(ConnectionManager));
LoggerFactory = loggerFactory;
BackoffPolicyFactory = backoffPolicyFactory;
_subchannels = new List<Subchannel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SocketConnectivitySubchannelTransport(
ILoggerFactory loggerFactory,
Func<Socket, DnsEndPoint, CancellationToken, ValueTask>? socketConnect)
{
_logger = loggerFactory.CreateLogger<SocketConnectivitySubchannelTransport>();
_logger = loggerFactory.CreateLogger(typeof(SocketConnectivitySubchannelTransport));
_subchannel = subchannel;
_socketPingInterval = socketPingInterval;
ConnectTimeout = connectTimeout;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/PickFirstBalancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal sealed class PickFirstBalancer : LoadBalancer
public PickFirstBalancer(IChannelControlHelper controller, ILoggerFactory loggerFactory)
{
_controller = controller;
_logger = loggerFactory.CreateLogger<PickFirstBalancer>();
_logger = loggerFactory.CreateLogger(typeof(PickFirstBalancer));
}

private void ResolverError(Status status)
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Balancer/PollingResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected PollingResolver(ILoggerFactory loggerFactory, IBackoffPolicyFactory? b
{
ArgumentNullThrowHelper.ThrowIfNull(loggerFactory);

_logger = loggerFactory.CreateLogger<PollingResolver>();
_logger = loggerFactory.CreateLogger(typeof(PollingResolver));
_backoffPolicyFactory = backoffPolicyFactory;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/GrpcChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal GrpcChannel(Uri address, GrpcChannelOptions channelOptions) : base(addr
OperatingSystem = channelOptions.ResolveService<IOperatingSystem>(Internal.OperatingSystem.Instance);
RandomGenerator = channelOptions.ResolveService<IRandomGenerator>(new RandomGenerator());
Debugger = channelOptions.ResolveService<IDebugger>(new CachedDebugger());
Logger = LoggerFactory.CreateLogger<GrpcChannel>();
Logger = LoggerFactory.CreateLogger(typeof(GrpcChannel));

#if SUPPORT_LOAD_BALANCING
InitialReconnectBackoff = channelOptions.InitialReconnectBackoff;
Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Net.Client/Internal/Retry/ChannelRetryThrottling.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -26,7 +26,7 @@ internal class ChannelRetryThrottling
private readonly object _lock = new object();
private readonly double _tokenRatio;
private readonly int _maxTokens;
private readonly ILogger<ChannelRetryThrottling> _logger;
private readonly ILogger _logger;

private double _tokenCount;
private readonly double _tokenThreshold;
Expand All @@ -41,7 +41,7 @@ public ChannelRetryThrottling(int maxTokens, double tokenRatio, ILoggerFactory l
_maxTokens = maxTokens;
_tokenCount = maxTokens;
_tokenThreshold = _tokenCount / 2;
_logger = loggerFactory.CreateLogger<ChannelRetryThrottling>();
_logger = loggerFactory.CreateLogger(typeof(ChannelRetryThrottling));
}

public bool IsRetryThrottlingActive()
Expand Down

0 comments on commit 6429ae2

Please sign in to comment.