How to use VM Selection Policy to Offload the Applications from EdgeServer?
Share
Condition for VM Selection Policy to Offload the Applications from EdgeServer
Description: To use a VM selection policy for offloading applications from an edge server, a policy is defined based on resource requirements like CPU, memory, or bandwidth, with priorities on minimizing latency, optimizing resources, or maintaining quality of service. The policy helps the edge server identify the most suitable VM for offloading by evaluating resource availability, load, and proximity. Integrating this policy into the system allows dynamic management of workloads, optimizing performance and resource utilization.
Sample Code
EdgeVMSelectionOffload.java: package edgecloudsim;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.core.CloudSim;
import edu.boun.edgecloudsim.core.ScenarioFactory;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.utils.SimLogger;
import edu.boun.edgecloudsim.utils.SimUtils;
public class EdgeVMAllocationOffload {
/**
* Creates main() to run this example
*/
public static void main(String[] args) {
//disable console output of cloudsim library
Log.disable();
//enable console ourput and file output of this application
SimLogger.enablePrintLog();
String configFile = "";
String outputFolder = "";
String edgeDevicesFile = "";
String applicationsFile = "";
int iterationNumber = 1;
if (args.length == 5) {
configFile = args[0];
edgeDevicesFile = args[1];
applicationsFile = args[2];
outputFolder = args[3];
iterationNumber = Integer.parseInt(args[4]);
} else {
SimLogger.printLine("Simulation setting file, output folder and iteration number are not provided! Using default ones...");
configFile = "src/scripts/sample_app1/config/default_config.properties";
applicationsFile = "src/scripts/sample_app1/config/applications.xml";
edgeDevicesFile = "src/scripts/sample_app1/config/edge_devices.xml";
outputFolder = "src/sim_results/ite" + iterationNumber;
}
//load settings from configuration file
SimSettings SS = SimSettings.getInstance();
if (SS.initialize(configFile, edgeDevicesFile, applicationsFile) == false) {
SimLogger.printLine("cannot initialize simulation settings!");
System.exit(0);
}
if (SS.getFileLoggingEnabled()) {
SimLogger.enableFileLog();
SimUtils.cleanOutputFolder(outputFolder);
}
DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date SimulationStartDate = Calendar.getInstance().getTime();
String now = df.format(SimulationStartDate);
SimLogger.printLine("Simulation started at " + now);
SimLogger.printLine("----------------------------------------------------------------------");
for (int j = SS.getMinNumOfMobileDev(); j <= SS.getMaxNumOfMobileDev(); j += SS.getMobileDevCounterSize()) {
for (int k = 0; k < SS.getSimulationScenarios().length; k++) {
for (int i = 0; i < SS.getOrchestratorPolicies().length; i++) {
String simScenario = SS.getSimulationScenarios()[k];
String orchestratorPolicy = SS.getOrchestratorPolicies()[i];
Date ScenarioStartDate = Calendar.getInstance().getTime();
now = df.format(ScenarioStartDate);
SimLogger.printLine("Scenario started at " + now);
SimLogger.printLine("Scenario: " + simScenario + " - Policy: " + orchestratorPolicy + " - #iteration: " + iterationNumber);
SimLogger.printLine("Duration: " + SS.getSimulationTime() / 3600 + " hour(s) - Poisson: " + SS.getTaskLookUpTable()[0][2] + " - #devices: " + j);
SimLogger.getInstance().simStarted(outputFolder, "SIMRESULT_" + simScenario + "_" + orchestratorPolicy + "_" + j + "DEVICES");
try {
// First step: Initialize the CloudSim package. It should be called
// before creating any entities.
int num_user = 2; // number of grid users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; // mean trace events
// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag, 0.01);
// Generate EdgeCloudsim Scenario Factory
ScenarioFactory sampleFactory = new SampleScenarioFactory(j, SS.getSimulationTime(), "NEXT_FIT", simScenario);
// Generate EdgeCloudSim Simulation Manager
SimManager manager = new SimManager(sampleFactory, j, simScenario, orchestratorPolicy);
// Start simulation
manager.startSimulation();
} catch (Exception e) {
SimLogger.printLine("The simulation has been terminated due to an unexpected error");
e.printStackTrace();
System.exit(0);
}
Date ScenarioEndDate = Calendar.getInstance().getTime();
now = df.format(ScenarioEndDate);
SimLogger.printLine("Scenario finished at " + now + ". It took " + SimUtils.getTimeDifference(ScenarioStartDate, ScenarioEndDate));
SimLogger.printLine("----------------------------------------------------------------------");
}//End of orchestrators loop
}//End of scenarios loop
}//End of mobile devices loop
Date SimulationEndDate = Calendar.getInstance().getTime();
now = df.format(SimulationEndDate);
SimLogger.printLine("Simulation finished at " + now + ". It took " + SimUtils.getTimeDifference(SimulationStartDate, SimulationEndDate));
}
}