You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Priority Hints spec is in the process of being merged into the fetch and HTML specs and allows for site developers to hint at the relative fetch priority for various resources.
This would be an interesting use case to support. While Node.js does not offer much in terms of prioritization from the network stack, Undici queue logic is a prime candidate for this.
My take is that a high priority request jumps at the top of the queue and it's not pipelineable.
Wdyt?
Reacted by Robert Nagy, Ilyas Shabi and Carlos Fuentes
I looked into this but I'm not super familiar with undici's queuing logic. From my understanding, after a request is added to the queue, it's sychronously queued & removed from the queue. So for fetch, assuming that the dispatcher is a default Agent, a priority option wouldn't have an affect, as there isn't a time where multiple requests are in the queue.
For both requests, there is only 1 item in the queue. Adding more requests, we see the same result - there's only ever 1 request queued at a time, and always in the order in which they were dispatched.
I am probably missing something here, but I don't understand how it would be possible to prioritize a certain request. Any help would be appreciated 😄
Maybe a third one is to keep a second queue that's always ordered, and balance the load between the both? e.g. the ordered queue gets flushed first if it has requests with assigned priority, meanwhile the ones without priority remain at the normal queue, and continue running after the ordered one is empty.
Activity
mcollina commentedon Nov 1, 2022
This would be an interesting use case to support. While Node.js does not offer much in terms of prioritization from the network stack, Undici queue logic is a prime candidate for this.
My take is that a high priority request jumps at the top of the queue and it's not pipelineable.
Wdyt?
KhafraDev commentedon Nov 8, 2022
I looked into this but I'm not super familiar with undici's queuing logic. From my understanding, after a request is added to the queue, it's sychronously queued & removed from the queue. So for fetch, assuming that the dispatcher is a default
Agent, a priority option wouldn't have an affect, as there isn't a time where multiple requests are in the queue.Test code:
(of course which request resolves first has no relevance here)
Where the queue looks like:
For both requests, there is only 1 item in the queue. Adding more requests, we see the same result - there's only ever 1 request queued at a time, and always in the order in which they were dispatched.
I am probably missing something here, but I don't understand how it would be possible to prioritize a certain request. Any help would be appreciated 😄
KhafraDev commentedon Sep 2, 2023
cc @mcollina @ronag @metcoder95 is this something we can do?
metcoder95 commentedon Sep 2, 2023
@mcollina and @ronag might have better insights than me on this, but my take is that it should be possible.
AFAICT, we've either of two options:
dispatchingthe request, right here:undici/lib/client.js
Line 303 in 68e2275
runningIdx, here:undici/lib/client.js
Line 1257 in 68e2275
Maybe a third one is to keep a second queue that's always ordered, and balance the load between the both? e.g. the ordered queue gets flushed first if it has requests with assigned priority, meanwhile the ones without priority remain at the normal queue, and continue running after the ordered one is empty.
mcollina commentedon Sep 3, 2023
This is the place I had in in mind.