[ 
https://issues.apache.org/jira/browse/BEAM-6655?focusedWorklogId=203286&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-203286
 ]

ASF GitHub Bot logged work on BEAM-6655:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Feb/19 19:00
            Start Date: 24/Feb/19 19:00
    Worklog Time Spent: 10m 
      Work Description: chamikaramj commented on pull request #7819: 
[BEAM-6655] Initial support for progress reporting over the FnAPI.
URL: https://github.com/apache/beam/pull/7819#discussion_r259635193
 
 

 ##########
 File path: sdks/python/apache_beam/runners/worker/operations.py
 ##########
 @@ -584,19 +596,57 @@ def monitoring_infos(self, transform_id):
 
 class SdfProcessElements(DoOperation):
 
+  def __init__(self, *args, **kwargs):
+    super(SdfProcessElements, self).__init__(*args, **kwargs)
+    self.lock = threading.RLock()
+    self.element_start_output_bytes = None
+
   def process(self, o):
     with self.scoped_process_state:
-      delayed_application = self.dofn_runner.process_with_restriction(o)
-      if delayed_application:
-        self.execution_context.delayed_applications.append(
-            (self, delayed_application))
+      try:
+        with self.lock:
+          self.element_start_output_bytes = self._total_output_bytes()
+          for receiver in self.tagged_receivers.values():
+            receiver.opcounter.restart_sampling()
+        delayed_application = self.dofn_runner.process_with_restriction(o)
+        if delayed_application:
+          self.execution_context.delayed_applications.append(
+              (self, delayed_application))
+      finally:
+        with self.lock:
+          self.element_start_output_bytes = None
 
   def try_split(self, fraction_of_remainder):
     split = self.dofn_runner.try_split(fraction_of_remainder)
     if split:
       primary, residual = split
       return (self, primary), (self, residual)
 
+  def current_element_progress(self):
+    with self.lock:
+      if self.element_start_output_bytes is not None:
+        return self.dofn_runner.current_element_progress().with_completed(
+            self._total_output_bytes() - self.element_start_output_bytes)
+
+  def progress_metrics(self):
+    with self.lock:
+      metrics = super(SdfProcessElements, self).progress_metrics()
+      current_element_progress = self.current_element_progress()
+    if current_element_progress:
+      metrics.active_elements.measured.input_element_counts[
+          self.input_info[1]] = 1
+      metrics.active_elements.fraction_remaining = (
+          current_element_progress.fraction_remaining)
+    return metrics
+
+  def _total_output_bytes(self):
+    total = 0
+    for receiver in self.tagged_receivers.values():
+      elements = receiver.opcounter.element_counter.value()
+      if elements > 0:
+        total += elements * receiver.opcounter.mean_byte_counter.value()
 
 Review comment:
   mean_byte_counter is mean size of a given element ? I don't think this will 
be a good measure for SDFs since sizes of elements could vary significantly 
(different sources instead of elements of a given type).
 
----------------------------------------------------------------
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 203286)

> Support progress reporting over FnAPI
> -------------------------------------
>
>                 Key: BEAM-6655
>                 URL: https://issues.apache.org/jira/browse/BEAM-6655
>             Project: Beam
>          Issue Type: New Feature
>          Components: beam-model, sdk-java-harness, sdk-py-harness
>            Reporter: Robert Bradshaw
>            Priority: Major
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to