lhotari commented on code in PR #23811:
URL: https://github.com/apache/pulsar/pull/23811#discussion_r1903098213


##########
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java:
##########
@@ -329,26 +334,29 @@ public void run() {
                     }
                 }
 
-                JavaExecutionResult result;
 
                 // set last invocation time
                 stats.setLastInvocation(System.currentTimeMillis());
 
-                // start time for process latency stat
-                stats.processTimeStart();
-
-                // process the message
-                
Thread.currentThread().setContextClassLoader(functionClassLoader);
-                result = javaInstance.handleMessage(
-                        currentRecord,
-                        currentRecord.getValue(),
-                        asyncResultConsumer,
-                        asyncErrorHandler);
-                
Thread.currentThread().setContextClassLoader(instanceClassLoader);
-
-                // register end time
-                stats.processTimeEnd();
+                CompletableFuture<InstanceObserver> future = 
CompletableFuture.supplyAsync(() -> {
+                    JavaExecutionResult result;
+                    InstanceObserver instanceObserver = new InstanceObserver();
+                    instanceObserver.setStartTime(System.nanoTime());
+                    // process the message
+                    
Thread.currentThread().setContextClassLoader(functionClassLoader);
+                    result = javaInstance.handleMessage(
+                            currentRecord,
+                            currentRecord.getValue(),
+                            asyncResultConsumer,
+                            asyncErrorHandler);
+                    
Thread.currentThread().setContextClassLoader(instanceClassLoader);
+                    instanceObserver.setJavaExecutionResult(result);
+                    return instanceObserver;
+                }).whenComplete((res, ex) -> {
+                    stats.processTimeEnd(res.getStartTime());
+                });
 
+                JavaExecutionResult result = 
future.join().getJavaExecutionResult();

Review Comment:
   This doesn't make sense and is completely unnecessary. 
   Instead, you should simply pass the starting time nanos as an argument that 
gets added to the `JavaExecutionResult` instance field (add a new field 
`startTimeNanos` to JavaExecutionResult).
   The result can be recorded in the `handleResult` method. The 
`processTimeStart` method should be completely removed from the 
`ComponentStatsManager` class and the `processTimeEnd` method should accept the 
starting time as a parameter. The value gets taken from the `startTimeNanos` 
field of the `JavaExecutionResult` instance.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to