Skip to content

Commit ff954f9

Browse files
authored
Avoid creating Duration objects when direclty converting to millis (#36969)
1 parent 0f7a189 commit ff954f9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/DataflowExecutionContext.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.LinkedHashMap;
3131
import java.util.Map;
3232
import java.util.Optional;
33+
import java.util.concurrent.TimeUnit;
3334
import java.util.logging.Level;
3435
import java.util.logging.LogRecord;
3536
import java.util.stream.Collectors;
@@ -365,7 +366,7 @@ private String getBundleLullMessage(Thread trackedThread, Duration lullDuration)
365366
message.append(
366367
"Time spent in this step(millis): "
367368
+ (clock.currentTimeMillis()
368-
- getActiveMessageMetadata().get().stopwatch().elapsed().toMillis())
369+
- getActiveMessageMetadata().get().stopwatch().elapsed(TimeUnit.MILLISECONDS))
369370
+ "\n");
370371
}
371372
message.append("Processing times in each step(millis)\n");
@@ -476,7 +477,8 @@ private synchronized void recordActiveMessageInProcessingTimesMap() {
476477
if (this.activeMessageMetadata == null) {
477478
return;
478479
}
479-
int processingTime = (int) (this.activeMessageMetadata.stopwatch().elapsed().toMillis());
480+
int processingTime =
481+
(int) (this.activeMessageMetadata.stopwatch().elapsed(TimeUnit.MILLISECONDS));
480482
this.processingTimesByStep.compute(
481483
this.activeMessageMetadata.userStepName(),
482484
(k, v) -> {

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/streaming/Work.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727
import java.util.Map.Entry;
2828
import java.util.Optional;
29+
import java.util.concurrent.TimeUnit;
2930
import java.util.function.Consumer;
3031
import java.util.function.Supplier;
3132
import javax.annotation.concurrent.NotThreadSafe;
@@ -151,7 +152,7 @@ private static LatencyAttribution.Builder createLatencyAttributionWithActiveLate
151152
stepBuilder.setUserStepName(activeMessage.get().userStepName());
152153
ActiveElementMetadata.Builder activeElementBuilder = ActiveElementMetadata.newBuilder();
153154
activeElementBuilder.setProcessingTimeMillis(
154-
activeMessage.get().stopwatch().elapsed().toMillis());
155+
activeMessage.get().stopwatch().elapsed(TimeUnit.MILLISECONDS));
155156
stepBuilder.setActiveMessageMetadata(activeElementBuilder);
156157
latencyAttribution.addActiveLatencyBreakdown(stepBuilder.build());
157158
return latencyAttribution;

0 commit comments

Comments
 (0)