+ def _calculate_cpu_cfs_values(self, cpu_time_percentage):
+ """
+ Calculate cpu period and quota for CFS
+ :param cpu_time_percentage: percentage of overall CPU to be used
+ :return: cpu_period, cpu_quota
+ """
+ if cpu_time_percentage is None:
+ return -1, -1
+ if cpu_time_percentage < 0:
+ return -1, -1
+ # (see: https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt)
+ # Attention minimum cpu_quota is 1ms (micro)
+ cpu_period = 1000000 # lets consider a fixed period of 1000000 microseconds for now
+ LOG.debug("cpu_period is %r, cpu_percentage is %r" % (cpu_period, cpu_time_percentage))
+ cpu_quota = cpu_period * cpu_time_percentage # calculate the fraction of cpu time for this container
+ # ATTENTION >= 1000 to avoid a invalid argument system error ... no idea why
+ if cpu_quota < 1000:
+ LOG.debug("cpu_quota before correcting: %r" % cpu_quota)
+ cpu_quota = 1000
+ LOG.warning("Increased CPU quota to avoid system error.")
+ LOG.debug("Calculated: cpu_period=%f / cpu_quota=%f" % (cpu_period, cpu_quota))
+ return int(cpu_period), int(cpu_quota)
+