How to Evaluate the Impact of the First Fit Container Placement Policy on Resource Utilization, Load Balancing, and Performance in Containercloudsim?
Share
Condition for Evaluate the Impact of the First Fit Container Placement Policy on Resource Utilization
Description: This research focuses on the performance evaluation of the First Fit container placement policy within a containerized cloud data center environment, simulated using ContainerCloudSim. The study aims to analyze how First Fit placement influences resource utilization efficiency, load balancing, and execution time of workloads under various hosting and scheduling configurations. The system models a dynamic multi-host cloud infrastructure that provisions virtual machines (VMs), containers, and workloads (cloudlets) based on realistic PlanetLab workload traces. By integrating VM allocation, container allocation, and host selection policies with a First Fit placement mechanism, the simulation identifies patterns of CPU and memory utilization across multiple VMs. The analysis captures both pre-simulation placement efficiency and post-simulation performance metrics, including success rate, execution time variance, and load imbalance score. The results contribute to understanding how simple heuristic policies like First Fit perform in energy-aware, resource-constrained cloud environments, providing a foundation for improving future adaptive placement and migration strategies in container-based cloud systems.
/**
* Comprehensive analysis of First Fit Container Placement Policy
*/
public class PlacementPolicyFirstFit {
private static List cloudletList;
private static List vmList;
private static List containerList;
private static List hostList;
// Statistics for First Fit analysis
private static FirstFitStats firstFitStats;
public static void main(String[] args) {
Log.printLine("Starting First Fit Container Placement Policy Analysis...");
firstFitStats = new FirstFitStats();
// Get results and analyze
List completedCloudlets = broker.getCloudletReceivedList();
printCloudletList(completedCloudlets);
analyzeFirstFitResults(completedCloudlets, containerList, vmList);
printFirstFitStatistics();
Log.printLine("First Fit Container Placement Analysis finished!");
/**
* Analyze First Fit placement pattern
*/
private static void analyzeFirstFitPlacement(List containers, List vms) {
Log.printLine("\n=== FIRST FIT PLACEMENT ANALYSIS ===");
// Simulate First Fit placement
ContainerPlacementPolicy firstFitPolicy = new ContainerPlacementPolicyFirstFit();
Map vmContainerCount = new HashMap<>();
Map vmCpuUtilization = new HashMap<>();
Map vmRamUtilization = new HashMap<>();
// Initialize maps
for (ContainerVm vm : vms) {
vmContainerCount.put(vm.getId(), 0);
vmCpuUtilization.put(vm.getId(), 0.0);
vmRamUtilization.put(vm.getId(), 0.0);
}
// Simulate placement for each container
for (Container container : containers) {
ContainerVm selectedVm = firstFitPolicy.getContainerVm(vmList, container, new HashSet());
if (selectedVm != null) {
// Update statistics
int vmId = selectedVm.getId();
vmContainerCount.put(vmId, vmContainerCount.get(vmId) + 1);
/**
* Analyze First Fit results after simulation
*/
private static void analyzeFirstFitResults(List completedCloudlets,
List containers, List vms) {
Log.printLine("\n=== FIRST FIT PERFORMANCE RESULTS ===");
Map> vmExecutionTimes = new HashMap<>();
Map vmSuccessCount = new HashMap<>();
// Initialize maps
for (ContainerVm vm : vms) {
vmExecutionTimes.put(vm.getId(), new ArrayList());
vmSuccessCount.put(vm.getId(), 0);
}
// Analyze completed cloudlets
for (ContainerCloudlet cloudlet : completedCloudlets) {
if (cloudlet.getCloudletStatusString().equals("Success")) {
int vmId = cloudlet.getVmId();
double executionTime = cloudlet.getActualCPUTime();
// Calculate average execution times per VM
Log.printLine("\nVM ID | Success Count | Avg Time (s) | Std Dev");
Log.printLine("------|--------------|--------------|---------");
for (ContainerVm vm : vms) {
int vmId = vm.getId();
List times = vmExecutionTimes.get(vmId);
int successCount = vmSuccessCount.get(vmId);
/**
* Calculate standard deviation
*/
private static double calculateStdDev(List values, double mean) {
double sum = 0;
for (double value : values) {
sum += Math.pow(value - mean, 2);
}
return Math.sqrt(sum / values.size());
}
/**
* Print comprehensive First Fit statistics
*/
private static void printFirstFitStatistics() {
Log.printLine("\n=== FIRST FIT STATISTICS SUMMARY ===");
/**
* Analyze placement patterns for First Fit
*/
private static void analyzePlacementPatterns() {
Log.printLine("\n=== PLACEMENT PATTERN ANALYSIS ===");
// Count containers per VM in placement sequence
Map placementDistribution = new HashMap<>();
for (Placement placement : firstFitStats.placementSequence) {
placementDistribution.put(placement.vmId,
placementDistribution.getOrDefault(placement.vmId, 0) + 1);
}
// Existing utility methods (unchanged from your original code)
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 ArrayList createVmList(int brokerId, int containerVmsNumber) {
ArrayList containerVms = new ArrayList();
for (int i = 0; i < containerVmsNumber; ++i) {
ArrayList peList = new ArrayList();
int vmType = i / (int) Math.ceil((double) containerVmsNumber / 4.0D);
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;
}
public static List createHostList(int hostsNumber) {
ArrayList hostList = new ArrayList();
for (int i = 0; i < hostsNumber; ++i) {
int hostType = i / (int) Math.ceil((double) hostsNumber / 3.0D);
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;
}
ContainerDatacenter datacenter = new PowerContainerDatacenterCM(name, characteristics, vmAllocationPolicy,
containerAllocationPolicy, new LinkedList(), schedulingInterval, experimentName, logAddress,
VMStartupDelay, ContainerStartupDelay);
return datacenter;
}
public static List createContainerList(int brokerId, int containersNumber) {
ArrayList containers = new ArrayList();
for (int i = 0; i < containersNumber; ++i) {
int containerType = i / (int) Math.ceil((double) containersNumber / 3.0D);
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;
}
public 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 var13) {
var13.printStackTrace();
System.exit(0);
}
cloudlet.setUserId(brokerId);
cloudletList.add(cloudlet);
createdCloudlets += 1;
} else {
return cloudletList;
}
}
}
return cloudletList;
}
/**
* Statistics class for First Fit analysis
*/
static class FirstFitStats {
int totalPlacements = 0;
int successfulCloudlets = 0;
double totalExecutionTime = 0;
double minExecutionTime = -1;
double maxExecutionTime = 0;
double minVmUtilization = -1;
double maxVmUtilization = 0;
List vmUtilization = new ArrayList<>();
List placementSequence = new ArrayList<>();
Map vmAvgTimes = new HashMap<>();
}
/**
* Placement record class
*/
static class Placement {
int containerId;
int vmId;