Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
amcasey authored and wtgodbe committed Oct 18, 2023
1 parent 5f7c4fc commit 4a5b77e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ internal partial class Http2Connection : IHttp2StreamLifetimeHandler, IHttpHeade
private const PseudoHeaderFields _mandatoryRequestPseudoHeaderFields =
PseudoHeaderFields.Method | PseudoHeaderFields.Path | PseudoHeaderFields.Scheme;

private const string EnhanceYourCalmMaximumCountProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.EnhanceYourCalmCount";
private const string MaximumEnhanceYourCalmCountProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.MaxEnhanceYourCalmCount";
private const string MaximumFlowControlQueueSizeProperty = "Microsoft.AspNetCore.Server.Kestrel.Http2.MaxConnectionFlowControlQueueSize";

private static readonly int _enhanceYourCalmMaximumCount = GetEnhanceYourCalmMaximumCount();
private static readonly int _enhanceYourCalmMaximumCount = GetMaximumEnhanceYourCalmCount();

private static int GetEnhanceYourCalmMaximumCount()
private static int GetMaximumEnhanceYourCalmCount()
{
var data = AppContext.GetData(EnhanceYourCalmMaximumCountProperty);
var data = AppContext.GetData(MaximumEnhanceYourCalmCountProperty);
if (data is int count)
{
return count;
Expand Down Expand Up @@ -186,7 +186,7 @@ public Http2Connection(HttpConnectionContext context)
_serverSettings.InitialWindowSize = (uint)http2Limits.InitialStreamWindowSize;

_maximumFlowControlQueueSize = ConfiguredMaximumFlowControlQueueSize is null
? 4 * http2Limits.MaxStreamsPerConnection
? 4 * http2Limits.MaxStreamsPerConnection // 4 is a magic number to give us some padding above the expected maximum size
: (int)ConfiguredMaximumFlowControlQueueSize;

if (IsMaximumFlowControlQueueSizeEnabled && _maximumFlowControlQueueSize < http2Limits.MaxStreamsPerConnection)
Expand Down Expand Up @@ -1224,6 +1224,8 @@ private void AbortStream(int streamId, IOException error)
void IRequestProcessor.Tick(DateTimeOffset now)
{
Input.CancelPendingRead();
// We count EYCs over a window of a given length to avoid flagging short-lived bursts.
// At the end of each window, reset the count.
if (IsEnhanceYourCalmEnabled && ++_tickCount % EnhanceYourCalmTickWindowCount == 0)
{
Interlocked.Exchange(ref _enhanceYourCalmCount, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,23 @@ public void Http3GoAwayStreamId(string connectionId, long goAwayStreamId)
Http3GoAwayStreamId(_http3Logger, connectionId, goAwayStreamId);
}

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

public void Http2TooManyEnhanceYourCalms(string connectionId, int count)
{
Http2TooManyEnhanceYourCalms(_http2Logger, connectionId, count);
}

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

public void Http2FlowControlQueueOperationsExceeded(string connectionId, int count)
{
Http2FlowControlQueueOperationsExceeded(_http3Logger, connectionId, count);
}

[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")]
[LoggerMessage(56, LogLevel.Debug, @"Connection id ""{ConnectionId}"" configured maximum flow control queue size {Actual} is less than the maximum streams per connection {Expected}. Increasing configured value to {Expected}.", EventName = "Http2FlowControlQueueMaximumTooLow")]
private static partial void Http2FlowControlQueueMaximumTooLow(ILogger logger, string connectionId, int expected, int actual);

public void Http2FlowControlQueueMaximumTooLow(string connectionId, int expected, int actual)
Expand Down

0 comments on commit 4a5b77e

Please sign in to comment.