You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2018/08/09 20:29:40 UTC

[GitHub] nlu90 closed pull request #2976: Adding average Serialization/Deserialization time per tuple

nlu90 closed pull request #2976: Adding average Serialization/Deserialization time per tuple
URL: https://github.com/apache/incubator-heron/pull/2976
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/heron/common/src/java/org/apache/heron/common/utils/metrics/FullBoltMetrics.java b/heron/common/src/java/org/apache/heron/common/utils/metrics/FullBoltMetrics.java
index 320bef06a9..84700d371c 100644
--- a/heron/common/src/java/org/apache/heron/common/utils/metrics/FullBoltMetrics.java
+++ b/heron/common/src/java/org/apache/heron/common/utils/metrics/FullBoltMetrics.java
@@ -52,8 +52,10 @@
   // Time in nano-seconds spending in execute() at every interval
   private final MultiCountMetric executeTimeNs;
   private final MultiCountMetric emitCount;
-  private final MultiCountMetric deserializationTimeNs;
-  private final MultiCountMetric serializationTimeNs;
+  private final MultiCountMetric totalDeserializationTimeNs;
+  private final MultiCountMetric totalSerializationTimeNs;
+  private final MultiReducedMetric<MeanReducerState, Number, Double> averageSerializationTimeNs;
+  private final MultiReducedMetric<MeanReducerState, Number, Double> averageDeserializationTimeNs;
 
   // The # of times back-pressure happens on outStreamQueue
   // so instance could not produce more tuples
@@ -71,8 +73,11 @@ public FullBoltMetrics() {
     emitCount = new MultiCountMetric();
     outQueueFullCount = new CountMetric();
 
-    deserializationTimeNs = new MultiCountMetric();
-    serializationTimeNs = new MultiCountMetric();
+    totalDeserializationTimeNs = new MultiCountMetric();
+    totalSerializationTimeNs = new MultiCountMetric();
+
+    averageSerializationTimeNs = new MultiReducedMetric<>(new MeanReducer());
+    averageDeserializationTimeNs = new MultiReducedMetric<>(new MeanReducer());
   }
 
   public void registerMetrics(TopologyContextImpl topologyContext) {
@@ -91,8 +96,13 @@ public void registerMetrics(TopologyContextImpl topologyContext) {
     topologyContext.registerMetric("__emit-count", emitCount, interval);
     topologyContext.registerMetric("__out-queue-full-count", outQueueFullCount, interval);
     topologyContext.registerMetric(
-        "__tuple-deserialization-time-ns", deserializationTimeNs, interval);
-    topologyContext.registerMetric("__tuple-serialization-time-ns", serializationTimeNs, interval);
+        "__tuple-deserialization-time-ns", totalDeserializationTimeNs, interval);
+    topologyContext.registerMetric(
+        "__tuple-serialization-time-ns", totalSerializationTimeNs, interval);
+    topologyContext.registerMetric(
+        "__av-tuple-deserialization-time-ns", totalDeserializationTimeNs, interval);
+    topologyContext.registerMetric(
+        "__av-tuple-serialization-time-ns", totalSerializationTimeNs, interval);
   }
 
   // For MultiCountMetrics, we need to set the default value for all streams.
@@ -174,17 +184,20 @@ public void updateOutQueueFullCount() {
   }
 
   public void deserializeDataTuple(String streamId, String sourceComponent, long latency) {
-    deserializationTimeNs.scope(streamId).incrBy(latency);
+    totalDeserializationTimeNs.scope(streamId).incrBy(latency);
+    averageDeserializationTimeNs.scope(streamId).update(latency);
 
     // Consider there are cases that different streams with the same streamId,
     // but with different source component. We need to distinguish them too.
     String globalStreamId =
         new StringBuilder(sourceComponent).append("/").append(streamId).toString();
-    deserializationTimeNs.scope(globalStreamId).incrBy(latency);
+    totalDeserializationTimeNs.scope(globalStreamId).incrBy(latency);
+    averageDeserializationTimeNs.scope(globalStreamId).update(latency);
   }
 
   public void serializeDataTuple(String streamId, long latency) {
-    serializationTimeNs.scope(streamId).incrBy(latency);
+    totalSerializationTimeNs.scope(streamId).incrBy(latency);
+    averageSerializationTimeNs.scope(streamId).update(latency);
   }
 }
 
diff --git a/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java b/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java
index f58e181ace..68193d2012 100644
--- a/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java
+++ b/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java
@@ -291,7 +291,7 @@ public void readTuplesAndExecute(Communicator<Message> inQueue) {
         int sourceTaskId = tuples.getSrcTaskId();
 
         for (HeronTuples.HeronDataTuple dataTuple : tuples.getData().getTuplesList()) {
-          long startExecuteTuple = System.nanoTime();
+          long startTime = System.nanoTime();
           // Create the value list and fill the value
           List<Object> values = new ArrayList<>(nValues);
           for (int i = 0; i < nValues; i++) {
@@ -300,20 +300,23 @@ public void readTuplesAndExecute(Communicator<Message> inQueue) {
 
           // Decode the tuple
           TupleImpl t = new TupleImpl(topologyContext, stream, dataTuple.getKey(),
-              dataTuple.getRootsList(), values, startExecuteTuple, false, sourceTaskId);
+              dataTuple.getRootsList(), values, System.nanoTime(), false, sourceTaskId);
+
+          long deserializedTime = System.nanoTime();
 
           // Delegate to the use defined bolt
           bolt.execute(t);
 
-          // record the end of a tuple execution
-          long endExecuteTuple = System.nanoTime();
-
-          long executeLatency = endExecuteTuple - startExecuteTuple;
+          // record the latency of execution
+          long executeLatency = Duration.ofNanos(System.nanoTime()).
+              minusNanos(deserializedTime).toNanos();
 
           // Invoke user-defined execute task hook
           topologyContext.invokeHookBoltExecute(t, Duration.ofNanos(executeLatency));
 
           // Update metrics
+          boltMetrics.deserializeDataTuple(stream.getId(), stream.getComponentName(),
+              deserializedTime - startTime);
           boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency);
         }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services