Repository: aurora
Updated Branches:
  refs/heads/master 5bffe8f6a -> b8f72d146


Use Process.oneshot() in latest psutils for faster stats retrieval.

Without the Process.oneshot() decorator stats retrieval can lead to
multiple reads of the same `/proc` filesystem values. The oneshot
decorator enables caching to speed this up. It has been added in
psutils 5.0.

Oneshot docs: https://pythonhosted.org/psutil/#psutil.Process.oneshot
Changelog: https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#520

Bugs closed: AURORA-1907

Reviewed at https://reviews.apache.org/r/57732/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/b8f72d14
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/b8f72d14
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/b8f72d14

Branch: refs/heads/master
Commit: b8f72d1461c2f13f1f73c13211b428f60596c11e
Parents: 5bffe8f
Author: Stephan Erb <[email protected]>
Authored: Sun Mar 19 16:01:50 2017 +0100
Committer: Stephan Erb <[email protected]>
Committed: Sun Mar 19 16:01:50 2017 +0100

----------------------------------------------------------------------
 3rdparty/python/requirements.txt                |  2 +-
 .../monitoring/process_collector_psutil.py      | 23 ++++++++++----------
 2 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/b8f72d14/3rdparty/python/requirements.txt
----------------------------------------------------------------------
diff --git a/3rdparty/python/requirements.txt b/3rdparty/python/requirements.txt
index df2db7a..0c04b98 100644
--- a/3rdparty/python/requirements.txt
+++ b/3rdparty/python/requirements.txt
@@ -21,7 +21,7 @@ mock==1.0.1
 mox==0.5.3
 pex==1.1.14
 protobuf==2.6.1
-psutil==4.3.0
+psutil==5.2.0
 pystachio==0.8.3
 requests==2.11.1
 requests-kerberos==0.10.0

http://git-wip-us.apache.org/repos/asf/aurora/blob/b8f72d14/src/main/python/apache/thermos/monitoring/process_collector_psutil.py
----------------------------------------------------------------------
diff --git 
a/src/main/python/apache/thermos/monitoring/process_collector_psutil.py 
b/src/main/python/apache/thermos/monitoring/process_collector_psutil.py
index 3000e95..3594955 100644
--- a/src/main/python/apache/thermos/monitoring/process_collector_psutil.py
+++ b/src/main/python/apache/thermos/monitoring/process_collector_psutil.py
@@ -27,17 +27,18 @@ from .process import ProcessSample
 def process_to_sample(process):
   """ Given a psutil.Process, return a current ProcessSample """
   try:
-    # the nonblocking get_cpu_percent call is stateful on a particular Process 
object, and hence
-    # >2 consecutive calls are required before it will return a non-zero value
-    rate = process.cpu_percent(0.0) / 100.0
-    cpu_times = process.cpu_times()
-    user, system = cpu_times.user, cpu_times.system
-    memory_info = process.memory_info()
-    rss, vms = memory_info.rss, memory_info.vms
-    nice = process.nice()
-    status = process.status()
-    threads = process.num_threads()
-    return ProcessSample(rate, user, system, rss, vms, nice, status, threads)
+    with process.oneshot():
+      # the nonblocking get_cpu_percent call is stateful on a particular 
Process object, and hence
+      # >2 consecutive calls are required before it will return a non-zero 
value
+      rate = process.cpu_percent(0.0) / 100.0
+      cpu_times = process.cpu_times()
+      user, system = cpu_times.user, cpu_times.system
+      memory_info = process.memory_info()
+      rss, vms = memory_info.rss, memory_info.vms
+      nice = process.nice()
+      status = process.status()
+      threads = process.num_threads()
+      return ProcessSample(rate, user, system, rss, vms, nice, status, threads)
   except (AccessDenied, NoSuchProcess) as e:
     log.debug('Error during process sampling [pid=%s]: %s' % (process.pid, e))
     return ProcessSample.empty()

Reply via email to