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

Introduce a new FlushMode in the interest of not creating too many batches #14060

Closed
wants to merge 7 commits into from

Conversation

andre4i
Copy link
Contributor

@andre4i andre4i commented Feb 8, 2023

Description

When the client uses async code, there is a risk of creating too many batches (enough batches to trigger server-side throttling) as with FlushMode.TurnBased as flush is scheduled as a microtask. This change allows for flushing to happen in a scheduled macrotask, capturing all the ops from all microtask and bundling them as a single batch.

@github-actions github-actions bot added area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc base: next PRs targeted against next branch labels Feb 8, 2023
@github-actions github-actions bot added the public api change Changes to a public API label Feb 8, 2023
@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Feb 8, 2023

@fluid-example/bundle-size-tests: -606 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 430.62 KB 430.44 KB -180 Bytes
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 225.58 KB 225.4 KB -180 Bytes
loader.js 158.96 KB 158.96 KB No change
map.js 43.95 KB 43.87 KB -82 Bytes
matrix.js 136.13 KB 136.05 KB -82 Bytes
odspDriver.js 91.07 KB 91.07 KB No change
odspPrefetchSnapshot.js 42.43 KB 42.43 KB No change
sharedString.js 156.67 KB 156.59 KB -82 Bytes
Total Size 1.36 MB 1.36 MB -606 Bytes

Baseline commit: 2aebc74

Generated by 🚫 dangerJS against a70cfa3

@andre4i andre4i marked this pull request as ready for review February 8, 2023 21:03
@andre4i andre4i requested review from msfluid-bot and a team as code owners February 8, 2023 21:03
@@ -96,6 +96,7 @@ export type FluidDataStoreRegistryEntry = Readonly<Partial<IProvideFluidDataStor

// @public
export enum FlushMode {
Async = 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can have most of these changes in main, with exception of this change in enum.
I.e. you can easily have

export enum FlushModeEx {
Async = 2,
};

and use it in main, and merge FlushModeEx & FlushMode in next

Copy link
Contributor Author

@andre4i andre4i Feb 9, 2023

Choose a reason for hiding this comment

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

How would that work? Can you expand a bit? The runtime would still expect FlushMode | FlushModeEx in its APIs, right? Isn't that still a back-compat breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, everywhere in the code I'd keep FlushMode alone.
If caller (Loop) wants to experiment, then can do FlusModeEx.timeout as FlusModeEx.
And the only place where we need to do cast is switch:

switch (mode) {
case FlushMode.immidiate:...
case FlushModeEx.timeout as FlushMode:

}

This adds ability to push most of the code into main (which is good think from all points), while not changing officially API, but allowing (if we want to) experimentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will prepare the change for main

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so the plan is to merge #14106 first, then wait for main->next integration and afterwards I'll re-adjust this PR to accommodate the changes from main. My goal is to make it so that we don't end up with merge conflicts and at the same time, next uses proper flushmode.

@agarwal-navin
Copy link
Contributor

Before we add this experiment, should we check that the current applications will even use this? Otherwise, we might not get any data suggesting if this even works.

andre4i added a commit that referenced this pull request Feb 10, 2023
…tches (#14106)

## Description

When the client uses async code, there is a risk of creating too many
batches (enough batches to trigger server-side throttling) as with
FlushMode.TurnBased as flush is scheduled as a microtask. This change
allows for flushing to happen in a scheduled macrotask, capturing all
the ops from all microtask and bundling them as a single batch.

**Note this ability is not part of the public API. The runtime does not
accept this new flush mode without explicit casting**

This change is #14060
but for `main`
@microsoft-github-policy-service
Copy link
Contributor

This PR has been automatically marked as stale because it has had no activity for 60 days. It will be closed if no further activity occurs within 8 days of this comment. Thank you for your contributions to Fluid Framework!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: runtime Runtime related issues area: tests Tests to add, test infrastructure improvements, etc base: next PRs targeted against next branch public api change Changes to a public API status: stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants