How to Demonstrate the Mapping Between Containers and Virtual Machines (Vms) in a Container-Based Cloud Data Center Using Containercloudsim?
Share
Condition for Mapping Between Containers and Virtual Machines (Vms) in a Container-Based Cloud Data Center using ContainerCloudSim
Description: The PowerConsumptio is designed to simulate and analyze the energy consumption of a container-based cloud data center using the CloudSim and ContainerCloudSim frameworks. It models a realistic cloud environment where physical hosts, virtual machines (VMs), containers, and cloudlets interact to execute workloads under specific power management and allocation policies.
The simulation begins with initializing the CloudSim environment, followed by the creation of multiple physical hosts equipped with power models to monitor their energy usage. A power-aware VM allocation policy and container allocation policy are employed to efficiently distribute workloads based on host utilization thresholds, enabling migration and consolidation of VMs to reduce power waste.
The program uses the PlanetLab workload traces to simulate real-world task execution. During and after the simulation, the total power consumption of each host is recorded, converted from joules to kilowatt-hours (kWh), and printed along with the total data center energy usage. Overall, this program demonstrates how energy-efficient resource management strategies can be modeled and evaluated in a containerized cloud environment to achieve optimized performance with minimal power consumption.
private static List vmList;
private static List containerList;
private static List cloudletList;
private static List hostList;
private static ContainerDatacenter datacenter;
private static ContainerDatacenterBroker broker;
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
// Define policies and thresholds
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();
// Submit VMs, containers and cloudlets to the broker
broker.submitVmList(vmList);
broker.submitContainerList(containerList);
broker.submitCloudletList(cloudletList);
Log.printLine("ContainerCloudSim Exercise finished!");
} catch (Exception e) {
e.printStackTrace();
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
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();
}
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])));
}
// Create VM with appropriate scheduler and provisioners
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
private static void printPowerConsumption() {
Log.printLine();
Log.printLine("========== POWER CONSUMPTION ==========");
double totalPower = 0.0;
for (ContainerHost host : hostList) {
if (host instanceof PowerContainerHostUtilizationHistory) {
PowerContainerHostUtilizationHistory powerHost
= (PowerContainerHostUtilizationHistory) host;
// Get the total energy consumption in kWh
double energy = powerHost.getPower() / (1000 * 3600); // Convert from Joules to kWh
Log.printLine("Host #" + host.getId() + " energy consumption: "
+ String.format("%.5f", energy) + " kWh");
totalPower += energy;
}
}