Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce logger allocations by not using generic CreateLogger #2256

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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