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

Add a waiter box for the connection pool #397

Merged
merged 3 commits into from
Jul 8, 2021

Conversation

fabianfett
Copy link
Member

Motivation

For the new HTTPConnectionPool.StateMachine we need a new Waiter type.

Modifications

  • Add a new HTTPConnectionPool.Waiter

@fabianfett fabianfett added this to the HTTP/2 support milestone Jul 7, 2021
@fabianfett fabianfett added the semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Jul 7, 2021

let id: ID
let request: HTTPScheduledRequest
let eventLoopRequirement: EventLoop?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general for good hygiene I'd recommend these being var instead of let.

let request: HTTPScheduledRequest
let eventLoopRequirement: EventLoop?

init(request: HTTPScheduledRequest, eventLoopRequirement: EventLoop?) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we take the preference separately from the HTTPScheduledRequest, which encodes a preference?

@fabianfett fabianfett force-pushed the ff-add-waiter branch 2 times, most recently from 0266fef to f92aa7a Compare July 8, 2021 13:26
@fabianfett fabianfett requested a review from Lukasa July 8, 2021 13:53

extension HTTPConnectionPool {
struct Waiter {
struct ID: Hashable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a great idea ;)

Comment on lines 27 to 35
var id: ID {
ID(self.request)
}

var request: HTTPScheduledRequest {
didSet {
self.updateEventLoopRequirement()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this feels a bit off. If we can the request then the id of the waiter also changes. Is that the behaviour we actually want or should it really be called requestID?

Comment on lines 18 to 42
struct RequestID: Hashable {
private let objectIdentifier: ObjectIdentifier

init(_ request: HTTPScheduledRequest) {
self.objectIdentifier = ObjectIdentifier(request)
}
}

struct Waiter {
var requestID: RequestID {
RequestID(self.request)
}

var request: HTTPScheduledRequest {
didSet {
self.updateEventLoopRequirement()
}
}
Copy link
Member Author

@fabianfett fabianfett Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glbrntt Changed to RecordID. But I moved the RecordID type out of the waiter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still says RequestID. Have I missed something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be called ID and was on the type Waiter, but dependent on the HTTPScheduledRequest

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I was confused by this comment saying the change was to RecordID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

var request: HTTPScheduledRequest {
didSet {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be easier to make eventLoopRequirement a computed property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since HTTPScheduledRequest is a protocol, I wanted to keep the number of calls going through the lookup table as small as possible.

@fabianfett fabianfett merged commit 7311c0e into swift-server:main Jul 8, 2021
@fabianfett fabianfett deleted the ff-add-waiter branch July 8, 2021 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants