You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/09/30 01:28:49 UTC

[GitHub] [beam] xinyuiscool opened a new pull request, #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

xinyuiscool opened a new pull request, #23434:
URL: https://github.com/apache/beam/pull/23434

   In pr #23313, we added the executor support for processing elements within a ParDo bundle in parallel. This pr provides the ordering by key for stateful ParDo processing. Instead of dispatching the processing in the thread pool directly, we chain the element processing onto the output future of the last element with the same key, to ensure the ordering by key.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] xinyuiscool commented on pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
xinyuiscool commented on PR #23434:
URL: https://github.com/apache/beam/pull/23434#issuecomment-1290842796

   Run Java PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] xinyuiscool commented on pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
xinyuiscool commented on PR #23434:
URL: https://github.com/apache/beam/pull/23434#issuecomment-1265788340

   Run Java PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] xinyuiscool commented on pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
xinyuiscool commented on PR #23434:
URL: https://github.com/apache/beam/pull/23434#issuecomment-1290980734

   Run Java PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] mynameborat commented on a diff in pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
mynameborat commented on code in PR #23434:
URL: https://github.com/apache/beam/pull/23434#discussion_r1003630941


##########
runners/samza/src/test/java/org/apache/beam/runners/samza/runtime/AsyncDoFnRunnerTest.java:
##########
@@ -168,4 +174,57 @@ public void testPipelineWithAggregation() {
 
     pipeline.run();
   }
+
+  @Test
+  public void testKeyedOutputFutures() {
+    // We test the scenario that two elements of the same key needs to be processed in order.
+    final DoFnRunner<KV<String, Integer>, Void> doFnRunner = mock(DoFnRunner.class);
+    final AtomicInteger prev = new AtomicInteger(0);
+    doAnswer(
+            invocation -> {
+              WindowedValue<KV<String, Integer>> wv = invocation.getArgument(0);
+              Integer val = wv.getValue().getValue();
+
+              // Verify the previous element has been fully processed by checking the prev value
+              assertEquals(val - 1, prev.get());
+
+              prev.set(val);
+              return null;
+            })
+        .when(doFnRunner)
+        .processElement(any());
+
+    SamzaPipelineOptions options = PipelineOptionsFactory.as(SamzaPipelineOptions.class);
+    options.setNumThreadsForProcessElement(4);
+
+    final OpEmitter<Void> opEmitter = new OpAdapter.OpEmitterImpl<>();
+    final FutureCollector<Void> futureCollector = new DoFnOp.FutureCollectorImpl<>();
+    futureCollector.prepare();
+
+    final AsyncDoFnRunner<KV<String, Integer>, Void> asyncDoFnRunner =
+        AsyncDoFnRunner.create(doFnRunner, opEmitter, futureCollector, true, options);
+
+    final String appleKey = "apple";
+
+    final WindowedValue<KV<String, Integer>> input1 =
+        WindowedValue.valueInGlobalWindow(KV.of(appleKey, 1));
+
+    final WindowedValue<KV<String, Integer>> input2 =
+        WindowedValue.valueInGlobalWindow(KV.of(appleKey, 2));
+
+    asyncDoFnRunner.processElement(input1);
+    asyncDoFnRunner.processElement(input2);

Review Comment:
   Is there a way to introduce some sort of additional delay in the execution of input1 to ensure there is time for the following `asyncDoFnRunner.processElement(input2)` to be invoked and  guarantee that it is gated on the first call?
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] xinyuiscool merged pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
xinyuiscool merged PR #23434:
URL: https://github.com/apache/beam/pull/23434


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] xinyuiscool commented on a diff in pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
xinyuiscool commented on code in PR #23434:
URL: https://github.com/apache/beam/pull/23434#discussion_r1003789363


##########
runners/samza/src/test/java/org/apache/beam/runners/samza/runtime/AsyncDoFnRunnerTest.java:
##########
@@ -168,4 +174,57 @@ public void testPipelineWithAggregation() {
 
     pipeline.run();
   }
+
+  @Test
+  public void testKeyedOutputFutures() {
+    // We test the scenario that two elements of the same key needs to be processed in order.
+    final DoFnRunner<KV<String, Integer>, Void> doFnRunner = mock(DoFnRunner.class);
+    final AtomicInteger prev = new AtomicInteger(0);
+    doAnswer(
+            invocation -> {
+              WindowedValue<KV<String, Integer>> wv = invocation.getArgument(0);
+              Integer val = wv.getValue().getValue();
+
+              // Verify the previous element has been fully processed by checking the prev value
+              assertEquals(val - 1, prev.get());
+
+              prev.set(val);
+              return null;
+            })
+        .when(doFnRunner)
+        .processElement(any());
+
+    SamzaPipelineOptions options = PipelineOptionsFactory.as(SamzaPipelineOptions.class);
+    options.setNumThreadsForProcessElement(4);
+
+    final OpEmitter<Void> opEmitter = new OpAdapter.OpEmitterImpl<>();
+    final FutureCollector<Void> futureCollector = new DoFnOp.FutureCollectorImpl<>();
+    futureCollector.prepare();
+
+    final AsyncDoFnRunner<KV<String, Integer>, Void> asyncDoFnRunner =
+        AsyncDoFnRunner.create(doFnRunner, opEmitter, futureCollector, true, options);
+
+    final String appleKey = "apple";
+
+    final WindowedValue<KV<String, Integer>> input1 =
+        WindowedValue.valueInGlobalWindow(KV.of(appleKey, 1));
+
+    final WindowedValue<KV<String, Integer>> input2 =
+        WindowedValue.valueInGlobalWindow(KV.of(appleKey, 2));
+
+    asyncDoFnRunner.processElement(input1);
+    asyncDoFnRunner.processElement(input2);

Review Comment:
   Good point! I added a countdown latch to let processElement(input2) to run before the actual processing of input1. Please take a look again.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] xinyuiscool commented on pull request #23434: Support keyed executors in Samza Runner to process bundles for stateful ParDo

Posted by GitBox <gi...@apache.org>.
xinyuiscool commented on PR #23434:
URL: https://github.com/apache/beam/pull/23434#issuecomment-1290836869

   Run Java PreCommit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org