You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "DaanHoogland (via GitHub)" <gi...@apache.org> on 2024/01/18 08:07:30 UTC

Re: [PR] Add advance settings to fine tune DRS imbalance calculation [cloudstack]

DaanHoogland commented on code in PR #8521:
URL: https://github.com/apache/cloudstack/pull/8521#discussion_r1457066252


##########
api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithm.java:
##########
@@ -87,36 +90,65 @@ Ternary<Double, Double, Double> getMetrics(long clusterId, VirtualMachine vm, Se
      *         the virtual machine being migrated
      * @param destHost
      *         the destination host for the virtual machine
-     * @param hostCpuFreeMap
-     *         a map of host IDs to the amount of CPU free on each host
-     * @param hostMemoryFreeMap
-     *         a map of host IDs to the amount of memory free on each host
+     * @param hostCpuMap
+     *         a map of host IDs to the Ternary of used, reserved and total CPU on each host
+     * @param hostMemoryMap
+     *         a map of host IDs to the Ternary of used, reserved and total memory on each host
      *
      * @return a pair containing the CPU and memory imbalance of the cluster after the migration
      */
-    default Pair<Double, Double> getImbalancePostMigration(ServiceOffering serviceOffering, VirtualMachine vm,
-                                                           Host destHost, Map<Long, Pair<Long, Long>> hostCpuFreeMap,
-                                                           Map<Long, Pair<Long, Long>> hostMemoryFreeMap) {
-        List<Double> postCpuList = new ArrayList<>();
-        List<Double> postMemoryList = new ArrayList<>();
-        final int vmCpu = serviceOffering.getCpu() * serviceOffering.getSpeed();
-        final long vmRam = serviceOffering.getRamSize() * 1024L * 1024L;
-
-        for (Long hostId : hostCpuFreeMap.keySet()) {
-            long cpu = hostCpuFreeMap.get(hostId).first();
-            long memory = hostMemoryFreeMap.get(hostId).first();
+    default Double getImbalancePostMigration(ServiceOffering serviceOffering, VirtualMachine vm,
+                                                           Host destHost, Map<Long, Ternary<Long, Long, Long>> hostCpuMap,
+                                                           Map<Long, Ternary<Long, Long, Long>> hostMemoryMap) throws ConfigurationException {
+        String metric = ClusterDrsMetric.valueIn(destHost.getClusterId());
+        long vmMetric;
+        Map<Long, Ternary<Long, Long, Long>> hostMetricsMap;
+        switch (metric) {
+            case "cpu":
+                hostMetricsMap = hostCpuMap;
+                vmMetric = (long) serviceOffering.getCpu() * serviceOffering.getSpeed();
+                break;
+            case "memory":
+                hostMetricsMap = hostMemoryMap;
+                vmMetric = serviceOffering.getRamSize() * 1024L * 1024L;
+                break;
+            default:
+                throw new ConfigurationException(
+                        String.format("Invalid metric: %s for cluster: %d", metric, destHost.getClusterId()));
+        }

Review Comment:
   could be a `setMetricsMapAndType()`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org