Description: It performs a performance evaluation of a container-based cloud computing environment using ContainerCloudSim. It simulates a cloud data center consisting of multiple hosts, each running virtual machines (VMs) that host containers executing cloudlets (tasks). The program uses energy-aware VM allocation and container scheduling policies while collecting detailed performance metrics. During the simulation, it tracks metrics such as the number of completed cloudlets, success rate, makespan, average response time, average latency, average bandwidth usage, and SLA violations. After the simulation, these metrics are calculated and printed to provide a comprehensive analysis of system performance, helping to assess efficiency, resource utilization, and service quality in a containerized cloud environment.
package containercloudsim;
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.container.containerProvisioners.*;
import org.cloudbus.cloudsim.container.containerVmProvisioners.*;
import org.cloudbus.cloudsim.container.core.*;
import org.cloudbus.cloudsim.container.hostSelectionPolicies.*;
import org.cloudbus.cloudsim.container.resourceAllocators.*;
import org.cloudbus.cloudsim.container.resourceAllocatorMigrationEnabled .PowerContainerVmAllocationPolicyMigrationAbstractHostSelection;
import org.cloudbus.cloudsim.container.schedulers.*;
import org.cloudbus.cloudsim.container.utils.IDs;
import org.cloudbus.cloudsim.container.vmSelectionPolicies.*;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.examples.container.ConstantsExamples;
import org.cloudbus.cloudsim.examples.container.UtilizationModelPlanetLabInMemoryExtended;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;
import java.util.*;
public class PerformanceEvaluation {
private static List vmList;
private static List containerList;
private static List cloudletList;
private static List hostList;
private static ContainerDatacenter datacenter;
private static ContainerDatacenterBroker broker;
// Metrics collection
private static double totalCost = 0.0;
private static double totalEnergy = 0.0;
private static double makespan = 0.0;
private static double totalResponseTime = 0.0;
private static double totalLatency = 0.0;
private static double totalBandwidth = 0.0;
private static int slaViolations = 0;
private static int completedCloudlets = 0;
public static void main(String[] args) {
Log.printLine("Starting ContainerCloudSim Exercise...");
try {
// First step: Initialize the CloudSim package
int numUsers = 1;
Calendar calendar = Calendar.getInstance();
boolean traceFlag = false;
CloudSim.init(numUsers, calendar, traceFlag);
// Second step: Create Datacenter
ContainerAllocationPolicy containerAllocationPolicy = new PowerContainerAllocationPolicySimple();
PowerContainerVmSelectionPolicy vmSelectionPolicy = new PowerContainerVmSelectionPolicyMaximumUsage();
HostSelectionPolicy hostSelectionPolicy = new HostSelectionPolicyFirstFit();
double overUtilizationThreshold = 0.80;
double underUtilizationThreshold = 0.70;
// Create host list
hostList = createHostList(5); // 5 hosts
// Create VM allocation policy
ContainerVmAllocationPolicy vmAllocationPolicy = new PowerContainerVmAllocationPolicyMigrationAbstractHostSelection(
hostList, vmSelectionPolicy, hostSelectionPolicy,
overUtilizationThreshold, underUtilizationThreshold);
// Third step: Create Broker with overbooking factor
int overBookingFactor = 80;
broker = createBroker(overBookingFactor);
int brokerId = broker.getId();
// Fourth step: Create VMs, Containers and Cloudlets
vmList = createVmList(brokerId, 10); // 10 VMs
containerList = createContainerList(brokerId, 20); // 20 containers
cloudletList = createContainerCloudletList(brokerId, 20); // 20 cloudlets
// Create datacenter
String experimentName = getExperimentName("ContainerCloudSimExercise", String.valueOf(overBookingFactor));
String logAddress = "~/Results";
datacenter = (PowerContainerDatacenter) createDatacenter(
"Datacenter_1", PowerContainerDatacenterCM.class,
hostList, vmAllocationPolicy, containerAllocationPolicy,
experimentName, ConstantsExamples.SCHEDULING_INTERVAL,
logAddress, ConstantsExamples.VM_STARTTUP_DELAY,
ConstantsExamples.CONTAINER_STARTTUP_DELAY);
// Submit VMs, containers and cloudlets to the broker
broker.submitVmList(vmList);
broker.submitContainerList(containerList);
broker.submitCloudletList(cloudletList);
// Fifth step: Starts the simulation
CloudSim.terminateSimulation(86400.00); // 24 hours simulation
CloudSim.startSimulation();
// Final step: Print results when simulation is over
List newList = broker.getCloudletReceivedList();
CloudSim.stopSimulation();
// Calculate all metrics
calculateMetrics(newList);
// Print comprehensive results
printCloudletList(newList);
printComprehensiveMetrics();
Log.printLine("ContainerCloudSim Exercise finished!");
} catch (Exception e) {
e.printStackTrace();
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
private static void calculateMetrics(List cloudletList) {
completedCloudlets = 0;
totalResponseTime = 0.0;
totalLatency = 0.0;
makespan = 0.0;
slaViolations = 0;
// SLA parameters
final double MAX_RESPONSE_TIME_SLA = 1000.0; // 1000 seconds max response time
final double MAX_LATENCY_SLA = 50.0; // 50 seconds max latency
for (ContainerCloudlet cloudlet : cloudletList) {
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
completedCloudlets++;
// Calculate response time (submission to start execution)
double responseTime = cloudlet.getFinishTime() - cloudlet.getExecStartTime();
totalResponseTime += responseTime;
// Calculate latency (approximated as response time for this simulation)
double latency = responseTime;
totalLatency += latency;
// Calculate makespan (maximum finish time)
if (cloudlet.getFinishTime() > makespan) {
makespan = cloudlet.getFinishTime();
}
// Check SLA violations
if (responseTime > MAX_RESPONSE_TIME_SLA || latency > MAX_LATENCY_SLA) {
slaViolations++;
}
}
}
// Calculate energy consumption
calculateEnergyConsumption();
// Calculate cost
calculateCost();
// Calculate bandwidth (average)
calculateBandwidth();
}
private static void calculateEnergyConsumption() {
totalEnergy = 0.0;
for (ContainerHost host : hostList) {
if (host instanceof PowerContainerHost) {
PowerContainerHost powerHost = (PowerContainerHost) host;
totalEnergy += powerHost.getPower();
}
}
}
private static void calculateCost() {
totalCost = 0.0;
// VM cost calculation
for (ContainerVm vm : vmList) {
if (vm.getHost() != null) {
double vmRuntime = makespan; // Simplified - using makespan as runtime
double vmCost = vmRuntime * 0.05; // $0.05 per second
totalCost += vmCost;
}
}
// Storage cost
double storageCost = makespan * 0.001; // $0.001 per second
totalCost += storageCost;
// Bandwidth cost
double bandwidthCost = totalBandwidth * 0.0001; // $0.0001 per MB
totalCost += bandwidthCost;
// Energy cost (assuming $0.15 per kWh)
double energyCostKWh = totalEnergy / 3600000.0; // Convert joules to kWh
totalCost += energyCostKWh * 0.15;
// SLA violation penalties
double slaPenalty = slaViolations * 10.0; // $10 per violation
totalCost += slaPenalty;
}
private static void calculateBandwidth() {
totalBandwidth = 0.0;
for (ContainerCloudlet cloudlet : cloudletList) {
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
// Estimate bandwidth usage based on cloudlet characteristics
double bandwidthUsage = cloudlet.getCloudletFileSize() + cloudlet.getCloudletOutputSize();
totalBandwidth += bandwidthUsage;
}
}
}
private static void printComprehensiveMetrics() {
DecimalFormat df = new DecimalFormat("###.##");
Log.printLine("\n========== COMPREHENSIVE METRICS ANALYSIS ==========");
// Basic statistics
Log.printLine("Completed Cloudlets: " + completedCloudlets + "/" + cloudletList.size());
Log.printLine("Success Rate: " + df.format((completedCloudlets * 100.0) / cloudletList.size()) + "%");
// Performance metrics
if (completedCloudlets > 0) {
double avgResponseTime = totalResponseTime / completedCloudlets;
double avgLatency = totalLatency / completedCloudlets;
double avgBandwidth = totalBandwidth / completedCloudlets;
Log.printLine("Makespan: " + df.format(makespan) + " seconds");
Log.printLine("Average Response Time: " + df.format(avgResponseTime) + " seconds");
Log.printLine("Average Latency: " + df.format(avgLatency) + " seconds");
Log.printLine("Average Bandwidth Usage: " + df.format(avgBandwidth) + " MB");
}
// SLA metrics
Log.printLine("SLA Violations: " + slaViolations + " ("
+ df.format((slaViolations * 100.0) / completedCloudlets) + "%)");
}
private static String getExperimentName(String... args) {
StringBuilder experimentName = new StringBuilder();
for (int i = 0; i < args.length; ++i) {
if (!args[i].isEmpty()) {
if (i != 0) {
experimentName.append("_");
}
experimentName.append(args[i]);
}
}
return experimentName.toString();
}
private static ContainerDatacenterBroker createBroker(int overBookingFactor) {
ContainerDatacenterBroker broker = null;
try {
broker = new ContainerDatacenterBroker("Broker", overBookingFactor);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}
private static List createHostList(int hostsNumber) {
ArrayList hostList = new ArrayList();
for (int i = 0; i < hostsNumber; ++i) {
int hostType = i % 3; // Distribute host types evenly
ArrayList peList = new ArrayList();
for (int j = 0; j < ConstantsExamples.HOST_PES[hostType]; ++j) {
peList.add(new ContainerVmPe(j,
new ContainerVmPeProvisionerSimple((double) ConstantsExamples.HOST_MIPS[hostType])));
}
hostList.add(new PowerContainerHostUtilizationHistory(
IDs.pollId(ContainerHost.class),
new ContainerVmRamProvisionerSimple(ConstantsExamples.HOST_RAM[hostType]),
new ContainerVmBwProvisionerSimple(1000000L),
1000000L, peList,
new ContainerVmSchedulerTimeSharedOverSubscription(peList),
ConstantsExamples.HOST_POWER[hostType]));
}
return hostList;
}
public static ContainerDatacenter createDatacenter(
String name, Class< extends ContainerDatacenter> datacenterClass,
List hostList,
ContainerVmAllocationPolicy vmAllocationPolicy,
ContainerAllocationPolicy containerAllocationPolicy,
String experimentName, double schedulingInterval, String logAddress,
double VMStartupDelay, double ContainerStartupDelay) throws Exception {
String arch = "x86";
String os = "Linux";
String vmm = "Xen";
double time_zone = 10.0;
double cost = 3.0;
double costPerMem = 0.05;
double costPerStorage = 0.001;
double costPerBw = 0.0;
ContainerDatacenterCharacteristics characteristics = new ContainerDatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);
ContainerDatacenter datacenter = new PowerContainerDatacenterCM(
name, characteristics, vmAllocationPolicy,
containerAllocationPolicy, new LinkedList(),
schedulingInterval, experimentName, logAddress,
VMStartupDelay, ContainerStartupDelay);
return datacenter;
}
private static ArrayList createVmList(int brokerId, int containerVmsNumber) {
ArrayList containerVms = new ArrayList();
for (int i = 0; i < containerVmsNumber; ++i) {
ArrayList peList = new ArrayList();
int vmType = i % 4; // Distribute VM types evenly
for (int j = 0; j < ConstantsExamples.VM_PES[vmType]; ++j) {
peList.add(new ContainerPe(j,
new ContainerPeProvisionerSimple((double) ConstantsExamples.VM_MIPS[vmType])));
}
containerVms.add(new PowerContainerVm(
IDs.pollId(ContainerVm.class), brokerId,
(double) ConstantsExamples.VM_MIPS[vmType],
(float) ConstantsExamples.VM_RAM[vmType],
ConstantsExamples.VM_BW, ConstantsExamples.VM_SIZE, "Xen",
new ContainerSchedulerTimeSharedOverSubscription(peList),
new ContainerRamProvisionerSimple(ConstantsExamples.VM_RAM[vmType]),
new ContainerBwProvisionerSimple(ConstantsExamples.VM_BW),
peList, ConstantsExamples.SCHEDULING_INTERVAL));
}
return containerVms;
}
private static List createContainerList(int brokerId, int containersNumber) {
ArrayList containers = new ArrayList();
for (int i = 0; i < containersNumber; ++i) {
int containerType = i % 3; // Distribute container types evenly
containers.add(new PowerContainer(
IDs.pollId(Container.class), brokerId,
(double) ConstantsExamples.CONTAINER_MIPS[containerType],
ConstantsExamples.CONTAINER_PES[containerType],
ConstantsExamples.CONTAINER_RAM[containerType],
ConstantsExamples.CONTAINER_BW, 0L, "Xen",
new ContainerCloudletSchedulerDynamicWorkload(
ConstantsExamples.CONTAINER_MIPS[containerType],
ConstantsExamples.CONTAINER_PES[containerType]),
ConstantsExamples.SCHEDULING_INTERVAL));
}
return containers;
}
private static List createContainerCloudletList(int brokerId, int numberOfCloudlets)
throws FileNotFoundException {
String inputFolderName = "/home/soft13/soft13/Project 2019/Cloudsim-4.0-examples/src/workload/planetlab";
ArrayList cloudletList = new ArrayList();
long fileSize = 300L;
long outputSize = 300L;
UtilizationModelNull utilizationModelNull = new UtilizationModelNull();
java.io.File inputFolder1 = new java.io.File(inputFolderName);
java.io.File[] files1 = inputFolder1.listFiles();
int createdCloudlets = 0;
for (java.io.File aFiles1 : files1) {
java.io.File inputFolder = new java.io.File(aFiles1.toString());
java.io.File[] files = inputFolder.listFiles();
for (int i = 0; i < files.length; ++i) {
if (createdCloudlets < numberOfCloudlets) {
ContainerCloudlet cloudlet = null;
try {
cloudlet = new ContainerCloudlet(
IDs.pollId(ContainerCloudlet.class),
ConstantsExamples.CLOUDLET_LENGTH, 1,
fileSize, outputSize,
new UtilizationModelPlanetLabInMemoryExtended(
files[i].getAbsolutePath(), 300.0D),
utilizationModelNull, utilizationModelNull);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
cloudlet.setUserId(brokerId);
cloudletList.add(cloudlet);
createdCloudlets += 1;
} else {
return cloudletList;
}
}
}
return cloudletList;
}
private static void printCloudletList(List list) {
int size = list.size();
ContainerCloudlet cloudlet;
String indent = " ";
Log.printLine();
Log.printLine("========== CLOUDLET EXECUTION DETAILS ==========");
Log.printLine("Cloudlet ID" + indent + "Container ID" + indent + "STATUS" + indent
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent
+ "Start Time" + indent + "Finish Time");
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent);
Log.print(cloudlet.getContainerId() + indent);
if (cloudlet.getCloudletStatusString().equals("Success")) {
Log.print("SUCCESS");
Log.printLine(indent + indent + cloudlet.getResourceId()
+ indent + indent + indent + cloudlet.getVmId()
+ indent + indent
+ dft.format(cloudlet.getActualCPUTime()) + indent
+ indent + dft.format(cloudlet.getExecStartTime())
+ indent + indent
+ dft.format(cloudlet.getFinishTime()));
}
}
}
}