Skip to content

Commit

Permalink
psutil 1.2.1 has issue with large number of cores (giampaolo/psutil#522
Browse files Browse the repository at this point in the history
…). Since OpenStack uses this version of psutil, we cannot use the latest version that solves this problem. Instead, we use other library, cpu-affinity, to get the CPU affinity
  • Loading branch information
krha committed Sep 22, 2015
1 parent c4e259c commit 4fdfd1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions elijah/provisioning/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ def set_num_cores(num_cores):
p = psutil.Process()
desired_cpus = list(range(num_cores))
p.set_cpu_affinity(desired_cpus)
updated_cpu = p.get_cpu_affinity()
try:
# psutil 1.2.1 has issue with large number of cores
# https://github.com/giampaolo/psutil/issues/522
updated_cpu = p.get_cpu_affinity()
except OSError as e:
updated_cpu = desired_cpus
pass
if desired_cpus != updated_cpu:
raise Exception(
"Cannot not set affinity mask: from %s to %s" %
Expand All @@ -248,7 +254,14 @@ def get_num_cores():
if version >= (2, 0):
return len(p.cpu_affinity())
else:
return len(p.get_cpu_affinity())
try:
# psutil 1.2.1 has issue with large number of cores
# https://github.com/giampaolo/psutil/issues/522
cores = len(p.get_cpu_affinity())
except OSError as e:
import affinity
cores = len(affinity.sched_getaffinity(p.pid))
return cores

def get_mode_id(self):
sorted_key = sorted(self.__dict__.keys())
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ bsdiff4==1.1.4
Cython==0.21.2
psutil>=2.2.1
testtools>=1.8.0
cpu-affinity>=0.1.0

0 comments on commit 4fdfd1b

Please sign in to comment.