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

Allow Addresses to have a max calls per connection #8386

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

peckb1
Copy link
Collaborator

@peckb1 peckb1 commented Apr 24, 2024

Overview

This adds the ability for the Address Policy to also contain a maximum number of connections per Stream.

Additionally creates a ConnectionPoolPolicy which can have default options set up for all connections in the pool.

Context

In some environments it seems that OkHttp's HTTP/2 gets worse the more streams that are packed onto a single connection.
By adding in the ability for users to alter their client's AddressPolicy to set a maximum number of connections per stream, they can control how much (if any) packing they want OkHttp to perform.

This adds the ability for the Address Policy to also contain a maximum
number of connections per Stream.

In some environments it seems that OkHttp's HTTP/2 gets worse the more
streams that are packed onto a single connection. By adding in the
ability for users to alter their client's AddressPolicy to set a maximum
number of connections per stream, they can control how much (if any)
packing they want OkHttp to perform.
@@ -368,6 +384,18 @@ class RealConnection(
}
}

private fun getMaximumAllocationLimit(): Int {
// if we have not negotiated a max per streams yet, don't check for the policy override
val negotiatedMaxCurrentStreams = lastMaxConcurrentStreamsFromSettings ?: return 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this just defaulted to 1 for Http/1 and Http2Connection.DEFAULT_SETTINGS.getMaxConcurrentStreams() for Http/2?

should it be a lateinit and start sets to one or the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe?

private var lastMaxConcurrentStreamsFromSettings = 1 would avoid the early return, but then we're checking against the policy.

Would it be better to have the null and early return or check the policy every time, even if we're not in HTTP/2 land?

Copy link
Collaborator

@ean5533 ean5533 left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, but I recommend waiting for a review from a more experienced maintainer

okhttp/src/main/kotlin/okhttp3/ConnectionPool.kt Outdated Show resolved Hide resolved
@peckb1 peckb1 force-pushed the feature.peckb.address-policy-max-calls-per-connection branch from c6a955f to 96345cf Compare April 24, 2024 22:06
@@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.locks.ReentrantLock
import javax.net.ssl.SSLPeerUnverifiedException
import javax.net.ssl.SSLSocket
import kotlin.concurrent.withLock
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no longer need when the references from lock.withLock were changed to this.withLock

  • though that extension function still forwards to lock.withLock so same concurrent method used one step further.

@peckb1 peckb1 changed the title Allow AddressPolicy to have a max calls per connection Allow Addresses to have a max calls per connection Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants