diff --git a/nbactions.xml b/nbactions.xml index 11bc967..a485118 100644 --- a/nbactions.xml +++ b/nbactions.xml @@ -14,4 +14,19 @@ java + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.5.0:exec + + + -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.mycompany.resourceoptimizer.ResourceOptimizer + java + true + + diff --git a/src/main/java/com/mycompany/resourceoptimizer/HeterogeneousFCO.java b/src/main/java/com/mycompany/resourceoptimizer/HeterogeneousFCO.java index f79b439..274120b 100644 --- a/src/main/java/com/mycompany/resourceoptimizer/HeterogeneousFCO.java +++ b/src/main/java/com/mycompany/resourceoptimizer/HeterogeneousFCO.java @@ -5,8 +5,13 @@ */ package com.mycompany.resourceoptimizer; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -16,48 +21,35 @@ public class HeterogeneousFCO { public HeterogeneousFCO() { + } + public static void insertCurrentRACSV(Map dataDict, FileWriter csvFile) { + try { + csvFile.append(dataDict.get("m2.small").toString()); + csvFile.append(","); + csvFile.append(dataDict.get("m2.medium").toString()); + csvFile.append(","); + csvFile.append(dataDict.get("m2.large").toString()); + csvFile.append("\n"); + } catch (IOException ex) { + Logger.getLogger(ResourceOptimizer.class.getName()).log(Level.SEVERE, null, ex); + } } - public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, int deltaB, Float[] price) { + public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int delta_A, int delta_B, Float[] price) { @SuppressWarnings("UnusedAssignment") float total_cost = 0.0F; try { - // int[][] S1_W = new int[][]{{1, 10, 30, 31, 31, 31}, {1, 10, 30, 50, 51, 51}, {1, 10, 30, 50, 80, 90}}; //aws - t2- micro, small, medium - // int[][] S1_W = new int[][]{{1000, 5000, 10000, 20000, 30000}, - //{1000, 5000, 10000, 20000, 30000}, - //{1000, 5000, 10000, 20000, 30000}}; - //{0, 0, 0, 0, 0}}; - //{0, 0, 0, 0, 0}}; - //int[][] S2_W = new int[][]{{1, 2, 3, 4, 5, 5}, {1, 2, 3, 4, 5, 5}, {1, 2, 3, 4, 5, 6}}; -// int[][] S2_W = new int[][]{{1000, 5000, 10000, 20000, 30000, 40000, 50000, 50001, 50001, 50001, 50001, 50001}, -// {1000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 60001, 60001, 60001, 60001}, -// {1000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}}; - //int[][] S2_W = new int[][]{{1000, 5000, 10000, 20000, 30000, 40000, 50000}, {0, 0, 0, 0, 0, 0, 0}}; - // int[][] S3_W = new int[][]{{1, 5, 10, 15, 18, 19, 19}, {1, 5, 10, 15, 18, 19, 19}, {1, 5, 10, 15, 20, 25, 30}}; -// int[][] S3_W = new int[][]{{1000, 5000, 10000, 10001, 10001, 10001, 10001}, -// {1000, 5000, 10000, 20000, 30000, 30001, 30001}, -// {1000, 5000, 10000, 20000, 30000, 40000, 50000}}; - //int[][] S3_W = new int[][]{{1000, 5000, 10000}, {0, 0, 0}}; - //int[][] S1_Q = new int[][]{{73, 75, 79, 5000, 5000, 5000}, {28, 35, 44, 45, 5000, 5000}, {16, 25, 31, 33, 52, 60}}; -// int[][] S1_Q = new int[][]{{8, 11, 14, 22, 29}, -// {7, 9, 10, 13, 18}, -// {5, 7, 8, 10, 12}}; - // int[][] S1_Q = new int[][]{{8, 11, 14, 22, 29}, {10000, 10000, 10000, 10000, 10000}}; - //int[][] S2_Q = new int[][]{{300, 400, 700, 900, 5000, 5000}, {300, 400, 700, 900, 5000, 5000}, {200, 400, 700, 800, 850, 900}}; -// int[][] S2_Q = new int[][]{{45, 90, 200, 400, 600, 800, 900, 5000, 5000, 5000, 5000, 5000}, -// {30, 60, 200, 400, 500, 600, 800, 900, 5000, 5000, 5000, 5000}, -// {25, 50, 100, 200, 250, 350, 450, 500, 600, 700, 800, 900}}; - // int[][] S2_Q = new int[][]{{45, 90, 200, 400, 600, 800, 900}, {10000, 10000, 10000, 10000, 10000, 10000, 10000}}; - //int[][] S3_Q = new int[][]{{15, 17, 20, 25, 51, 5000, 5000}, {15, 16, 18, 25, 35, 5000, 5000}, {15, 15, 16, 17, 20, 25, 40}}; -// int[][] S3_Q = new int[][]{{2, 20, 260, 5000, 5000, 5000, 5000}, -// {1, 2, 6, 40, 140, 5000, 5000}, -// {1, 1, 2, 4, 9, 25, 120}}; - // int[][] S3_Q = new int[][]{{2, 20, 260}, {10000, 10000, 10000}}; - //Float[] price = new Float[]{0.0146F, 0.0292F, 0.0584F}; //on-demand t2.micro, t2.small and t2.medium price in USD/hr - // Float[] price = new Float[]{0.0292F, 0.0584F, 0.2336F}; - /* - Sustainable QoS profile - AWS and NeCTAR - */ + + /* + //homogeneous across all layers.. + int[][] S1_W = new int[][]{{1000, 5000, 10000, 20000, 30000}, + {0, 0, 0, 0, 0}}; + int[][] S2_W = new int[][]{{1000, 5000, 10000, 20000, 30000, 40000, 50000}, {0, 0, 0, 0, 0, 0, 0}}; + int[][] S3_W = new int[][]{{1000, 5000, 10000}, {0, 0, 0}}; + int[][] S1_Q = new int[][]{{8, 11, 14, 22, 29}, {10000, 10000, 10000, 10000, 10000}}; + int[][] S2_Q = new int[][]{{45, 90, 200, 400, 600, 800, 900}, {10000, 10000, 10000, 10000, 10000, 10000, 10000}}; + int[][] S3_Q = new int[][]{{2, 20, 260}, {10000, 10000, 10000}}; + */ // int[][] S1_W = new int[][]{{1, 10, 30, 31, 31, 31}, {1, 10, 30, 50, 51, 51}, {1, 10, 30, 50, 80, 90}}; //aws - t2- micro, small, medium int[][] S1_W = new int[][]{{1000, 5000, 10000, 20000, 30000}, {1000, 5000, 10000, 20000, 30000}, @@ -82,8 +74,8 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, int[][] S3_Q = new int[][]{{2, 20, 260, 5000, 5000, 5000, 5000}, {1, 2, 6, 40, 140, 5000, 5000}, {1, 1, 2, 4, 9, 25, 120}}; - int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 - int delta_B = deltaB;//GetPropertyFileKeyValues.getDeltaMinBQoS(); //based on minimum latency required in layer 3 + //int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 + //int delta_B = deltaB;//GetPropertyFileKeyValues.getDeltaMinBQoS(); //based on minimum latency required in layer 3 int aggQoS = delta_A + delta_B; List soln = new ArrayList<>(); @@ -162,7 +154,7 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, soln.add(String.valueOf(x) + "x" + inst_type1 + "," + String.valueOf(y) + "x" + inst_type2); totCost.add(x * price[0] + y * price[i + 1]); qos.add(Math.max(S1_Q[0][kk], S1_Q[i + 1][j + 1])); - // totCapacity.add((x * S1_W[0][kk]) + (y * S1_W[i + 1][j + 1])); + // totCapacity.add((x * S1_W[0][kk]) + (y * S1_W[i + 1][j + 1])); } } } @@ -202,7 +194,8 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, nextQoS = qosS1[1]; } // MainForm.txtAreaIngestionResources.append("Instances required for ingestion layer: " + instS1[0] + "\n"); - System.out.println("Instances required for Kafka: " + instS1[0] + "\n"); + //System.out.print("Kafka: " + instS1[0] + ", "); + break; } @@ -239,7 +232,7 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, } } //new code - heterogeneity - String inst_type1 = null; + String inst_type1 = null; String inst_type2 = null; int kk = 0; while (kk < S2_W[0].length - 1) { @@ -270,7 +263,7 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, soln2.add(String.valueOf(x) + "x" + inst_type1 + "," + String.valueOf(y) + "x" + inst_type2); totCost2.add(x * price[0] + y * price[i + 1]); qos2.add(Math.max(S2_Q[0][kk], S2_Q[i + 1][j + 1])); - // totCapacity2.add((x * S2_W[0][kk]) + (y * S2_W[i + 1][j + 1])); + // totCapacity2.add((x * S2_W[0][kk]) + (y * S2_W[i + 1][j + 1])); } } } @@ -303,7 +296,8 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, } aggQoS = aggQoS + qosS2[0]; total_cost = total_cost + costS2[0]; - System.out.println("Instances required for processing layer: " + instS2[0] + "\n"); + //System.out.println("spark: " + instS2[0] + ""); + System.out.println(instS2[0]); break; } case 3: { @@ -339,7 +333,7 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, } } //new code - heterogeneity - String inst_type1 = null; + String inst_type1 = null; String inst_type2 = null; int kk = 0; while (kk < S3_W[0].length - 1) { @@ -404,7 +398,7 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, aggQoS = aggQoS + qosS3[0]; total_cost = total_cost + costS3[0]; - System.out.println("Instances required for storage layer: " + instS3[0] + "\n"); + //System.out.println("cassandra: " + instS3[0] + ""); //System.out.print(instS3[0] + '\t'); // String[] split = instS3[0].split("X"); @@ -417,13 +411,10 @@ public static float FCOStrategy(int w1, int w2, int w3, int e2eQoS, int deltaA, } } - System.out.println("Total cost: " + String.valueOf(total_cost)); - System.out.println("total end-to-end QoS: " + String.valueOf(aggQoS)); - - + // System.out.println("Total cost: " + String.valueOf(total_cost)); + // System.out.println("total end-to-end QoS: " + String.valueOf(aggQoS)); } catch (NumberFormatException ex) { - } return total_cost; diff --git a/src/main/java/com/mycompany/resourceoptimizer/Homogeneous.java b/src/main/java/com/mycompany/resourceoptimizer/Homogeneous.java index a1664eb..5f209f8 100644 --- a/src/main/java/com/mycompany/resourceoptimizer/Homogeneous.java +++ b/src/main/java/com/mycompany/resourceoptimizer/Homogeneous.java @@ -29,33 +29,42 @@ public static float HomogeneousFCO(int w1, int w2, int w3, int e2eQoS, int delta int[][] S1_W = new int[][]{{1000, 5000, 10000, 20000, 30000}, {1000, 5000, 10000, 20000, 30000}, {1000, 5000, 10000, 20000, 30000}}; - //{0, 0, 0, 0, 0}}; - //{0, 0, 0, 0, 0}}; + //int[][] S2_W = new int[][]{{1, 2, 3, 4, 5, 5}, {1, 2, 3, 4, 5, 5}, {1, 2, 3, 4, 5, 6}}; int[][] S2_W = new int[][]{{1000, 5000, 10000, 20000, 30000, 40000, 50000, 50001, 50001, 50001, 50001, 50001}, - {1000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 60001, 60001, 60001, 60001}, - {1000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}}; - // int[][] S2_W = new int[][]{{1000, 5000, 10000, 20000, 30000, 40000, 50000}, {0, 0, 0, 0, 0, 0, 0}}; + {1000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 60001, 60001, 60001, 60001}, + {1000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}}; + // int[][] S3_W = new int[][]{{1, 5, 10, 15, 18, 19, 19}, {1, 5, 10, 15, 18, 19, 19}, {1, 5, 10, 15, 20, 25, 30}}; int[][] S3_W = new int[][]{{1000, 5000, 10000, 10001, 10001, 10001, 10001}, {1000, 5000, 10000, 20000, 30000, 30001, 30001}, {1000, 5000, 10000, 20000, 30000, 40000, 50000}}; - //int[][] S3_W = new int[][]{{1000, 5000, 10000}, {0, 0, 0}}; + //int[][] S1_Q = new int[][]{{73, 75, 79, 5000, 5000, 5000}, {28, 35, 44, 45, 5000, 5000}, {16, 25, 31, 33, 52, 60}}; int[][] S1_Q = new int[][]{{8, 11, 14, 22, 29}, {7, 9, 10, 13, 18}, {5, 7, 8, 10, 12}}; - //int[][] S1_Q = new int[][]{{8, 11, 14, 22, 29}, {10000, 10000, 10000, 10000, 10000}}; + //int[][] S2_Q = new int[][]{{300, 400, 700, 900, 5000, 5000}, {300, 400, 700, 900, 5000, 5000}, {200, 400, 700, 800, 850, 900}}; int[][] S2_Q = new int[][]{{45, 90, 200, 400, 600, 800, 900, 5000, 5000, 5000, 5000, 5000}, {30, 60, 200, 400, 500, 600, 800, 900, 5000, 5000, 5000, 5000}, {25, 50, 100, 200, 250, 350, 450, 500, 600, 700, 800, 900}}; - //int[][] S2_Q = new int[][]{{45, 90, 200, 400, 600, 800, 900}, {10000, 10000, 10000, 10000, 10000, 10000, 10000}}; + //int[][] S3_Q = new int[][]{{15, 17, 20, 25, 51, 5000, 5000}, {15, 16, 18, 25, 35, 5000, 5000}, {15, 15, 16, 17, 20, 25, 40}}; int[][] S3_Q = new int[][]{{2, 20, 260, 5000, 5000, 5000, 5000}, {1, 2, 6, 40, 140, 5000, 5000}, {1, 1, 2, 4, 9, 25, 120}}; - //int[][] S3_Q = new int[][]{{2, 20, 260}, {10000, 10000, 10000}}; + /* + //homogeneous across all layers.. + int[][] S1_W = new int[][]{{1000, 5000, 10000, 20000, 30000}, + {0, 0, 0, 0, 0}}; + int[][] S2_W = new int[][]{{1000, 5000, 10000, 20000, 30000, 40000, 50000}, {0, 0, 0, 0, 0, 0, 0}}; + int[][] S3_W = new int[][]{{1000, 5000, 10000}, {0, 0, 0}}; + int[][] S1_Q = new int[][]{{8, 11, 14, 22, 29}, {10000, 10000, 10000, 10000, 10000}}; + int[][] S2_Q = new int[][]{{45, 90, 200, 400, 600, 800, 900}, {10000, 10000, 10000, 10000, 10000, 10000, 10000}}; + int[][] S3_Q = new int[][]{{2, 20, 260}, {10000, 10000, 10000}}; + */ + //Float[] price = new Float[]{0.0146F, 0.0292F, 0.0584F}; //on-demand t2.micro, t2.small and t2.medium price in USD/hr // Float[] price = new Float[]{0.0292F, 0.0584F, 0.2336F}; int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 @@ -279,9 +288,7 @@ public static float HomogeneousFCO(int w1, int w2, int w3, int e2eQoS, int delta System.out.println("Total cost: " + String.valueOf(total_cost)); System.out.println("total end-to-end QoS: " + String.valueOf(aggQoS)); - } catch (NumberFormatException ex) { - } return total_cost; diff --git a/src/main/java/com/mycompany/resourceoptimizer/HomogeneousDCO.java b/src/main/java/com/mycompany/resourceoptimizer/HomogeneousDCO.java deleted file mode 100644 index 91bf560..0000000 --- a/src/main/java/com/mycompany/resourceoptimizer/HomogeneousDCO.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.mycompany.resourceoptimizer; - -/** - * - * @author Sunil - */ -public class HomogeneousDCO { - public HomogeneousDCO(){ - - } - - -} diff --git a/src/main/java/com/mycompany/resourceoptimizer/ResourceOptimizer.java b/src/main/java/com/mycompany/resourceoptimizer/ResourceOptimizer.java index a64fbc0..3ffdb85 100644 --- a/src/main/java/com/mycompany/resourceoptimizer/ResourceOptimizer.java +++ b/src/main/java/com/mycompany/resourceoptimizer/ResourceOptimizer.java @@ -57,8 +57,8 @@ public ResourceOptimizer() { static FileWriter processingRA = null; static FileWriter storageRA = null; - public static int[] read() throws IOException { - File inputWorkbook = new File("D:\\dpp.xls"); + public static int[] read(String path) throws IOException { + File inputWorkbook = new File(path); Workbook w; int[] dataArr = null; try { @@ -73,6 +73,26 @@ public static int[] read() throws IOException { } } catch (BiffException e) { } + + return dataArr; + } + + public static Float[] readPrice(String path) throws IOException { + File inputWorkbook = new File(path); + Workbook w; + Float[] dataArr = null; + try { + w = Workbook.getWorkbook(inputWorkbook); + Sheet sheet = w.getSheet(0); + dataArr = new Float[sheet.getRows()]; + for (int j = 0; j < sheet.getColumns(); j++) { + for (int i = 0; i < sheet.getRows(); i++) { + Cell cell = sheet.getCell(j, i); + dataArr[i] = Float.parseFloat(cell.getContents()); + } + } + } catch (BiffException e) { + } return dataArr; } @@ -94,14 +114,12 @@ public static boolean checkForEmptyAllocation(Map resourceAlloc return true; } else if (resourceAllocation.get("m2.medium") > 0) { return true; - } else if (resourceAllocation.get("m2.large") > 0) { - return true; } else { - return false; + return resourceAllocation.get("m2.large") > 0; } } - public static float DCOHomogeneous(int w1, int w2, int w3, int e2eQoS, int deltaA, int deltaB, Float[] price, boolean init, boolean ingSO, boolean ingSI, boolean proSO, boolean proSI, boolean stoSO, boolean stoSI) { + public static float DCOHomogeneous(int w1, int w2, int w3, int e2eQoS, int delta_A, int delta_B, Float[] price, boolean init, boolean ingSO, boolean ingSI, boolean proSO, boolean proSI, boolean stoSO, boolean stoSI) { @SuppressWarnings("UnusedAssignment") float total_cost = 0.0F; @@ -141,9 +159,8 @@ public static float DCOHomogeneous(int w1, int w2, int w3, int e2eQoS, int delta int[][] S3_W = new int[][]{{1000, 5000, 10000}, {0, 0, 0}}; int[][] S3_Q = new int[][]{{2, 20, 260}, {10000, 10000, 10000}}; */ - int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 - int delta_B = deltaB;//GetPropertyFileKeyValues.getDeltaMinBQoS(); //based on minimum latency required in layer 3 - + //int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 + //int delta_B = deltaB;//GetPropertyFileKeyValues.getDeltaMinBQoS(); //based on minimum latency required in layer 3 int aggQoS = delta_A + delta_B; List soln = new ArrayList<>(); List totCost = new ArrayList<>(); @@ -909,8 +926,9 @@ else if (proSO) { } } + //DCO strategy - includes resource and contract heterogeneity - public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, int deltaB, Float[] price, boolean init, boolean ingSO, boolean ingSI, boolean proSO, boolean proSI, boolean stoSO, boolean stoSI) throws IOException { + public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int delta_A, int delta_B, Float[] price, boolean init, boolean ingSO, boolean ingSI, boolean proSO, boolean proSI, boolean stoSO, boolean stoSI) throws IOException { @SuppressWarnings("UnusedAssignment") float total_cost = 0.0F; @@ -939,8 +957,8 @@ public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, int[][] S3_Q = new int[][]{{2, 20, 260, 5000, 5000, 5000, 5000}, {1, 2, 6, 40, 140, 5000, 5000}, {1, 1, 2, 4, 9, 25, 120}}; - int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 - int delta_B = deltaB;//GetPropertyFileKeyValues.getDeltaMinBQoS(); //based on minimum latency required in layer 3 + //int delta_A = deltaA;//GetPropertyFileKeyValues.getDeltaMinAQoS(); //based on the minimum latency required in layer 2 + //int delta_B = deltaB;//GetPropertyFileKeyValues.getDeltaMinBQoS(); //based on minimum latency required in layer 3 int aggQoS = delta_A + delta_B; List soln = new ArrayList<>(); @@ -1079,7 +1097,7 @@ public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, insertCurrentRACSV(ingestion_resources, ingestionRA); } else { if (ingSI) { - if (!(current_capacity_ingestion == capacityS1[0])) { + if (current_capacity_ingestion > capacityS1[0]) { if (instS1[0].indexOf(',') != -1) { String[] extStr = instS1[0].split(","); for (String dt : extStr) { @@ -1148,7 +1166,7 @@ public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, String[] split = instS1[0].split("x"); if (ingestion_resources.get(split[1]) == Integer.parseInt(split[0])) { ingestion_resources.put(split[1], ingestion_resources.get(split[1]) - Integer.parseInt(split[0])); - if (checkForEmptyAllocation(ingestion_resources)) { + if (checkForEmptyAllocation(ingestion_resources)) { //to check if other instances are present in the cluster current_capacity_ingestion = current_capacity_ingestion - capacityS1[0]; @@ -1163,7 +1181,7 @@ public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, } insertCurrentRACSV(ingestion_resources, ingestionRA); - } else { + } else { //if only one instance of same type present the scale-in is disabled and next allocation remains same as the current ingestion_resources.put(split[1], ingestion_resources.get(split[1]) + Integer.parseInt(split[0])); if (ingestion_resources.get("m2.small") > 0) { previous_Period_total_cost = previous_Period_total_cost + price[0] * ingestion_resources.get("m2.small"); @@ -1374,7 +1392,7 @@ public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, } // total_cost = total_cost + costS1[0]; else { if (proSI) { - if (!(current_capacity_processing == capacityS2[0])) { + if (current_capacity_processing > capacityS2[0]) { if (instS2[0].indexOf(',') != -1) { String[] extStr = instS2[0].split(","); for (String dt : extStr) { @@ -1484,7 +1502,7 @@ public static float DCOStratgey(int w1, int w2, int w3, int e2eQoS, int deltaA, } insertCurrentRACSV(processing_resources, processingRA); - } else { + } else { // if scale-in instance type differs from current instance type then allocation remains same. if (processing_resources.get("m2.small") > 0) { previous_Period_total_cost = previous_Period_total_cost + price[0] * processing_resources.get("m2.small"); } @@ -1666,7 +1684,7 @@ else if (proSO) { } // total_cost = total_cost + costS1[0]; else { if (stoSI) { - if (!(current_capacity_storage == capacityS3[0])) { + if (current_capacity_storage > capacityS3[0]) { if (instS3[0].indexOf(',') != -1) { String[] extStr = instS3[0].split(","); for (String dt : extStr) { @@ -1746,7 +1764,7 @@ else if (proSO) { } insertCurrentRACSV(storage_resources, storageRA); - } else { + } else {//instance to remove and current instance are same (no and type) so no change in allocation. storage_resources.put(split[1], storage_resources.get(split[1]) + Integer.parseInt(split[0])); if (storage_resources.get("m2.small") > 0) { previous_Period_total_cost = previous_Period_total_cost + price[0] * storage_resources.get("m2.small"); @@ -1843,7 +1861,6 @@ else if (proSO) { System.out.println("total end-to-end QoS: " + String.valueOf(aggQoS)); System.out.println("Total cost: " + String.valueOf(previous_Period_total_cost)); - } catch (NumberFormatException ex) { System.out.println("Error:" + ex.getMessage()); @@ -1858,13 +1875,15 @@ else if (proSO) { } public static void main(String args[]) throws IOException { - Float[] price = {0.0385F, 0.0928F, 0.1856F}; //OD + //Float[] price = {0.0385F, 0.0928F, 0.1856F}; //OD Ohio + Float[] price = new Float[3]; // {0.048F, 0.1168F, 0.2336F}; //OD Sydney float totalCost = 0.0F; - //Float[] price = {0.032F, 0.065F, 0.13F}; //SB - 6hrs - // Float[] price = {0.032F, 0.0928F, 0.1856F}; //mixed - first spot block, 2 -ODs - //Float[] price = {0.032F, 0.065F, 0.1856F}; // mixed - 2 SB , 1 OD - // Float[] price = {0.0385F, 0.065F, 0.13F}; //mixed - 1OD, 2 SB - //Float[] price = {0.0385F, 0.0928F}; //OD - homogeneous across all layers + //Float[] price = {0.032F, 0.065F, 0.13F}; //SB - 6hrs Ohio + //Float[] price = {0.019F, 0.035F, 0.0701F}; //Spot Sydeny + // Float[] price = {0.048F, 0.1168F, 0.2336F}; //mixed - first spot, 2 -ODs + //Float[] price = {0.019F, 0.035F, 0.0701F}; // mixed - 2 Spots , 1 OD + // Float[] price = {0.048F, 0.035F, 0.0701F}; //mixed - 1OD, 2 SB + //Float[] price = {0.048F, 0.1168F}; //OD - homogeneous across all layers ingestion_resources.put("m2.small", 0); ingestion_resources.put("m2.medium", 0); ingestion_resources.put("m2.large", 0); @@ -1910,45 +1929,53 @@ public static void main(String args[]) throws IOException { current_allocation_ingestion = current_allocation_processing = current_allocation_storage = null; previous_Period_total_cost = 0.0F; boolean ingSO, ingSI, proSO, proSI, stoSO, stoSI; - int[] workloads = read(); //read workload data from excel file - 31 days NYC taxi data. + + int[] workloads = read("D:\\dpp.xls"); //read workload data from a file - 31 days NYC taxi data. + Float[] mediumInstPrice = readPrice("D:\\m6g_mediumPriceOD.xls"); // m6g_mediumPriceOD , m6g_mediumPriceSpot + Float[] largeInstPrice = readPrice("D:\\t2_largePriceOD.xls");// t2_largePriceOD , t2_largePriceSpot + Float[] xlargeInstPrice = readPrice("D:\\t2_xlargePriceOD.xls"); // t2_xlargePriceOD, t2_xlargePriceSpot int w1, w2, w3; System.out.println("Select stratgey:(DCO/FCO)"); String strategy = scanner.next(); + System.out.println("Resource homogeneity or heterogeneity: (Ho/He)"); + String option = scanner.next(); if (null == strategy) { System.out.println("Please select an appropriate scaling strategy option:"); } else { switch (strategy) { case "DCO": -// for (int i = 0; i < price.length; i++) { -// System.out.println("Enter price for instance0" + (i + 1) + ":"); -// price[i] = scanner.nextFloat(); -// } -// do { -// -// System.out.println("Enter workload for ingestion layer:"); -// int w1 = scanner.nextInt(); -// System.out.println("Enter workload for processing layer"); -// int w2 = scanner.nextInt(); -// System.out.println("Enter workload for storage layer"); -// int w3 = scanner.nextInt(); -// getResourceAllocation(w1, w2, w3, e2eQoS, deltaA, deltaB, price); -// //MKPSolver.MKPSolver(w1, w2, w3, e2eQoS, deltaA, deltaB, price); -// System.out.println("Do you want to continue?"); -// choice = scanner.next(); -// } while ("yes".equals(choice) || "y".equals(choice)); case "dco": for (int i = 0; i < workloads.length; i++) { if (i == 0) { w3 = (int) (0.25 * workloads[i]); - DCOStratgey(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price, true, false, false, false, false, false, false); - //DCOHomogeneous(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price, true, false, false, false, false, false, false); + price[0] = mediumInstPrice[i]; + price[1] = largeInstPrice[i]; + price[2] = xlargeInstPrice[i]; + if (null == option) { + System.out.println("Please select appropriate heterogeneity option:"); + } else { + switch (option) { + case "he": + DCOStratgey(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price, true, false, false, false, false, false, false); + break; + case "ho": + DCOHomogeneous(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price, true, false, false, false, false, false, false); + break; + default: + System.out.println("Please select appropriate heterogeneity option:"); + break; + } + } } else { + price[0] = mediumInstPrice[i]; + price[1] = largeInstPrice[i]; + price[2] = xlargeInstPrice[i]; if (current_capacity_ingestion > workloads[i]) { - ingSI = true; + ingSI = true; //scale-in ingSO = false; w1 = current_capacity_ingestion - workloads[i]; } else if (current_capacity_ingestion < workloads[i]) { - ingSO = true; + ingSO = true; //scale-out ingSI = false; w1 = workloads[i] - current_capacity_ingestion; } else { @@ -1956,12 +1983,12 @@ public static void main(String args[]) throws IOException { w1 = 0; } if (current_capacity_processing > workloads[i]) { - proSI = true; + proSI = true; //scale-in proSO = false; w2 = current_capacity_processing - workloads[i]; } else if (current_capacity_processing < workloads[i]) { - proSO = true; + proSO = true; //scale-out proSI = false; w2 = workloads[i] - current_capacity_processing; } else { @@ -1981,31 +2008,65 @@ public static void main(String args[]) throws IOException { stoSO = stoSI = false; w3 = 0; } - DCOStratgey(w1, w2, w3, e2eQoS, deltaA, deltaB, price, false, ingSO, ingSI, proSO, proSI, stoSO, stoSI); - //DCOHomogeneous(w1, w2, w3, e2eQoS, deltaA, deltaB, price, false, ingSO, ingSI, proSO, proSI, stoSO, stoSI); + if (null == option) { + System.out.println("Please select appropriate heterogeneity option:"); + } else { + switch (option) { + case "he": + DCOStratgey(w1, w2, w3, e2eQoS, deltaA, deltaB, price, false, ingSO, ingSI, proSO, proSI, stoSO, stoSI); + break; + case "ho": + DCOHomogeneous(w1, w2, w3, e2eQoS, deltaA, deltaB, price, false, ingSO, ingSI, proSO, proSI, stoSO, stoSI); + break; + default: + System.out.println("Please select appropriate heterogeneity option:"); + break; + } + } } } System.out.println("Total cost of RA using DCO:" + previous_Period_total_cost); break; case "FCO": case "fco": + long startTime = System.currentTimeMillis(); for (int i = 0; i < workloads.length; i++) { w3 = (int) (0.25 * workloads[i]); - totalCost = totalCost + HeterogeneousFCO.FCOStrategy(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price); - //totalCost = totalCost + Homogeneous.HomogeneousFCO(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price); + price[0] = mediumInstPrice[i]; + price[1] = largeInstPrice[i]; + price[2] = xlargeInstPrice[i]; + if (null == option) { + System.out.println("Please select appropriate heterogeneity option:"); + } else { + switch (option) { + case "he": + totalCost = totalCost + HeterogeneousFCO.FCOStrategy(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price); + break; + case "ho": + totalCost = totalCost + Homogeneous.HomogeneousFCO(workloads[i], workloads[i], w3, e2eQoS, deltaA, deltaB, price); + break; + default: + System.out.println("Please select appropriate heterogeneity option:"); + break; + } + } + } + long endTime = System.currentTimeMillis(); + System.out.println("Total time taken to find cost-optimal solution(ms):" + (endTime - startTime) + ""); System.out.println("Total cost of RA using FCO:" + totalCost); + //System.out.println("Total time taken to find cost-optimal solution(ms): " + duration); break; default: System.out.println("Please select an appropriate scaling strategy option:"); break; } } - ingestionRA.flush(); - ingestionRA.close(); - processingRA.flush(); - processingRA.close(); - storageRA.flush(); - storageRA.close(); + ingestionRA.flush(); + ingestionRA.close(); + processingRA.flush(); + processingRA.close(); + storageRA.flush(); + storageRA.close(); } }