forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(presence): Add support for signal batching (microsoft#23075)
## Summary of changes Presence updates are grouped together and throttled to prevent flooding the network with messages when presence values are rapidly updated. This means the presence infrastructure will not immediately broadcast updates but will broadcast them after a configurable delay. The `allowableUpdateLatencyMs` property configures how long a local update may be delayed under normal circumstances, enabling batching with other updates. The default `allowableUpdateLatencyMs` is **60 milliseconds** but may be (1) specified during configuration of a States Workspace or Value Manager and/or (2) updated later using the `controls` member of Workspace or Value Manager. States Workspace configuration applies when a Value Manager does not have its own setting. Notifications are never queued; they effectively always have an `allowableUpdateLatencyMs` of 0. However, they may be batched with other updates that were already queued. Note that due to throttling, clients receiving updates may not see updates for all values set by another. For example, with `Latest*ValueManagers`, the only value sent is the value at the time the outgoing batched message is sent. Previous values set by the client will not be broadcast or seen by other clients. ### Example You can configure the batching and throttling behavior using the `allowableUpdateLatencyMs` property as in the following example: ```ts // Configure a states workspace const stateWorkspace = presence.getStates("app:v1states", { // This value manager has an allowable latency of 100ms. position: Latest({ x: 0, y: 0 }, { allowableUpdateLatencyMs: 100 }), // This value manager uses the workspace default. count: Latest({ num: 0 }), }, // Specify the default for all value managers in this workspace to 200ms, // overriding the default value of 60ms. { allowableUpdateLatencyMs: 200 } ); // Temporarily set count updates to send as soon as possible const countState = stateWorkspace.props.count; countState.controls.allowableUpdateLatencyMs = 0; countState.local = { num: 5000 }; // Reset the update latency to the workspace default countState.controls.allowableUpdateLatencyMs = undefined; ``` ## Test cases 1. Signals send immediately when allowable latency is 0 1. Signals are batched when they are received within the send deadline (send deadline is set to now + allowable latency iff a new message is queued; i.e. a message was not previously queued - this is the first message to be put in the queue) 1. Signals from LVMs with different allowable latencies are batched correctly 1. Queued signal is sent with immediate signal (i.e. if a signal is queued and an immediate message comes in, it should merge and send immediately) 1. Multiple workspaces; messages from multiple workspaces should be batched and queued 1. Include sending notifications - they should be sent immediately The test cases themselves include inline comments with the time and expected deadline for each operation. Signals are also numbered inline to make it easier to match up with the expected signals. ## Known gaps LatestMapValueManager is not tested. --------- Co-authored-by: Jason Hartman <[email protected]>
- Loading branch information
1 parent
f7be965
commit abde76d
Showing
7 changed files
with
1,307 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
"@fluidframework/presence": minor | ||
--- | ||
--- | ||
"section": feature | ||
--- | ||
|
||
Presence updates are now batched and throttled | ||
|
||
Presence updates are grouped together and throttled to prevent flooding the network with messages when presence values are rapidly updated. This means the presence infrastructure will not immediately broadcast updates but will broadcast them after a configurable delay. | ||
|
||
The `allowableUpdateLatencyMs` property configures how long a local update may be delayed under normal circumstances, enabling batching with other updates. The default `allowableUpdateLatencyMs` is **60 milliseconds** but may be (1) specified during configuration of a [States Workspace](https://github.com/microsoft/FluidFramework/tree/main/packages/framework/presence#value-managers#states-workspace) or [Value Manager](https://github.com/microsoft/FluidFramework/tree/main/packages/framework/presence#value-managers#value-managers) and/or (2) updated later using the `controls` member of Workspace or Value Manager. [States Workspace](https://github.com/microsoft/FluidFramework/tree/main/packages/framework/presence#value-managers#states-workspace) configuration applies when a Value Manager does not have its own setting. | ||
|
||
Notifications are never queued; they effectively always have an `allowableUpdateLatencyMs` of 0. However, they may be batched with other updates that were already queued. | ||
|
||
Note that due to throttling, clients receiving updates may not see updates for all values set by another. For example, | ||
with `Latest*ValueManagers`, the only value sent is the value at the time the outgoing batched message is sent. Previous | ||
values set by the client will not be broadcast or seen by other clients. | ||
|
||
#### Example | ||
|
||
You can configure the batching and throttling behavior using the `allowableUpdateLatencyMs` property as in the following example: | ||
|
||
```ts | ||
// Configure a states workspace | ||
const stateWorkspace = presence.getStates("app:v1states", | ||
{ | ||
// This value manager has an allowable latency of 100ms. | ||
position: Latest({ x: 0, y: 0 }, { allowableUpdateLatencyMs: 100 }), | ||
// This value manager uses the workspace default. | ||
count: Latest({ num: 0 }), | ||
}, | ||
// Specify the default for all value managers in this workspace to 200ms, | ||
// overriding the default value of 60ms. | ||
{ allowableUpdateLatencyMs: 200 } | ||
); | ||
|
||
// Temporarily set count updates to send as soon as possible | ||
const countState = stateWorkspace.props.count; | ||
countState.controls.allowableUpdateLatencyMs = 0; | ||
countState.local = { num: 5000 }; | ||
|
||
// Reset the update latency to the workspace default | ||
countState.controls.allowableUpdateLatencyMs = undefined; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.