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

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

                Author: ASF GitHub Bot
            Created on: 06/Mar/19 14:55
            Start Date: 06/Mar/19 14:55
    Worklog Time Spent: 10m 
      Work Description: robertwb commented on pull request #7819: [BEAM-6655] 
Initial support for progress reporting over the FnAPI.
URL: https://github.com/apache/beam/pull/7819#discussion_r260041995
 
 

 ##########
 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:
   This is the output size, used to produce a fraction if the SDF published 
nothing but backlog bytes.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


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

    Worklog Id:     (was: 208876)
    Time Spent: 2h 10m  (was: 2h)

> 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: 2h 10m
>  Remaining Estimate: 0h
>




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

Reply via email to