Intent to Implement and Ship: Throttling background dedicated workers

220 views
Skip to first unread message

Alexander Timin

unread,
Feb 7, 2018, 8:31:34 AM2/7/18
to blink-dev, elle...@chromium.org

Contact emails

alt...@chromium.org, elle...@chromium.org


Design doc

Design doc


Summary

This intervention expands the concept of background throttling from javascript timers to dedicated workers.


Motivation

When a renderer is backgrounded, the amount of work coming from dedicated workers is higher than that coming from the main thread. This intervention aims to lessen the adverse performance and battery impact caused by content users cannot see. This intervention also addresses the recent rise of malicious scripts performing power-heavy computations without user permission (e.g. cryptocurrency mining).


Risks

Interoperability and Compatibility

Medium risk. There are web applications (i.e. SETI-at-home) which will require a user-initiated action to remain unthrottled, but the vast majority of pages should not be affected.


Edge: No signals

Firefox: No signals

Safari: No signals

Web developers: Mixed signals


Ergonomics

N/A


Activation

None required.


Debuggability

Similar to existing throttling mechanisms -- a console warning will be generated when worker is throttled. Tracing coverage will be provided.


Also there is a effort underway to expose throttling state as a part of chrome://discards, but given that this throttling intervention is very similar to main thread throttling, the intervention won’t be blocked on it.


Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes.


Is this feature fully tested by web-platform-tests?

N/A, as this is an intervention.


Link to entry on the feature dashboard

https://www.chromestatus.com/feature/6334419736461312


Requesting approval to ship?

Yes, using experiment-based rollout. The findings of this rollout will be shared on this thread.

Ben Kelly

unread,
Feb 7, 2018, 10:07:36 AM2/7/18
to Alexander Timin, blink-dev, elle...@chromium.org
On Wed, Feb 7, 2018 at 8:31 AM, Alexander Timin <alt...@chromium.org> wrote:

Firefox: No signals


FWIW, we hope to do the same in firefox:

Wez

unread,
Feb 7, 2018, 1:12:46 PM2/7/18
to Alexander Timin, blink-dev, elle...@chromium.org
Can you provide more detail on the implementation for this?  The existing main-thread throttler appears to be design only for use by the Inspector, not for production CPU throttling, e.g. it spins on a dedicated thread on Windows, to get the desired timing precision.  (Or perhaps I'm just looking at the wrong class :)

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CALHg4n%3DF2sV-5bv568sahLQGKDPpqCeS%3DA2wOzPhdEeH899QnA%40mail.gmail.com.

Alexander Timin

unread,
Feb 8, 2018, 1:36:07 AM2/8/18
to Wez, blink-dev, elle...@chromium.org
On 8 February 2018 at 03:12, Wez <w...@chromium.org> wrote:
Can you provide more detail on the implementation for this?  The existing main-thread throttler appears to be design only for use by the Inspector, not for production CPU throttling, e.g. it spins on a dedicated thread on Windows, to get the desired timing precision.  (Or perhaps I'm just looking at the wrong class :)

The class implementing existing main thread throttling mechanism is TaskQueueThrottler. It throttled tasks by delaying new ones and does not interfere with running ones.

However, given that a script can hijack a worker thread completely, it's suggested to throttle long-running tasks. The implementation details of this are not finalised and two options are considered: a) modify ThreadCPUThrottler to support this use case (i.e. lose extra precision and avoid busy-wait) and suspend thread on os level b) yield control back to the scheduler inside v8 safepoints. 

est...@chromium.org

unread,
Feb 11, 2018, 12:05:37 PM2/11/18
to blink-dev, w...@chromium.org, elle...@chromium.org
Is there somewhere I can read more about the user-initiated action for opting out? Where will that setting live and what will it look like?

Ojan Vafai

unread,
Feb 15, 2018, 6:41:42 PM2/15/18
to est...@chromium.org, blink-dev, w...@chromium.org, elle...@chromium.org
Shipping this doesn't block on the user opt-out, right?

This seems like a natural extension of the throttling we do for main thread script, so I think doesn't have substantially different implications for the platform on top of what we already ship. LGTM1 with or without the user opt-out.

Philip Jägenstedt

unread,
Feb 21, 2018, 8:44:35 AM2/21/18
to Ojan Vafai, est...@chromium.org, blink-dev, w...@chromium.org, elle...@chromium.org
On "Web developers: Mixed signals", are there cases other than the mentioned SETI-at-home that are known to be impacted, and have any web developers been concerned about this?

Even if we already throttle the main thread, closing the last way of doing heavy background computation (if this is the last) does change the platform I'd argue, so I'm also very curious about how sites will be able to get this capability back.

Alex Russell

unread,
Mar 1, 2018, 1:52:39 PM3/1/18
to blink-dev, oj...@chromium.org, est...@chromium.org, w...@chromium.org, elle...@chromium.org
Hey all,

Per today's API Owners meeting, a few questions following on from Philip's:
  • Do we understand the percentage of content that will be impacted? Do we know of sites other than SETI that are impacted?
  • Will this policy be applied to WASM content (which is conceptually identical)?
  • Will UMA be logged about how frequently this is invoked?
  • Have we considered launching a monitoring version of this to collect data before actually shipping?
  • Will this be Finch'd?
Regards

Ojan Vafai

unread,
Mar 2, 2018, 12:38:32 PM3/2/18
to Alex Russell, blink-dev, est...@chromium.org, w...@chromium.org, elle...@chromium.org
On Thu, Mar 1, 2018 at 10:52 AM Alex Russell <sligh...@google.com> wrote:
Hey all,

Per today's API Owners meeting, a few questions following on from Philip's:
  • Do we understand the percentage of content that will be impacted? Do we know of sites other than SETI that are impacted?
  • Will this policy be applied to WASM content (which is conceptually identical)?
  • Will UMA be logged about how frequently this is invoked?
  • Have we considered launching a monitoring version of this to collect data before actually shipping?
I don't think we should do this for a few reasons:
  • This is unlikely to give us useful information about breakage. Our experience with throttling the main thread is that the (rare) breakage information really only came from shipping and waiting for bug reports to come in.
  • This would delay shipping by 6-12 weeks at a minimum, which is not appropriate for the urgency of this change given the user impact it's mitigating. It may be the case that we try to ship, find breakage that we believe to be unacceptable and keep iterating anyways, but this would add a delay on top of that.

Alex Russell

unread,
Mar 2, 2018, 4:12:46 PM3/2/18
to Ojan Vafai, blink-dev, Emily Stark, w...@chromium.org, elle...@chromium.org
TL;DR: changing my response to "LGTM".

Detail:

Spoke offline with Ojan offline and he was able to clear up what, in retrospect, turned out to be my confusion (thanks Ojan!)

I was under the impression that this was about throttling workers in foreground tabs. This isn't the proposal -- instead, what's being suggested is extending the throttling we already do to background pages to the workers created by them. 

This seems much less challenging. To some degree, it's surprising we aren't already doing this!

There's a large open question about UI and API that might be eventually created for exceptions to this throttling (to handle the SETI case), but I'm fine with this being out of scope for now.

I would like to see UMA added to understand how frequently we invoke this intervention as we build/ship it to inform that design process.

Thanks again.

bradn...@chromium.org

unread,
Mar 2, 2018, 5:13:04 PM3/2/18
to blink-dev, oj...@chromium.org, est...@chromium.org, w...@chromium.org, elle...@chromium.org
In general, sounds like a reasonable approach especially to mitigate what we're seeing now.

However, a few concerns:
* Various polyfills in JS + Wasm for decoding audio / video exist, used by Wikipedia and other. Is there any danger this could throttle these down below usability when the user wants background audio?
   - Could we use audio as a signal to permit this?
   - Would folks then play null audio to game this?
* Having a user prompt for background tasks like SETI or other user intended background work (compilers, rendering, long running simulation etc.) Is there any standards work in place to provide this? (Or did we imagine we could glean this from CPU use?)
* Once SharedArrayBuffer returns to the platform, event loop based throttling won't work for content that uses SABs to route data. How quickly can we start something OS level?

Kentaro Hara

unread,
Mar 2, 2018, 9:24:43 PM3/2/18
to bradn...@chromium.org, blink-dev, Ojan Vafai, est...@chromium.org, Wez, elle...@chromium.org
Non-owner LGTM to experimenting this idea and collecting UMA.

Existing UMA shows that 43% of the CPU performance on background tabs is consumed by dedicated workers. From the perspective of "throttling invisible work", throttling workers on background tabs is super important :)








--
Kentaro Hara, Tokyo, Japan

Daniel Bratell

unread,
Mar 7, 2018, 11:52:56 AM3/7/18
to bradn...@chromium.org, Kentaro Hara, blink-dev, Ojan Vafai, est...@chromium.org, Wez, elle...@chromium.org
I'm wondering if wasm will be throttled as well? The suggested throttling is aggressive (triggering after 10 seconds) and I can see how that can cause issues with for instance a chess site such as lichess.org.

/Daniel
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CABg10jybHyW9sWOUqdMtXmnMRHdFt13YZRWQaOM4Ysw-SjrjGw%40mail.gmail.com.



--
/* Opera Software, Linköping, Sweden: CET (UTC+1) */

Ojan Vafai

unread,
Mar 7, 2018, 3:38:15 PM3/7/18
to Daniel Bratell, bradn...@chromium.org, Kentaro Hara, blink-dev, est...@chromium.org, Wez, elle...@chromium.org
This throttling is only for background tabs. lichess.org would be fine if throttled in background tabs (WASM or not), no?

Daniel Bratell

unread,
Mar 8, 2018, 7:29:42 AM3/8/18
to Ojan Vafai, bradn...@chromium.org, Kentaro Hara, blink-dev, est...@chromium.org, Wez, elle...@chromium.org
Having a computer analyze a position for a long time is a common use case for a chess engine, but lichess wasm is a factor slower than native implementations (still impressively fast) so maybe that is something that should not be done in a browser.

/Daniel

Yoav Weiss

unread,
Mar 15, 2018, 9:27:19 AM3/15/18
to Daniel Bratell, Ojan Vafai, bradn...@chromium.org, Kentaro Hara, blink-dev, est...@chromium.org, Wez, elle...@chromium.org
On Thu, Mar 8, 2018 at 1:29 PM Daniel Bratell <bra...@opera.com> wrote:
Having a computer analyze a position for a long time is a common use case for a chess engine, but lichess wasm is a factor slower than native implementations (still impressively fast) so maybe that is something that should not be done in a browser.

Or maybe something that could use the eventual opt-in that will enable such background work to take place.
 

Rick Byers

unread,
Mar 15, 2018, 3:33:59 PM3/15/18
to Yoav Weiss, Daniel Bratell, Ojan Vafai, Bradley Nelson, Kentaro Hara, blink-dev, Emily Stark, Wez, elle...@chromium.org, Shubhie Panicker
Discussed at the API owners meeting (chrishtr@, slightlyoff@, yoav@, jochen@, rbyers@ present).  We agreed that this is largely about aligning with our existing background tab throttling policies.

There's some new compat risk here (since code running in a worker is often designed specifically to be "background work").  But our understanding is that a user opt-out for "allow unrestricted background work" is imminent. Having a user opt-out mitigates the additional compat risk.

So LGTM3 from the group if we can block shipping this change on the availability of some user opt-out.

If the UI for a user opt-out becomes stalled, then feel free to circle back on this thread and we can discuss options for other mitigations that don't require blocking on it.



/Daniel
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.



--
/* Opera Software, Linköping, Sweden: CET (UTC+1) */
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.



--
/* Opera Software, Linköping, Sweden: CET (UTC+1) */

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.

Alexander Timin

unread,
Mar 19, 2018, 9:15:19 AM3/19/18
to Rick Byers, Yoav Weiss, Daniel Bratell, Ojan Vafai, Bradley Nelson, Kentaro Hara, blink-dev, Emily Stark, Wez, elle...@chromium.org, Shubhie Panicker
Thanks for the approval!

Once again, we'll treat pages playing audible audio (or pages which recently played audible audio) are foregrounded, exactly the same as we do for main thread throttling.

I'll add metrics to record the frequency of this intervention.

I will update this thread once we launch this intervention to Dev channel and get back some numbers.

Daniel Bratell

unread,
Mar 26, 2018, 9:36:33 AM3/26/18
to Rick Byers, Alexander Timin, Yoav Weiss, Ojan Vafai, Bradley Nelson, Kentaro Hara, blink-dev, Emily Stark, Wez, elle...@chromium.org, Shubhie Panicker
This might have the interesting side effect that a processing background script has to give the user an audible ping every now and then. I don't think that is a bad thing.

/Daniel

/Daniel
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.



--
/* Opera Software, Linköping, Sweden: CET (UTC+1) */
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.



--
/* Opera Software, Linköping, Sweden: CET (UTC+1) */
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CACj%3DBEgPPfcfj4Yr8cmQKLukAp-0S7dBEx%3D79tn8bycVgaQctw%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.




--
/* Opera Software, Linköping, Sweden: CEST (UTC+2) */

Alexander Timin

unread,
Jun 21, 2018, 10:26:26 AM6/21/18
to Daniel Bratell, Rick Byers, Yoav Weiss, Ojan Vafai, Bradley Nelson, Kentaro Hara, blink-dev, Emily Stark, Wez, elle...@chromium.org, Shubhie Panicker
A quick update on this: I've launched the initial version to Canary&Dev and the results are really promising: -30% of background renderer process CPU usage, -10% overall renderer process CPU usage on Windows. There is also a noticeable improvement on foreground tabs both on desktop and on Android in FCP and scroll latency, of around 5-10%.

The next step is to add an opt-out and ship it :) The plan is to have Origin-Trial opt-out, here is the first draft. I'll be sending Intent-to-Experiment for the opt-out to this list shortly.

Alexander
Reply all
Reply to author
Forward
0 new messages