-
Notifications
You must be signed in to change notification settings - Fork 123
[HTTP2ConnectionPool] added HTTP2Connections
struct
#440
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
[HTTP2ConnectionPool] added HTTP2Connections
struct
#440
Conversation
5e83e02
to
2b3b29a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Small stuff now.
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Outdated
Show resolved
Hide resolved
5.5 failed because of an unrelated issue:
@fabianfett investigates: https://ci.swiftserver.group/job/async-http-client-swift55-prb/154/console |
4de065c
to
1289735
Compare
5.5 fails because of an issue that is fixed in #441. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! @Lukasa would you mind giving this another look?
if self.isIdle { | ||
stats.idleConnections &+= 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: maybe move this into .active
and check if usedStream == 0
.
1289735
to
dfd000d
Compare
private enum State { | ||
/// the pool is establishing a connection. Valid transitions are to: .backingOff, .active and .closed | ||
case starting | ||
/// the connection is waiting to retry to establish a connection. Transition to .closed. From .closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably this wanted to say "Valid transitions are to:"?
case closed | ||
} | ||
|
||
var isActive: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to clarify the intended meaning of "active" here: it's a bit of a surprise to me that .draining
connections aren't active.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are actually no longer using isActive
and I have now removed it.
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift
Show resolved
Hide resolved
lastIdle = .now() | ||
} | ||
self.state = .active(conn, maxStreams: maxStreams, usedStreams: usedStreams, lastIdle: lastIdle) | ||
return max(maxStreams - usedStreams, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This max
call is unnecessary: we can raise the assert
above into a precondition
and then just return maxStreams - usedStreams
.
Additionally, while we're here, the same precondition
means we can use unchecked subtraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think max
actually is necessary because we could receive a new max concurrent streams settings at any time which is lower than the current streams in use. In that case, we would potentially report a negative number of available streams.
Nevertheless, I agree with raising the assert to a precondition and the unchecked subtraction.
|
||
case .draining(let conn, let maxStreams, var usedStreams): | ||
usedStreams -= 1 | ||
assert(usedStreams >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a precondition
.
return .removeConnection | ||
|
||
case .active(let connection, _, let usedStreams, _): | ||
if usedStreams <= 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to precondition
on this number being less than zero.
return connection.connectionID | ||
} | ||
|
||
/// A new HTTP/2.0 connection was established. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giant nitpick: It's HTTP/2, not HTTP/2.0. No minor version.
/// tries to find an available connection on the prefered `eventLoop`. If it can't find one with the given `eventLoop`, it returns the first available connection | ||
private func findAvailableConnection(onPreferred eventLoop: EventLoop) -> Int? { | ||
var availableConnection: Int? | ||
for (index, connection) in self.connections.enumerated() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be somewhat cautious here: enumerated
does not return an (index, element)
tuple, it returns an (offset, element)
tuple. We should probably write a version of this that does what you actually want, in case we ever change the underlying object.
eb5cd0a
to
88f3606
Compare
|
One step closer to support HTTP/2 in the new connection pool.
HTTP2Connections
will be used in a newHTTP2StateMaschine
in a follow up PR.