-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Upload PerWorkerMetrics every 30 second instead of every 10 seconds #30795
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0dc2c4b
Upload PerWorkerMetrics every 30 second instead of every 10 seconds
JayajP dbceef7
Address comments
JayajP 1e605dc
Merge branch 'master' into uploadfrequency-v3
JayajP 44519a4
Fix merge conflicts
JayajP 6ff2ef8
Merge branch 'master' into uploadfrequency-v3
JayajP 3017996
Merge branch 'master' into uploadfrequency-v3
JayajP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.google.api.services.dataflow.model.WorkItemStatus; | ||
import com.google.api.services.dataflow.model.WorkerMessage; | ||
import java.io.IOException; | ||
import java.math.RoundingMode; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
|
@@ -52,6 +53,7 @@ | |
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ListMultimap; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.MultimapBuilder; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.math.LongMath; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -81,6 +83,12 @@ public final class StreamingWorkerStatusReporter { | |
private final ScheduledExecutorService globalWorkerUpdateReporter; | ||
private final ScheduledExecutorService workerMessageReporter; | ||
|
||
// PerWorkerMetrics are sent on the WorkerMessages channel, and are sent one in every | ||
// perWorkerMetricsUpdateFrequency RPC call. If 0, PerWorkerMetrics are not reported. | ||
long perWorkerMetricsUpdateFrequency = 0L; | ||
// Used to track the number of WorkerMessages that have been sent without PerWorkerMetrics. | ||
long workerMessagesIndex = 0L; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will not be threadsafe, how about using an AtomicLong |
||
|
||
private StreamingWorkerStatusReporter( | ||
boolean publishCounters, | ||
WorkUnitClient dataflowServiceClient, | ||
|
@@ -194,8 +202,12 @@ private static void shutdownExecutor(ScheduledExecutorService executor) { | |
} | ||
|
||
@SuppressWarnings("FutureReturnValueIgnored") | ||
public void start(long windmillHarnessUpdateReportingPeriodMillis) { | ||
public void start( | ||
long windmillHarnessUpdateReportingPeriodMillis, | ||
long perWorkerMetricsUpdateReportingPeriodMillis) { | ||
reportHarnessStartup(); | ||
setPerWorkerMetricsUpdateFrequency( | ||
windmillHarnessUpdateReportingPeriodMillis, perWorkerMetricsUpdateReportingPeriodMillis); | ||
if (windmillHarnessUpdateReportingPeriodMillis > 0) { | ||
LOG.info( | ||
"Starting periodic worker status reporters. Reporting period is every {} millis.", | ||
|
@@ -222,6 +234,7 @@ public void stop() { | |
shutdownExecutor(workerMessageReporter); | ||
// one last send | ||
reportPeriodicWorkerUpdates(); | ||
this.workerMessagesIndex = this.perWorkerMetricsUpdateFrequency; | ||
reportPeriodicWorkerMessage(); | ||
} | ||
|
||
|
@@ -240,6 +253,24 @@ private void reportHarnessStartup() { | |
} | ||
} | ||
|
||
// Calculates the PerWorkerMetrics reporting frequency, ensuring alignment with the | ||
// WorkerMessages RPC schedule. The desired reporting period | ||
// (perWorkerMetricsUpdateReportingPeriodMillis) is adjusted to the nearest multiple | ||
// of the RPC interval (windmillHarnessUpdateReportingPeriodMillis). | ||
private void setPerWorkerMetricsUpdateFrequency( | ||
long windmillHarnessUpdateReportingPeriodMillis, | ||
long perWorkerMetricsUpdateReportingPeriodMillis) { | ||
if (windmillHarnessUpdateReportingPeriodMillis == 0) { | ||
this.perWorkerMetricsUpdateFrequency = 0; | ||
return; | ||
} | ||
this.perWorkerMetricsUpdateFrequency = | ||
LongMath.divide( | ||
perWorkerMetricsUpdateReportingPeriodMillis, | ||
windmillHarnessUpdateReportingPeriodMillis, | ||
RoundingMode.CEILING); | ||
} | ||
|
||
/** Sends counter updates to Dataflow backend. */ | ||
private void sendWorkerUpdatesToDataflowService( | ||
CounterSet deltaCounters, CounterSet cumulativeCounters) throws IOException { | ||
|
@@ -313,11 +344,7 @@ private List<WorkerMessage> createWorkerMessage() { | |
List<WorkerMessage> workerMessages = new ArrayList<>(2); | ||
workerMessages.add(createWorkerMessageForStreamingScalingReport()); | ||
|
||
if (StreamingStepMetricsContainer.getEnablePerWorkerMetrics()) { | ||
Optional<WorkerMessage> metricsMsg = createWorkerMessageForPerWorkerMetrics(); | ||
metricsMsg.ifPresent(workerMessages::add); | ||
} | ||
|
||
createWorkerMessageForPerWorkerMetrics().ifPresent(metrics -> workerMessages.add(metrics)); | ||
return workerMessages; | ||
} | ||
|
||
|
@@ -334,6 +361,18 @@ private WorkerMessage createWorkerMessageForStreamingScalingReport() { | |
} | ||
|
||
private Optional<WorkerMessage> createWorkerMessageForPerWorkerMetrics() { | ||
if (!StreamingStepMetricsContainer.getEnablePerWorkerMetrics() | ||
|| perWorkerMetricsUpdateFrequency == 0) { | ||
return Optional.empty(); | ||
} | ||
|
||
workerMessagesIndex += 1; | ||
if (workerMessagesIndex < perWorkerMetricsUpdateFrequency) { | ||
return Optional.empty(); | ||
} else { | ||
workerMessagesIndex = 0; | ||
} | ||
|
||
List<PerStepNamespaceMetrics> metrics = new ArrayList<>(); | ||
allStageInfo.get().forEach(s -> metrics.addAll(s.extractPerWorkerMetricValues())); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this never changes lets make it private and final and initialize in the constructor
you can modify the constructor to take in this instead of passing it into start() and have start() take no params.