Skip to content

[wasm] spread WS based timers over next 6 minutes to prevent heavy throttling - #57745

Merged
pavelsavara merged 8 commits into
dotnet:mainfrom
pavelsavara:wasm_prevent_timer_throttling
Aug 26, 2021
Merged

[wasm] spread WS based timers over next 6 minutes to prevent heavy throttling#57745
pavelsavara merged 8 commits into
dotnet:mainfrom
pavelsavara:wasm_prevent_timer_throttling

Conversation

@pavelsavara

@pavelsavarapavelsavara commented Aug 19, 2021

Copy link
Copy Markdown
Member

Problem

Chromium browsers throttle setTimeout frequency on inactive pages to 1 sec almost immediately.
5 minutes later they throttle heavily to wakeup each 60 seconds.
That breaks dotnet Timer expectations and also threadpool.

The heavy throttling could be lifted back to 1sec if there was WebSocket activity.
https://developer.chrome.com/blog/timer-throttling-in-chrome-88/#intensive-throttling

Implementation

The idea is to cover the future 6 minutes with "wakeup" timer, each 1 second apart from each other.
1 second, because is the light throttling rate, so it would not help to try to do it more often.
It should be triggered from WS event, so that it's only 1 deep from it.
Every subsequent call would schedule only for uncovered future.

There is [OuterLoop] unit test for this.

Fixes#51041

@pavelsavarapavelsavara added the arch-wasm WebAssembly architecture label Aug 19, 2021
@pavelsavara
pavelsavara requested review from kg and lewingAugust 19, 2021 17:27
@ghost

Copy link
Copy Markdown

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #51041

Author:pavelsavara
Assignees:-
Labels:

arch-wasm

Milestone:-

@pavelsavara

pavelsavara commented Aug 19, 2021

Copy link
Copy Markdown
MemberAuthor

Right now, I'm not clear if 6 minutes is right time span.
Also I plan to implement OuterLoop unit test for it yet.

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

This is necessary infrastructure change for the automated test. It's still quite fragile.
dotnet/xharness#695

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-mono outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
pavelsavaraforce-pushed the wasm_prevent_timer_throttling branch from bec2dfc to 043e566CompareAugust 23, 2021 13:37
@pavelsavara

pavelsavara commented Aug 23, 2021

Copy link
Copy Markdown
MemberAuthor

New xharness binaries are in.

@pavelsavara
pavelsavara marked this pull request as ready for review August 23, 2021 15:49
@pavelsavara
pavelsavaraforce-pushed the wasm_prevent_timer_throttling branch from aa34508 to 42fc2eaCompareAugust 25, 2021 11:18
@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-mono outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-mono outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-mono outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-mono outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

Outerloop issue is Unable to open X display. for the new System.Net.WebSockets.Client.Wasm.Tests, which makes sense.
But throttling is not testable without real visible browser UI.

@kg

kg commented Aug 25, 2021

Copy link
Copy Markdown
Contributor

IIRC there are ways to run chromium headless with a 'fake' framebuffer, window etc. Not sure which one we'd use here, or whether it would actually trigger this. Another option would be a headless X instance paired to VNC, I know people do that for tests sometimes.

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

I just excluded the test from CI, making it manual test.

kg
kg approved these changes Aug 25, 2021

@kgkg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything looks fine to me

Comment threadsrc/libraries/System.Net.WebSockets.Client/System.Net.WebSockets.Client.sln Outdated
Comment threadsrc/mono/wasm/runtime/binding_support.js Outdated
Comment threadsrc/mono/wasm/runtime/binding_support.js Outdated
Comment threadsrc/mono/wasm/runtime/library_mono.js Outdated
@pavelsavara
pavelsavara merged commit 5eaa911 into dotnet:mainAug 26, 2021
@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/backport to release/6.0-rc1

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/6.0-rc1: https://github.com/dotnet/runtime/actions/runs/1169555771

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASM] Chrome timer throttling affects runtime

3 participants

@pavelsavara@kg@karelz