Skip to content

Commit 5f7c4fc

Browse files
amcaseywtgodbe
authored andcommitted
Address PR feedback
1 parent 966785f commit 5f7c4fc

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,22 @@ internal partial class Http2Connection : IHttp2StreamLifetimeHandler, IHttpHeade
3636
private const string EnhanceYourCalmMaximumCountProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.EnhanceYourCalmCount";
3737
private const string MaximumFlowControlQueueSizeProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.MaxConnectionFlowControlQueueSize";
3838

39-
private static readonly int _enhanceYourCalmMaximumCount = AppContext.GetData(EnhanceYourCalmMaximumCountProperty) is int eycMaxCount
40-
? eycMaxCount
41-
: 10;
39+
private static readonly int _enhanceYourCalmMaximumCount = GetEnhanceYourCalmMaximumCount();
40+
41+
private static int GetEnhanceYourCalmMaximumCount()
42+
{
43+
var data = AppContext.GetData(EnhanceYourCalmMaximumCountProperty);
44+
if (data is int count)
45+
{
46+
return count;
47+
}
48+
if (data is string countStr && int.TryParse(countStr, out var parsed))
49+
{
50+
return parsed;
51+
}
52+
53+
return 20; // Empirically derived
54+
}
4255

4356
// Accumulate _enhanceYourCalmCount over the course of EnhanceYourCalmTickWindowCount ticks.
4457
// This should make bursts less likely to trigger disconnects.
@@ -176,10 +189,10 @@ public Http2Connection(HttpConnectionContext context)
176189
? 4 * http2Limits.MaxStreamsPerConnection
177190
: (int)ConfiguredMaximumFlowControlQueueSize;
178191

179-
if (_maximumFlowControlQueueSize < http2Limits.MaxStreamsPerConnection)
192+
if (IsMaximumFlowControlQueueSizeEnabled && _maximumFlowControlQueueSize < http2Limits.MaxStreamsPerConnection)
180193
{
194+
Log.Http2FlowControlQueueMaximumTooLow(context.ConnectionId, http2Limits.MaxStreamsPerConnection, _maximumFlowControlQueueSize);
181195
_maximumFlowControlQueueSize = http2Limits.MaxStreamsPerConnection;
182-
Log.LogTrace($"The configured maximum flow control queue size {ConfiguredMaximumFlowControlQueueSize} is less than the maximum streams per connection {http2Limits.MaxStreamsPerConnection} - increasing to match.");
183196
}
184197

185198
// Start pool off at a smaller size if the max number of streams is less than the InitialStreamPoolSize

src/Servers/Kestrel/Core/src/Internal/Infrastructure/IKestrelTrace.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ internal interface IKestrelTrace : ILogger
8484

8585
void Http2FlowControlQueueOperationsExceeded(string connectionId, int count);
8686

87+
void Http2FlowControlQueueMaximumTooLow(string connectionId, int expected, int actual);
88+
8789
void InvalidResponseHeaderRemoved();
8890

8991
void Http3ConnectionError(string connectionId, Http3ConnectionErrorException ex);

src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelTrace.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,30 @@ public void Http3GoAwayStreamId(string connectionId, long goAwayStreamId)
395395
Http3GoAwayStreamId(_http3Logger, connectionId, goAwayStreamId);
396396
}
397397

398-
[LoggerMessage(54, LogLevel.Error, @"Connection id ""{ConnectionId}"" aborted since at least ""{Count}"" ENHANCE_YOUR_CALM responses were required per second.", EventName = "Http2TooManyEnhanceYourCalms")]
398+
[LoggerMessage(54, LogLevel.Debug, @"Connection id ""{ConnectionId}"" aborted since at least ""{Count}"" ENHANCE_YOUR_CALM responses were required per second.", EventName = "Http2TooManyEnhanceYourCalms")]
399399
private static partial void Http2TooManyEnhanceYourCalms(ILogger logger, string connectionId, int count);
400400

401401
public void Http2TooManyEnhanceYourCalms(string connectionId, int count)
402402
{
403403
Http2TooManyEnhanceYourCalms(_http2Logger, connectionId, count);
404404
}
405405

406-
[LoggerMessage(55, LogLevel.Error, @"Connection id ""{ConnectionId}"" exceeded the output flow control maximum queue size of ""{Count}"".", EventName = "Http2FlowControlQueueOperationsExceeded")]
406+
[LoggerMessage(55, LogLevel.Debug, @"Connection id ""{ConnectionId}"" exceeded the output flow control maximum queue size of ""{Count}"".", EventName = "Http2FlowControlQueueOperationsExceeded")]
407407
private static partial void Http2FlowControlQueueOperationsExceeded(ILogger logger, string connectionId, int count);
408408

409409
public void Http2FlowControlQueueOperationsExceeded(string connectionId, int count)
410410
{
411411
Http2FlowControlQueueOperationsExceeded(_http3Logger, connectionId, count);
412412
}
413413

414+
[LoggerMessage(56, LogLevel.Debug, @"Connection id ""{ConnectionId}"" configured maximum flow control queue size ""{Actual}"" is less than the maximum streams per connection ""{Expected}"" - increasing to match.", EventName = "Http2FlowControlQueueMaximumTooLow")]
415+
private static partial void Http2FlowControlQueueMaximumTooLow(ILogger logger, string connectionId, int expected, int actual);
416+
417+
public void Http2FlowControlQueueMaximumTooLow(string connectionId, int expected, int actual)
418+
{
419+
Http2FlowControlQueueMaximumTooLow(_http3Logger, connectionId, expected, actual);
420+
}
421+
414422
public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
415423
=> _generalLogger.Log(logLevel, eventId, state, exception, formatter);
416424

src/Servers/Kestrel/perf/Microbenchmarks/Mocks/MockTrace.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void Http2FrameSending(string connectionId, Http2Frame frame) { }
6262
public void Http2TooManyEnhanceYourCalms(string connectionId, int count) { }
6363
public void Http2MaxConcurrentStreamsReached(string connectionId) { }
6464
public void Http2FlowControlQueueOperationsExceeded(string connectionId, int count) { }
65+
public void Http2FlowControlQueueMaximumTooLow(string connectionId, int expected, int actual) { }
6566
public void InvalidResponseHeaderRemoved() { }
6667
public void Http3ConnectionError(string connectionId, Http3ConnectionErrorException ex) { }
6768
public void Http3ConnectionClosing(string connectionId) { }

src/Servers/Kestrel/shared/test/CompositeKestrelTrace.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ public void Http2FlowControlQueueOperationsExceeded(string connectionId, int cou
252252
_trace2.Http2FlowControlQueueOperationsExceeded(connectionId, count);
253253
}
254254

255+
public void Http2FlowControlQueueMaximumTooLow(string connectionId, int expected, int actual)
256+
{
257+
_trace1.Http2FlowControlQueueMaximumTooLow(connectionId, expected, actual);
258+
_trace2.Http2FlowControlQueueMaximumTooLow(connectionId, expected, actual);
259+
}
260+
255261
public void InvalidResponseHeaderRemoved()
256262
{
257263
_trace1.InvalidResponseHeaderRemoved();

0 commit comments

Comments
 (0)