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

Implement RFC 9113 stream priorities for HTTP/2 #404

Open
swankjesse opened this issue Jan 5, 2014 · 18 comments
Open

Implement RFC 9113 stream priorities for HTTP/2 #404

swankjesse opened this issue Jan 5, 2014 · 18 comments
Labels
enhancement Feature not a bug
Milestone

Comments

@swankjesse
Copy link
Collaborator

At the moment we don't honor stream priority, and we don't allow app developers to prioritize their streams.

We should.

@swankjesse swankjesse mentioned this issue Jan 5, 2014
7 tasks
@swankjesse swankjesse modified the milestones: Icebox, 3.0 Nov 5, 2014
@swankjesse
Copy link
Collaborator Author

@shanghuibo
Copy link

Is there any progress in this issue?

@JakeWharton
Copy link
Collaborator

No

On Mon, Jun 6, 2016 at 10:29 PM shanghuibo [email protected] wrote:

Is there any progress in this issue?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#404 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAEEEcc90-JqoPgEeT6VF9VhdjqZ4tvWks5qJNeBgaJpZM4BXgco
.

@HyperSimon
Copy link

我是来看jake大神的

@swankjesse
Copy link
Collaborator Author

Dispatcher Proposal

I propose a prioritization scheme for use in processing Dispatcher’s backlog of async calls. Each call has a priority between 0.0 (lowest priority) and 1.0 (highest priority). The default priority is 0.1.

We assign each queued call a priority score using the following function:

val BASE_MILLIS = 1000

fun Call.priorityScore() = (BASE_MILLIS   timeInQueueMillis()) * priority

Suppose we enqueue 3 calls:

A enqueued at time=0, priority=1.0
B enqueued at time=100, priority=0.5
C enqueued at time=200, priority=0.0

At time 200 we compute the priorities as A=1200, B=550, C=0.
At time 1000 we compute the priorities as A=2000, B=950, C=0.

Higher priority requests “age faster” than lower-priority requests. Any request with a non-zero priority eventually has been queued long enough to be preferred over higher-priority requests. Another example:

D enqueued at time=0, priority=0.1
E enqueued at time=10,000, priority=1.0
At time 10,000 we compute the priority of D=1100 ((1000 10,000) x 0.1), and E=1000 ((1000 0) x 1.0), so D is processed before E.
But if we hadn’t checked until time 11,000, then D=1200 and E=2000 so E is preferred.

Requests of priority 0.0 are allowed to starve and are only processed if requests of higher priority are not enqueued.

@biaomingzhong
Copy link

Dispatcher Proposal

I propose a prioritization scheme for use in processing Dispatcher’s backlog of async calls. Each call has a priority between 0.0 (lowest priority) and 1.0 (highest priority). The default priority is 0.1.

We assign each queued call a priority score using the following function:

val BASE_MILLIS = 1000

fun Call.priorityScore() = (BASE_MILLIS   timeInQueueMillis()) * priority

Suppose we enqueue 3 calls:

A enqueued at time=0, priority=1.0
B enqueued at time=100, priority=0.5
C enqueued at time=200, priority=0.0

At time 200 we compute the priorities as A=1200, B=550, C=0.
At time 1000 we compute the priorities as A=2000, B=950, C=0.

Higher priority requests “age faster” than lower-priority requests. Any request with a non-zero priority eventually has been queued long enough to be preferred over higher-priority requests. Another example:

D enqueued at time=0, priority=0.1
E enqueued at time=10,000, priority=1.0
At time 10,000 we compute the priority of D=1100 ((1000 10,000) x 0.1), and E=1000 ((1000 0) x 1.0), so D is processed before E.
But if we hadn’t checked until time 11,000, then D=1200 and E=2000 so E is preferred.

Requests of priority 0.0 are allowed to starve and are only processed if requests of higher priority are not enqueued.

Current dispatcher has readyAsyncCalls and runningAsyncCalls. How to implement this scheme?

@arsalankhan994
Copy link

Is there any update on this?

@caplan
Copy link

caplan commented Jun 28, 2021

As a workaround, would you accept a pr that allows the caller to optionally provide their own Dispatcher?

I'm thinking that OkHttpClient.Builder.dispatcher's type could be an interface (that Dispatcher implements), or alternatively Dispatcher could be open (although that seems kind of messy)

@swankjesse
Copy link
Collaborator Author

You could create two instances of OkHttpClient, one for high-priority calls and one for low-priority calls. We can’t make Dispatcher user-implementable; it’s too difficult internally for that.

@greyski
Copy link

greyski commented Jun 29, 2021

You could create two instances of OkHttpClient, one for high-priority calls and one for low-priority calls. We can’t make Dispatcher user-implementable; it’s too difficult internally for that.

Could you expand on how that would work exactly? How would one instance of the OkHttpClient be able to "communicate" with the other one and say "my requests are higher priority than yours"? Maybe some brief example code if possible, thanks!

@fzandroid
Copy link

Is this issue still being worked on?

@swankjesse
Copy link
Collaborator Author

@fzandroid nopers! We work in the open here so there's nothing happening in OkHttp that isn't also happening in GitHub.

@swankjesse
Copy link
Collaborator Author

swankjesse commented Jun 9, 2022

HTTP/2 dropped its priority scheme.
https://httpwg.org/specs/rfc9113.html#PriorityHere

@li-brich
Copy link

What makes you say HTTP/2 priority was dropped? On the contrary, RFC 9113 says that it retains RFC 7540's priority fields in order to maintain interoperability:

frame fields and some of the mandatory handling is retained to ensure that implementations of this document remain interoperable with implementations that use the priority signaling described in RFC 7540.

And it goes on to say that priority is (still) important and encourage the use of RFC 9218:

Signaling priority information is necessary to attain good performance in many cases. Where signaling priority information is important, endpoints are encouraged to use an alternative scheme, such as the scheme described in HTTP-PRIORITY

The footnote for HTTP-PRIORITY links to RFC 9218, which seems very forward-looking:

This document defines the Priority header field for communicating the initial priority in an HTTP version-independent manner, as well as HTTP/2 and HTTP/3 frames for reprioritizing responses. These share a common format structure that is designed to provide future extensibility.

If anything, how clients communicate priority will change as HTTP/3 is adopted. But RFC 7540 support hasn't been dropped and the IETF has defined a scheme that will allow them to support priority as a feature beyond HTTP/2.

@yschimke
Copy link
Collaborator

yschimke commented Nov 28, 2022

The impression I'd got was that HTTP/2 prioritisation was considered problematic, frequently not implemented by servers and clienta. And lessons learned were being applied to HTTP/3.

[Edit: I think your links have more context.]

But I don't have anything definitive on this. I could have misunderstood. Maybe https://blog.cloudflare.com/adopting-a-new-approach-to-http-prioritization/

Do we have real numbers for usage? Regardless, I don't think there is appetite and incentives to tackle this in OkHttp.

@ghost
Copy link

ghost commented Nov 29, 2022

Yes

@swankjesse
Copy link
Collaborator Author

I think we want to track RFC 9113’s prioritization scheme.

asuka-mio added a commit to Ehviewer-Overhauled/Ehviewer that referenced this issue Mar 9, 2023
…favourite, get torrent list etc.)

Currently okhttp does not support request priority(See square/okhttp#404), and our GalleryDetailScene will launch at most 200 image requests once, which stuffed okhttp async request queue.
We need another http client to ensure these plain-text request executed in time
@yschimke yschimke changed the title Stream priority: expose it & honor it Implement RFC 9113 stream priorities for HTTP/2 May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.