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

[WIP] Dataflow Streaming GroupByKey state multiplexing for small keys #33318

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

arunpandianp
Copy link
Contributor

This is a POC showing how state multiplexing can work for GroupByKey.

  • Messages with small keys (<4K) are hashed and shuffled to a fixed set of virtual sharding keys and get reduced on the virtual keys.
  • The actual keys are sent to the virtual keys as part of windows.
  • Existing combining, aggregations work at the window level, so they all work out of the box.

The 4k threshold is currently an arbitrary small value and can be tweaked. The constraint is any state tags should not exceed 64k and keys are now part of the windowed state tags.

Need to cleanup comments and add tests, sending this to share the idea and get initial feedback.

R: @scwhittle

…oupByKey state over a fixed number of sharding keys.

The number of sharding keys is fixed at 32k.
// Note that Never trigger finishes *at* GC time so it is OK, and
// AfterWatermark.fromEndOfWindow() finishes at end-of-window time so it is
// OK if there is no allowed lateness.
private static boolean triggerIsSafe(WindowingStrategy<?, ?> windowingStrategy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

}

@Override
public PCollection<KV<K, Iterable<V>>> expand(PCollection<KV<K, V>> input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to verify that the trigger is of some safe type that just uses processing timer or watermark time to trigger?

For example, after count (beyond 1) will have confusing results if it's supposed to count per key but won't now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is all trigger state are per window and the associated state variables are in the window namespace.

return stateInternals.state(windowNamespace(), address, context);

Since the userKey is part of the KeyedWindow and the window namespaces, state for different userKeys won't collide.

If there are custom trigger implementation relying on external state, that might have problems depending on how it accesses state.

after count (beyond 1) will have confusing results if it's supposed to count per key but won't now.

IIUC, this change should be transparent and not change semantics for any triggers/windows. Could you explain more on when the after count semantics can change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline, I was confusing things and this should work as triggers and state are per-window.

ByteString key = ((KeyedWindow<?>) w).getKey();
try {

// is it correct to use the pane from Keyed window here?
Copy link
Contributor

Choose a reason for hiding this comment

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

see above, I think we need to make sure we only do this for correct triggers. If that is done, I think it would be safe to use the pane.

@github-actions github-actions bot added build and removed java labels Dec 15, 2024
@github-actions github-actions bot added the java label Dec 17, 2024
@arunpandianp
Copy link
Contributor Author

Run Java Precommit

@arunpandianp
Copy link
Contributor Author

Run Precommit Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants