-
Notifications
You must be signed in to change notification settings - Fork 341
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 flag to indicate delay-tolerant Request, to enable request coalescing. #184
Comments
As I mentioned in the other issue, we should think about what parts of the delaying we want to expose to the web page which initiated the request. If we let the webpage see the timing of when the request goes out, that will severely limit our flexibility in choosing that timing. And we'll have to precisely define what that timing should be so that it's consistent across browsers. |
On a separate note, what is the plan for if the user leaves the page while these requests are still pending?
|
The webpage will be able to observe when the fetch goes out by checking the fetchStart timestamp on the associated ResourceTiming object. The delta between startTime and The above doesn't limit us in any way. I do think we should provide some suggested values for how often the UA should flush coalesced requests, but this can be purely advisory.
If the pending request was queued via sendBeacon then yes, they'll be dispatched whenever visibilityChange transitions to 'hidden'.
Dropped on the floor and never sent, I think.
|
Current implementations do not defer or coalesce beacon requests, and the definition of Beacon-Age allows it to be omitted when age is 0. As such, this is backwards compatible change. The right place to enable this is probably in Fetch API: whatwg/fetch#184 Assuming above is resolved, Beacon API would simply set a flag to indicate to fetch that the request is delay tolerant. Fetch would handle the coalescing logic and append the ~Request-Age header. This would allow different request types to be batched together (e.g. background sync, beacons, and so on).
I'd like to pick this thread back up in the context, at the very least, of analytics pings. I see this solution being instrumental to minimize the loss of analytics pings, while also minimizing negative effects on performance. I did some limited testing on different devices and it showed that simple batching can improve battery utilization by 33-38%. The benefit would be even better if it was possible to align batching with radio "on" times. The @igrigorik 's description above sounds great. But couple of nuances:
|
Great. Looks the list of requirements is enough for starting spec work. Given the configurable timeout, we need to define a request pool and timer logic in the spec for batching. I'll give it a try once get some time. /cc @yutakahirano as he's working on keepalive impl. |
Some requests initiated both by the browser and the application are delay tolerant (for relatively small values of "delay") - e.g. beacons, polling for updates, background sync requests, error reports, etc.
I think we should allow both the browser and applications to signal this when initializing the Request, via an additional flag. When such flag is present, the browser can coalesce network access and improve energy + network efficiency... Waking up the radio incurs a lot of overhead regardless of transfer size (due to timeout logic in the controller that keeps the radio active for some period of time), and coalescing multiple requests to fire at once would help amortize that cost and reduce overall energy footprint.
Implementing this kind of coalescing functionality in app-space is hard / impossible: it requires explicit coordination between all actors that initiate fetches (third party scripts, iframes, plus other browser processes, etc); there isn't sufficient information to infer whether radio is active or not.
In terms of implementation, the browser can do the following:
In other words, delay-tolerant requests would be sent immediately within at most X seconds from being queued, and sooner if network interface becomes - or is, already - active.
Nothing needs to change in terms of processing on the client: the promise would get resolved when response is received; rejected if request fails. The extra "delay" due to coalescing would look as if there is a long RTT to the server.
In terms of consumers that could leverage this: Beacon API, Reporting API, background sync, and application code that's emitting delay tolerant requests.
The text was updated successfully, but these errors were encountered: