Skip to content

Commit

Permalink
Try and fix query_cpu()
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdp committed Oct 22, 2023
1 parent cbd5ce9 commit f99f9f7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/src/backend/experiments/calc_surf_isec_inmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,20 @@ async def calc_surf_isec_inmem(


def query_cpu():
cpu_quota = -1
avail_cpu = -1

if os.path.isfile('/sys/fs/cgroup/cpu/cpu.cfs_quota_us'):
cpu_quota = int(open('/sys/fs/cgroup/cpu/cpu.cfs_quota_us').read().rstrip())
#print(cpu_quota) # Not useful for AWS Batch based jobs as result is -1, but works on local linux systems
print(cpu_quota) # Not useful for AWS Batch based jobs as result is -1, but works on local linux systems

if cpu_quota != -1 and os.path.isfile('/sys/fs/cgroup/cpu/cpu.cfs_period_us'):
cpu_period = int(open('/sys/fs/cgroup/cpu/cpu.cfs_period_us').read().rstrip())
#print(cpu_period)
print(cpu_period)
avail_cpu = int(cpu_quota / cpu_period) # Divide quota by period and you should get num of allotted CPU to the container, rounded down if fractional.
elif os.path.isfile('/sys/fs/cgroup/cpu/cpu.shares'):
cpu_shares = int(open('/sys/fs/cgroup/cpu/cpu.shares').read().rstrip())
#print(cpu_shares) # For AWS, gives correct value * 1024.
print(cpu_shares) # For AWS, gives correct value * 1024.
avail_cpu = int(cpu_shares / 1024)

return avail_cpu

0 comments on commit f99f9f7

Please sign in to comment.