small refactoring as preparation for overprovisioning RM
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 26 Apr 2016 13:35:07 +0000 (15:35 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 26 Apr 2016 13:35:07 +0000 (15:35 +0200)
src/emuvim/dcemulator/resourcemodel/upb/simple.py

index da76b96..181bc97 100644 (file)
@@ -126,10 +126,8 @@ class UpbSimpleCloudDcRM(BaseResourceModel):
         :return:
         """
         number_cu = self._get_flavor(d).get("compute")
-        # get cpu time fraction for entire emulation
-        e_cpu = self.registrar.e_cpu
         # calculate cpu time fraction of a single compute unit
-        self.single_cu = float(e_cpu) / sum([rm.dc_max_cu for rm in list(self.registrar.resource_models)])
+        self.single_cu = self._compute_single_cu()
         # calculate cpu time fraction for container with given flavor
         cpu_time_percentage = self.single_cu * number_cu
         # calculate input values for CFS scheduler bandwidth limitation
@@ -140,6 +138,16 @@ class UpbSimpleCloudDcRM(BaseResourceModel):
                       d.name, cpu_period, cpu_time_percentage, cpu_quota))
             d.updateCpuLimit(cpu_period=int(cpu_period), cpu_quota=int(cpu_quota))
 
+    def _compute_single_cu(self):
+        """
+        Calculate percentage of CPU time of a singe CU unit.
+        :return:
+        """
+        # get cpu time fraction for entire emulation
+        e_cpu = self.registrar.e_cpu
+        # calculate
+        return float(e_cpu) / sum([rm.dc_max_cu for rm in list(self.registrar.resource_models)])
+
     def _calculate_cpu_cfs_values(self, cpu_time_percentage):
         """
         Calculate cpu period and quota for CFS