o-nikolas commented on code in PR #39650:
URL: https://github.com/apache/airflow/pull/39650#discussion_r1608731275


##########
airflow/task/task_runner/standard_task_runner.py:
##########
@@ -186,3 +194,19 @@ def get_process_pid(self) -> int:
         if self.process is None:
             raise RuntimeError("Process is not started yet")
         return self.process.pid
+
+    def _read_task_utilization(self):
+        dag_id = self._task_instance.dag_id
+        task_id = self._task_instance.task_id
+
+        try:
+            while True:
+                with self.process.oneshot():
+                    mem_usage = self.process.memory_percent()
+                    cpu_usage = self.process.cpu_percent()
+
+                    Stats.gauge(f"task.mem_usage.{dag_id}.{task_id}", 
mem_usage)
+                    Stats.gauge(f"task.cpu_usage.{dag_id}.{task_id}", 
cpu_usage)
+                    time.sleep(1)
+        except (psutil.NoSuchProcess, psutil.AccessDenied, AttributeError):
+            return

Review Comment:
   Should we log here so the user knows why they aren't receiving that metric?



##########
airflow/task/task_runner/standard_task_runner.py:
##########
@@ -186,3 +194,19 @@ def get_process_pid(self) -> int:
         if self.process is None:
             raise RuntimeError("Process is not started yet")
         return self.process.pid
+
+    def _read_task_utilization(self):
+        dag_id = self._task_instance.dag_id
+        task_id = self._task_instance.task_id
+
+        try:
+            while True:
+                with self.process.oneshot():
+                    mem_usage = self.process.memory_percent()
+                    cpu_usage = self.process.cpu_percent()
+
+                    Stats.gauge(f"task.mem_usage.{dag_id}.{task_id}", 
mem_usage)
+                    Stats.gauge(f"task.cpu_usage.{dag_id}.{task_id}", 
cpu_usage)
+                    time.sleep(1)

Review Comment:
   I'd still vote to reduce this to something like 5s or more. 1s feels way too 
granular, does anyone need that level of detail? Most stats exporters are just 
going to aggregate those points anyways so we're spinning in a very tight loop 
for not much gain. 



-- 
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