Skip to content

[BEAM-5850] Add QueueingBeamFnDataClient and make process, finish and start run on the same thread to support metrics. - #6786

Merged
lukecwik merged 1 commit into
apache:masterfrom
ajamato:java_sdk_metrics_enqueuing_receiver
Dec 7, 2018
Merged

lukecwik merged 1 commit into
apache:masterfrom
ajamato:java_sdk_metrics_enqueuing_receiver

Conversation

@ajamato

@ajamato ajamato commented Oct 23, 2018 •

Copy link
Copy Markdown

Update BeamFnDataReceiver to place elements into a Queue and consumer then and call the element processing receiver in blockTillReadFinishes. This supports the user metrics API which depends on a same thread context for process, start and finish.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

It will help us expedite review of your Pull Request if you tag someone (e.g. @username) to look at it.

Post-Commit Tests Status (on master branch)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- --- --- --- ---
Java Build Status Build Status Build Status Build Status Build Status Build Status Build Status Build Status
Python Build Status --- Build Status
Build Status
Build Status --- --- ---

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add these to .gitignore so that they are never added whenever someone clicks the button "enable something something with Gradle" in Intellij

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

obsolete

@ajamato ajamato changed the title DO NOT SUBMIT/Review - Java sdk metrics enqueuing receiver [BEAM-5850] Add EnqueuingReceiver Oct 24, 2018
@ajamato ajamato changed the title [BEAM-5850] Add EnqueuingReceiver [BEAM-5850] Add BeamFnDataReceiver and make process, finish and start run on the same thread to support metrics. Oct 24, 2018
Comment thread .gitignore Resolved
@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 10 times, most recently from f5e9dd1 to 01ff6f7 Compare October 26, 2018 18:42
@ajamato

ajamato commented Oct 27, 2018

Copy link
Copy Markdown
Author

retest this please.

@ajamato

ajamato commented Oct 27, 2018

Copy link
Copy Markdown
Author

I was able to run this test successfully locally like this: I will try with the apache testing project

./gradlew :beam-runners-google-cloud-dataflow-java-examples-streaming:preCommit -PgcpProject=google.com:clouddfe -PgcsTempRoot=gs://ajamato_presubmit/testing

@ajamato

ajamato commented Oct 27, 2018

Copy link
Copy Markdown
Author

Yeah, I was able to get it to pass
./gradlew :beam-runners-google-cloud-dataflow-java-examples-streaming:preCommit

After authenticating properly

@ajamato

ajamato commented Oct 29, 2018

Copy link
Copy Markdown
Author

retest this please

@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 4 times, most recently from 0790ae2 to 53cc74d Compare October 30, 2018 23:27
@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 2 times, most recently from d8c6a91 to 7da5610 Compare November 9, 2018 21:13

// TODO(BEAM-5972). Make sure that the apiServiceDescriptor is the same.
// throughout all references in the InstructionRequest
if (apiServiceDescriptor != null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would think this would always be true for a real bundle, is this check only here because some of our unit tests don't construct valid ProcessBundleDescriptors?

If yes, it may be better to fix those unit tests instead so that we don't introduce a bug later on.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

See the new code now, I no longer need to lookup the apiServiceDescriptor.

@robertwb

Copy link
Copy Markdown
Contributor

Generally the direction of this PR has be a bit concerned. While it is convenient for users to be able to access and update metrics without having to reference an explicit context, I would definitely prefer that all internal access is explicit (e.g. no worrying about incrementing the wrong bundle's counter because you happened to be on the wrong thread). Forcing these executions to happen on the same thread just propagates this implicit assumption rather than cleaning it up. I think it'd be much cleaner to enter (and exit) the appropriate context on the desired thread (which presumably we'd be doing for state sampling anyway). In addition, adding extra buffers and queues is likely to hurt performance and makes understanding and debugging the system much harder and raises issues like how one should appropriately size and bound these queues. Is this the only (or at least best) way to support metrics?

@lukecwik

lukecwik commented Nov 13, 2018 •

Copy link
Copy Markdown
Member

@robertwb This to address a gap in the current Java SDK. The thread that executes StartBundle/FinishBundle calls is different from the thread that the calls ProcessElement breaking the thread safety expectations of DoFn authors.

This does make it easier to implement the metrics API as it exists today but that is a side effect.

@robertwb

robertwb commented Nov 14, 2018 via email

Copy link
Copy Markdown
Contributor

@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 3 times, most recently from c2908e0 to c593a7a Compare November 27, 2018 19:26
@ajamato ajamato changed the title [BEAM-5850] Add BeamFnDataReceiver and make process, finish and start run on the same thread to support metrics. [BEAM-5850] Add QueueingBeamFnDataClient and make process, finish and start run on the same thread to support metrics. Nov 27, 2018
@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 2 times, most recently from 5f4f2c9 to 2426a63 Compare November 28, 2018 18:35
@ajamato

ajamato commented Nov 29, 2018

Copy link
Copy Markdown
Author

@Ardagan

@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch from 2426a63 to 0de597d Compare November 29, 2018 23:52
}
});

receiveAllValuesB.await();

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.

Add timeout. Otherwise this can hang the test indefinitely.
Apply this to other awaits as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, added test timeout annotation. Thanks


boolean intentionallyFailedB = false;
try {
readFutureB.awaitCompletion(); // All InboundDataClients should be completed.

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.

Is comment relevant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

try {
readFutureB.awaitCompletion(); // All InboundDataClients should be completed.
} catch (RuntimeException e) {
intentionallyFailedB = true;

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.

Why would B be intentionally failed, does it propagate exception from A?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

adding comment
// Fail all InboundObservers if any of the downstream consumers fail.
// This allows the ProcessBundlerHandler to unblock everything and fail properly.

}

@Test
public void testBundleExecutionFailure() throws Exception {

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.

Using test names in the form of <does_something><when_something_happens> usually makes tests more readable with additional benefit of:

  1. Defines expected behavior
  2. Simplifies triaging of test failure to the level when reading test name might be enough.
  3. Surves as inline test description.

I suggest renaming this to "testBundleProcessorThrowsExecutionExceptionWhenUserCodeThrows"

This applies to other tests names as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

}))
.apply("gbk", GroupByKey.create());

RunnerApi.Pipeline pipelineProto = PipelineTranslation.toProto(p);

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.

[No action comment]
Do I understand correctly that you build bundle to process?
If it is, it might be useful to extract such code to share between tests. I might reuse it in some other places.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ack

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ack, good idea. Though I am not sure how to best do this. We can design this together if you would like

startFunction.run();
}

if (hasReadPTransform) {

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.

This should not be needed. queueingClient should handle case with no read ptransforms fine.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done


private final BeamFnDataClient mainClient;
private final SynchronousQueue<ConsumerAndData> queue;
private final ConcurrentHashMap<InboundDataClient, Object> idcs;

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.

rename to "dataClients" or "inboundDataClients".
It is not that much of text increase, but simplifies reading. I had to search several times for what does idcs mean.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

inputLocation.getInstructionId(),
inputLocation.getTarget());

QueueingFnDataReceiver<T> queueingConsumer = new QueueingFnDataReceiver<T>(consumer);

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.

Rename to queueingDataReceiver

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is synonymous. Not renaming. Consumer and receiver are used throughout the whole code base. Doing an entire code base rename would be worth doing if we pick and enforce a single term

@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 3 times, most recently from 632abf5 to ab6140f Compare November 30, 2018 00:54
@lukecwik

Copy link
Copy Markdown
Member

Run Java PreCommit

1 similar comment
@lukecwik

Copy link
Copy Markdown
Member

Run Java PreCommit

@Ardagan Ardagan 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.

I believe some of your changes were lost during rebase. Please revisit my comments above one more time.

@Ardagan

Ardagan commented Nov 30, 2018

Copy link
Copy Markdown
Contributor

Run Java Precommit

@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch from ab6140f to f73a388 Compare November 30, 2018 23:26

@Ardagan Ardagan 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.

   _~
_~ )_)_~
)_))_))_)
_!__!__!_
\______t/

@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch 3 times, most recently from 5ed71e3 to 9776ed4 Compare December 6, 2018 00:14
@ajamato
ajamato force-pushed the java_sdk_metrics_enqueuing_receiver branch from 9776ed4 to e2731a4 Compare December 6, 2018 18:46
@ajamato

ajamato commented Dec 6, 2018

Copy link
Copy Markdown
Author

@lukecwik Rebased this PR after #7214 was merged into master.
Would you please merge this after precommit finishes.

@ajamato

ajamato commented Dec 6, 2018

Copy link
Copy Markdown
Author

Run Java PreCommit

@Ardagan

Ardagan commented Dec 6, 2018 •

Copy link
Copy Markdown
Contributor

Failed precommit: https://builds.apache.org/job/beam_PreCommit_Java_Phrase/468/
This one seem to be flake.
Will trigger another one.

@Ardagan

Ardagan commented Dec 6, 2018

Copy link
Copy Markdown
Contributor

Run Java PreCommit

1 similar comment
@ajamato

ajamato commented Dec 7, 2018

Copy link
Copy Markdown
Author

Run Java PreCommit

@lukecwik
lukecwik merged commit 4cd1226 into apache:master Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants