Skip to content

Commit

Permalink
DOSHeuristics DeadlineClock more explicit on 5.6 (#422)
Browse files Browse the repository at this point in the history
Motivation:

The type inference system isn't able to work out the default clock type
in the DOSHeuristics init on Swift 5.6 so this change makes it more explicit

Modifications:

Add more explicit inits

Result:

The code should build on 5.6 and later
  • Loading branch information
rnro authored Oct 10, 2023
1 parent 3798fe5 commit 9c22e4f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
25 changes: 25 additions & 0 deletions Sources/NIOHTTP2/DOSHeuristics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,28 @@ struct DOSHeuristics<DeadlineClock: NIODeadlineClock> {

private var resetFrameRateControlStateMachine: HTTP2ResetFrameRateControlStateMachine

#if swift(>=5.7)
internal init(maximumSequentialEmptyDataFrames: Int, maximumResetFrameCount: Int, resetFrameCounterWindow: TimeAmount, clock: DeadlineClock = RealNIODeadlineClock()) {
precondition(maximumSequentialEmptyDataFrames >= 0,
"maximum sequential empty data frames must be positive, got \(maximumSequentialEmptyDataFrames)")
self.maximumSequentialEmptyDataFrames = maximumSequentialEmptyDataFrames
self.receivedEmptyDataFrames = 0
self.resetFrameRateControlStateMachine = .init(countThreshold: maximumResetFrameCount, timeWindow: resetFrameCounterWindow, clock: clock)
}
#else
internal init(maximumSequentialEmptyDataFrames: Int, maximumResetFrameCount: Int, resetFrameCounterWindow: TimeAmount, clock: DeadlineClock) {
precondition(maximumSequentialEmptyDataFrames >= 0,
"maximum sequential empty data frames must be positive, got \(maximumSequentialEmptyDataFrames)")
self.maximumSequentialEmptyDataFrames = maximumSequentialEmptyDataFrames
self.receivedEmptyDataFrames = 0

self.resetFrameRateControlStateMachine = .init(countThreshold: maximumResetFrameCount, timeWindow: resetFrameCounterWindow, clock: clock)
}

internal init(maximumSequentialEmptyDataFrames: Int, maximumResetFrameCount: Int, resetFrameCounterWindow: TimeAmount) where DeadlineClock == RealNIODeadlineClock {
self.init(maximumSequentialEmptyDataFrames: maximumSequentialEmptyDataFrames, maximumResetFrameCount: maximumResetFrameCount, resetFrameCounterWindow: resetFrameCounterWindow, clock: RealNIODeadlineClock())
}
#endif
}


Expand Down Expand Up @@ -89,13 +104,23 @@ extension DOSHeuristics {
private var resetTimestamps: Deque<NIODeadline>
private var _state: ResetFrameRateControlState = .noneReceived

#if swift(>=5.7)
init(countThreshold: Int, timeWindow: TimeAmount, clock: DeadlineClock = RealNIODeadlineClock()) {
self.countThreshold = countThreshold
self.timeWindow = timeWindow
self.clock = clock

self.resetTimestamps = .init(minimumCapacity: self.countThreshold)
}
#else
init(countThreshold: Int, timeWindow: TimeAmount, clock: DeadlineClock) {
self.countThreshold = countThreshold
self.timeWindow = timeWindow
self.clock = clock

self.resetTimestamps = .init(minimumCapacity: self.countThreshold)
}
#endif

mutating func resetReceived() -> ResetFrameRateControlState {
self.garbageCollect()
Expand Down
16 changes: 8 additions & 8 deletions docker/docker-compose.2004.56.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ services:
- MAX_ALLOCS_ALLOWED_1k_requests_inline_noninterleaved=34100
- MAX_ALLOCS_ALLOWED_1k_requests_interleaved=41150
- MAX_ALLOCS_ALLOWED_1k_requests_noninterleaved=40100
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=294050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=271050
- MAX_ALLOCS_ALLOWED_client_server_request_response=263050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=246050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1208050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=891050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=296050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=273050
- MAX_ALLOCS_ALLOWED_client_server_request_response=265050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=248050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1210050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=893050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=39050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=39050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_short_string=200050
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=292950
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291650
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=293050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291750

shell:
image: swift-nio-http2:20.04-5.6
16 changes: 8 additions & 8 deletions docker/docker-compose.2204.57.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ services:
- MAX_ALLOCS_ALLOWED_1k_requests_inline_noninterleaved=34100
- MAX_ALLOCS_ALLOWED_1k_requests_interleaved=41150
- MAX_ALLOCS_ALLOWED_1k_requests_noninterleaved=40100
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=294050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=271050
- MAX_ALLOCS_ALLOWED_client_server_request_response=263050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=246050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1208050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=891050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=296050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=273050
- MAX_ALLOCS_ALLOWED_client_server_request_response=265050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=248050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1210050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=893050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=39050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=39050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_short_string=200050
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=292950
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291650
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=293050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291750

shell:
image: swift-nio-http2:22.04-5.7
16 changes: 8 additions & 8 deletions docker/docker-compose.2204.58.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ services:
- MAX_ALLOCS_ALLOWED_1k_requests_inline_noninterleaved=34100
- MAX_ALLOCS_ALLOWED_1k_requests_interleaved=41150
- MAX_ALLOCS_ALLOWED_1k_requests_noninterleaved=40100
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=294050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=271050
- MAX_ALLOCS_ALLOWED_client_server_request_response=263050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=246050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1208050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=891050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=296050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=273050
- MAX_ALLOCS_ALLOWED_client_server_request_response=265050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=248050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1210050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=893050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=39050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=39050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_short_string=200050
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=292950
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291650
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=293050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291750
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error

shell:
Expand Down
16 changes: 8 additions & 8 deletions docker/docker-compose.2204.59.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ services:
- MAX_ALLOCS_ALLOWED_1k_requests_inline_noninterleaved=34100
- MAX_ALLOCS_ALLOWED_1k_requests_interleaved=41150
- MAX_ALLOCS_ALLOWED_1k_requests_noninterleaved=40100
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=294050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=271050
- MAX_ALLOCS_ALLOWED_client_server_request_response=263050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=246050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1208050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=891050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=296050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=273050
- MAX_ALLOCS_ALLOWED_client_server_request_response=265050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=248050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1210050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=893050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=39050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=39050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_short_string=200050
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=292950
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291650
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=293050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291750
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error

shell:
Expand Down
16 changes: 8 additions & 8 deletions docker/docker-compose.2204.main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ services:
- MAX_ALLOCS_ALLOWED_1k_requests_inline_noninterleaved=34100
- MAX_ALLOCS_ALLOWED_1k_requests_interleaved=41150
- MAX_ALLOCS_ALLOWED_1k_requests_noninterleaved=40100
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=294050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=271050
- MAX_ALLOCS_ALLOWED_client_server_request_response=263050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=246050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1208050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=891050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response=296050
- MAX_ALLOCS_ALLOWED_client_server_h1_request_response_inline=273050
- MAX_ALLOCS_ALLOWED_client_server_request_response=265050
- MAX_ALLOCS_ALLOWED_client_server_request_response_inline=248050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many=1210050
- MAX_ALLOCS_ALLOWED_client_server_request_response_many_inline=893050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel=39050
- MAX_ALLOCS_ALLOWED_create_client_stream_channel_inline=39050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace=200050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_long_string=300050
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_short_string=200050
- MAX_ALLOCS_ALLOWED_hpack_decoding=5050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=292950
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291650
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent=293050
- MAX_ALLOCS_ALLOWED_stream_teardown_100_concurrent_inline=291750
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error

shell:
Expand Down

0 comments on commit 9c22e4f

Please sign in to comment.