code refactoring and improvements

* saving log for each app type support
* colt library is used for poisson distribution
* Setting file structure is updated
* some bug fixes are applied
* new abstract functions are added to network manager for another
experimental study
This commit is contained in:
Cagatay Sonmez 2017-06-19 22:40:15 +03:00
parent 22b654d719
commit 138adb8f32
12 changed files with 618 additions and 360 deletions

BIN
lib/colt.jar Normal file

Binary file not shown.

View File

@ -37,7 +37,7 @@ public class SimSettings {
//if you want to add different types on your config file,
//you may modify current types or add new types here.
public static enum VM_TYPES { EDGE_VM, CLOUD_VM }
public static enum APP_TYPES { FACE_REC_APP, HEALTH_APP, HEAVY_COMP_APP, VIDEO_GAME_APP, SIMPLE_SERVICE_APP }
public static enum APP_TYPES { AUGMENTED_REALITY, HEALTH_APP, HEAVY_COMP_APP, INFOTAINMENT_APP }
public static enum PLACE_TYPES { ATTRACTIVENESS_L1, ATTRACTIVENESS_L2, ATTRACTIVENESS_L3 }
//predifined IDs for cloud components.
@ -52,10 +52,10 @@ public class SimSettings {
//delimiter for output file.
public static String DELIMITER = ";";
private double SIMULATION_TIME; //hours unit in properties file
private double WARM_UP_PERIOD; //seconds unit in properties file
private double INTERVAL_TO_GET_VM_LOAD_LOG; //seconds unit in properties file
private double INTERVAL_TO_GET_VM_LOCATION_LOG; //seconds unit in properties file
private double SIMULATION_TIME; //minutes unit in properties file
private double WARM_UP_PERIOD; //minutes unit in properties file
private double INTERVAL_TO_GET_VM_LOAD_LOG; //minutes unit in properties file
private double INTERVAL_TO_GET_VM_LOCATION_LOG; //minutes unit in properties file
private boolean FILE_LOG_ENABLED; //boolean to check file logging option
private boolean DEEP_FILE_LOG_ENABLED; //boolean to check deep file logging option
@ -92,7 +92,7 @@ public class SimSettings {
// [7] avg task length (MI)
// [8] required # of cores
// [9] vm utilization (%)
private double[][] taskLookUpTable = new double[APP_TYPES.values().length][10];
private double[][] taskLookUpTable = new double[APP_TYPES.values().length][11];
private SimSettings() {
}
@ -119,10 +119,10 @@ public class SimSettings {
Properties prop = new Properties();
prop.load(input);
SIMULATION_TIME = 3600 * Double.parseDouble(prop.getProperty("simulation_time")); //hours
WARM_UP_PERIOD = Double.parseDouble(prop.getProperty("warm_up_period")); //seconds
INTERVAL_TO_GET_VM_LOAD_LOG = Double.parseDouble(prop.getProperty("vm_load_check_interval")); //seconds
INTERVAL_TO_GET_VM_LOCATION_LOG = Double.parseDouble(prop.getProperty("vm_location_check_interval")); //seconds
SIMULATION_TIME = (double)60 * Double.parseDouble(prop.getProperty("simulation_time")); //seconds
WARM_UP_PERIOD = (double)60 * Double.parseDouble(prop.getProperty("warm_up_period")); //seconds
INTERVAL_TO_GET_VM_LOAD_LOG = (double)60 * Double.parseDouble(prop.getProperty("vm_load_check_interval")); //seconds
INTERVAL_TO_GET_VM_LOCATION_LOG = (double)60 * Double.parseDouble(prop.getProperty("vm_location_check_interval")); //seconds
FILE_LOG_ENABLED = Boolean.parseBoolean(prop.getProperty("file_log_enabled"));
DEEP_FILE_LOG_ENABLED = Boolean.parseBoolean(prop.getProperty("deep_file_log_enabled"));
@ -185,7 +185,7 @@ public class SimSettings {
/**
* returns simulation time (in hours unit) from properties file
* returns simulation time (in seconds unit) from properties file
*/
public double getSimulationTime()
{
@ -430,9 +430,10 @@ public class SimSettings {
double task_length = Double.parseDouble(appElement.getElementsByTagName("task_length").item(0).getTextContent());
double required_core = Double.parseDouble(appElement.getElementsByTagName("required_core").item(0).getTextContent());
double vm_utilization = Double.parseDouble(appElement.getElementsByTagName("vm_utilization").item(0).getTextContent());
double delay_sensitivity = Double.parseDouble(appElement.getElementsByTagName("delay_sensitivity").item(0).getTextContent());
taskLookUpTable[appType.ordinal()][0] = usage_percentage; //usage percentage (%)
taskLookUpTable[appType.ordinal()][1] = prob_cloud_selection; //prob. of selecting cloud (%)
taskLookUpTable[appType.ordinal()][0] = usage_percentage; //usage percentage [0-100]
taskLookUpTable[appType.ordinal()][1] = prob_cloud_selection; //prob. of selecting cloud [0-100]
taskLookUpTable[appType.ordinal()][2] = poisson_interarrival; //poisson mean (sec)
taskLookUpTable[appType.ordinal()][3] = active_period; //active period (sec)
taskLookUpTable[appType.ordinal()][4] = idle_period; //idle period (sec)
@ -440,7 +441,8 @@ public class SimSettings {
taskLookUpTable[appType.ordinal()][6] = data_download; //avg data download (KB)
taskLookUpTable[appType.ordinal()][7] = task_length; //avg task length (MI)
taskLookUpTable[appType.ordinal()][8] = required_core; //required # of core
taskLookUpTable[appType.ordinal()][9] = vm_utilization; //vm utilization (%)
taskLookUpTable[appType.ordinal()][9] = vm_utilization; //vm utilization [0-100]
taskLookUpTable[appType.ordinal()][10] = delay_sensitivity; //delay_sensitivity [0-1]
}
} catch (Exception e) {

View File

@ -38,7 +38,7 @@ public class MobileDeviceManager extends DatacenterBroker {
private static final int REQUEST_PROCESSED_BY_CLOUD = BASE + 2;
private static final int REQUEST_RECIVED_BY_EDGE_DEVICE = BASE + 3;
private static final int RESPONSE_RECEIVED_BY_MOBILE_DEVICE = BASE + 4;
private static final int REQUEST_RECIVED_BY_EDGE_ORCHESTRATOR = BASE + 5;
// private static final int REQUEST_RECIVED_BY_EDGE_ORCHESTRATOR = BASE + 5;
private int taskIdCounter=0;
public MobileDeviceManager() throws Exception {
@ -70,9 +70,10 @@ public class MobileDeviceManager extends DatacenterBroker {
if(task.getSubmittedLocation().equals(currentLocation))
{
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + task.getCloudletId() + " received");
double WlanDelay = networkModel.getDownloadDelay(task.getAssociatedHostId(), task.getMobileDeviceId());
double WlanDelay = networkModel.getDownloadDelay(task.getAssociatedHostId(), task.getMobileDeviceId(), task.getCloudletOutputSize());
if(WlanDelay > 0)
{
networkModel.downloadStarted(currentLocation, SimSettings.GENERIC_EDGE_DEVICE_ID);
schedule(getId(), WlanDelay, RESPONSE_RECEIVED_BY_MOBILE_DEVICE, task);
SimLogger.getInstance().downloadStarted(task.getCloudletId(), WlanDelay);
}
@ -103,9 +104,9 @@ public class MobileDeviceManager extends DatacenterBroker {
{
Task task = (Task) ev.getData();
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock());
networkModel.uploadFinished(task.getSubmittedLocation(), SimSettings.CLOUD_DATACENTER_ID);
task.setSubmittedLocation(currentLocation);
//save related host id
task.setAssociatedHostId(SimSettings.CLOUD_HOST_ID);
SimLogger.getInstance().uploaded(task.getCloudletId(),
@ -124,55 +125,71 @@ public class MobileDeviceManager extends DatacenterBroker {
case REQUEST_PROCESSED_BY_CLOUD:
{
Task task = (Task) ev.getData();
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock());
if(task.getSubmittedLocation().equals(currentLocation))
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + task.getCloudletId() + " received");
double WanDelay = networkModel.getDownloadDelay(SimSettings.CLOUD_DATACENTER_ID, task.getMobileDeviceId(), task.getCloudletOutputSize());
if(WanDelay > 0)
{
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + task.getCloudletId() + " received");
double WanDelay = networkModel.getDownloadDelay(SimSettings.CLOUD_DATACENTER_ID, task.getMobileDeviceId());
if(WanDelay > 0)
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock()+WanDelay);
if(task.getSubmittedLocation().equals(currentLocation))
{
networkModel.downloadStarted(task.getSubmittedLocation(), SimSettings.CLOUD_DATACENTER_ID);
schedule(getId(), WanDelay, RESPONSE_RECEIVED_BY_MOBILE_DEVICE, task);
SimLogger.getInstance().downloadStarted(task.getCloudletId(), WanDelay);
}
else
{
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
//SimLogger.printLine("task cannot be finished due to mobility of user!");
//SimLogger.printLine("device: " +task.getMobileDeviceId()+" - submitted " + task.getSubmissionTime() + " @ " + task.getSubmittedLocation().getXPos() + " handled " + CloudSim.clock() + " @ " + currentLocation.getXPos());
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
}
}
else
{
//SimLogger.printLine("task cannot be finished due to mobility of user!");
//SimLogger.printLine("device: " +task.getMobileDeviceId()+" - submitted " + task.getSubmissionTime() + " @ " + task.getSubmittedLocation().getXPos() + " handled " + CloudSim.clock() + " @ " + currentLocation.getXPos());
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
}
break;
}
/*
case REQUEST_RECIVED_BY_EDGE_ORCHESTRATOR:
{
Task task = (Task) ev.getData();
double internalDelay = networkModel.getDownloadDelay(
SimSettings.EDGE_ORCHESTRATOR_ID,
SimSettings.GENERIC_EDGE_DEVICE_ID);
SimSettings.GENERIC_EDGE_DEVICE_ID,
task.getCloudletOutputSize());
networkModel.downloadStarted(
SimSettings.EDGE_ORCHESTRATOR_ID,
SimSettings.GENERIC_EDGE_DEVICE_ID,
task.getCloudletOutputSize());
submitTaskToEdgeDevice(task,internalDelay);
break;
}
*/
case REQUEST_RECIVED_BY_EDGE_DEVICE:
{
Task task = (Task) ev.getData();
networkModel.uploadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID);
submitTaskToEdgeDevice(task,0);
break;
}
case RESPONSE_RECEIVED_BY_MOBILE_DEVICE:
{
Cloudlet cloudlet = (Cloudlet) ev.getData();
Task task = (Task) ev.getData();
if(task.getAssociatedHostId() == SimSettings.CLOUD_HOST_ID)
networkModel.downloadFinished(task.getSubmittedLocation(), SimSettings.CLOUD_DATACENTER_ID);
else
networkModel.downloadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID);
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + cloudlet.getCloudletId() + " is received");
SimLogger.getInstance().downloaded(cloudlet.getCloudletId(), CloudSim.clock());
SimLogger.getInstance().downloaded(task.getCloudletId(), CloudSim.clock());
break;
}
default:
@ -187,11 +204,7 @@ public class MobileDeviceManager extends DatacenterBroker {
EdgeVM selectedVM = SimManager.getInstance().getEdgeOrchestrator().getVmToOffload(task);
if(selectedVM != null){
Location currentLocation = SimManager.getInstance().getMobilityModel().
getLocation(task.getMobileDeviceId(),CloudSim.clock());
//save task info
task.setSubmittedLocation(currentLocation);
//save related host id
task.setAssociatedHostId(selectedVM.getHost().getId());
//bind task to related VM
@ -218,6 +231,12 @@ public class MobileDeviceManager extends DatacenterBroker {
//create a task
Task task = createTask(edgeTask);
Location currentLocation = SimManager.getInstance().getMobilityModel().
getLocation(task.getMobileDeviceId(),CloudSim.clock());
//set location of the mobile device which generates this task
task.setSubmittedLocation(currentLocation);
//add related task to log list
SimLogger.getInstance().addLog(CloudSim.clock(),
@ -230,38 +249,50 @@ public class MobileDeviceManager extends DatacenterBroker {
int nextHopId = SimManager.getInstance().getEdgeOrchestrator().getDeviceToOffload(task);
if(nextHopId == SimSettings.CLOUD_DATACENTER_ID){
double WanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(), nextHopId);
double WanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(), nextHopId, task.getCloudletFileSize());
if(WanDelay>0){
networkModel.uploadStarted(currentLocation, nextHopId);
schedule(getId(), WanDelay, REQUEST_RECEIVED_BY_CLOUD, task);
SimLogger.getInstance().uploadStarted(task.getCloudletId(),WanDelay);
}
else
{
//SimLogger.printLine("Task #" + task.getCloudletId() + " cannot assign to any VM");
SimLogger.getInstance().rejectedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
}
}
else if(nextHopId == SimSettings.EDGE_ORCHESTRATOR_ID){
double WlanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(), nextHopId);
if(WlanDelay > 0){
schedule(getId(), WlanDelay, REQUEST_RECIVED_BY_EDGE_ORCHESTRATOR, task);
SimLogger.getInstance().uploadStarted(task.getCloudletId(),WlanDelay);
}
else {
SimLogger.getInstance().rejectedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
SimLogger.getInstance().rejectedDueToBandwidth(
task.getCloudletId(),
CloudSim.clock(),
SimSettings.VM_TYPES.CLOUD_VM.ordinal());
}
}
// else if(nextHopId == SimSettings.EDGE_ORCHESTRATOR_ID){
// double WlanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(), nextHopId, task.getCloudletFileSize());
//
// if(WlanDelay > 0){
// networkModel.uploadStarted(task.getMobileDeviceId(), nextHopId, task.getCloudletFileSize());
// schedule(getId(), WlanDelay, REQUEST_RECIVED_BY_EDGE_ORCHESTRATOR, task);
// SimLogger.getInstance().uploadStarted(task.getCloudletId(),WlanDelay);
// }
// else {
// SimLogger.getInstance().rejectedDueToBandwidth(
// task.getCloudletId(),
// CloudSim.clock(),
// SimSettings.VM_TYPES.EDGE_VM.ordinal());
// }
// }
else if(nextHopId == SimSettings.GENERIC_EDGE_DEVICE_ID) {
double WlanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(), nextHopId);
double WlanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(), nextHopId, task.getCloudletFileSize());
if(WlanDelay > 0){
networkModel.uploadStarted(currentLocation, nextHopId);
schedule(getId(), WlanDelay, REQUEST_RECIVED_BY_EDGE_DEVICE, task);
SimLogger.getInstance().uploadStarted(task.getCloudletId(),WlanDelay);
}
else {
SimLogger.getInstance().rejectedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
SimLogger.getInstance().rejectedDueToBandwidth(
task.getCloudletId(),
CloudSim.clock(),
SimSettings.VM_TYPES.EDGE_VM.ordinal());
}
}
else {

View File

@ -53,7 +53,7 @@ public class BasicEdgeOrchestrator extends EdgeOrchestrator {
if(CloudVmPicker <= SimSettings.getInstance().getTaskLookUpTable()[task.getTaskType().ordinal()][1])
result = SimSettings.CLOUD_DATACENTER_ID;
else
result = SimSettings.EDGE_ORCHESTRATOR_ID;
result = SimSettings.GENERIC_EDGE_DEVICE_ID;
}
return result;

View File

@ -17,6 +17,7 @@ import java.util.List;
import java.util.TreeMap;
import java.util.Map.Entry;
import org.apache.commons.math3.distribution.ExponentialDistribution;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@ -24,7 +25,6 @@ import org.w3c.dom.NodeList;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.utils.Location;
import edu.boun.edgecloudsim.utils.PoissonDistr;
import edu.boun.edgecloudsim.utils.SimLogger;
import edu.boun.edgecloudsim.utils.SimUtils;
@ -40,7 +40,7 @@ public class NomadicMobility extends MobilityModel {
public void initialize() {
treeMapArray = new ArrayList<TreeMap<Double, Location>>();
PoissonDistr[] poissonRngList = new PoissonDistr[SimSettings.getInstance().getNumOfEdgeDatacenters()];
ExponentialDistribution[] expRngList = new ExponentialDistribution[SimSettings.getInstance().getNumOfEdgeDatacenters()];
//create random number generator for each place
Document doc = SimSettings.getInstance().getEdgeDevicesDocument();
@ -52,7 +52,7 @@ public class NomadicMobility extends MobilityModel {
String attractiveness = location.getElementsByTagName("attractiveness").item(0).getTextContent();
SimSettings.PLACE_TYPES placeType = SimUtils.stringToPlace(attractiveness);
poissonRngList[i] = new PoissonDistr(SimSettings.getInstance().getMobilityLookUpTable()[placeType.ordinal()]);
expRngList[i] = new ExponentialDistribution(SimSettings.getInstance().getMobilityLookUpTable()[placeType.ordinal()]);
}
//initialize tree maps and position of mobile devices
@ -79,7 +79,7 @@ public class NomadicMobility extends MobilityModel {
while(treeMap.lastKey() < SimSettings.getInstance().getSimulationTime()) {
boolean placeFound = false;
int currentLocationId = treeMap.lastEntry().getValue().getServingWlanId();
double waitingTime = poissonRngList[currentLocationId].sample() * 60;
double waitingTime = expRngList[currentLocationId].sample();
while(placeFound == false){
int newDatacenterId = SimUtils.getRandomNumber(0,SimSettings.getInstance().getNumOfEdgeDatacenters()-1);
@ -95,7 +95,7 @@ public class NomadicMobility extends MobilityModel {
int y_pos = Integer.parseInt(location.getElementsByTagName("y_pos").item(0).getTextContent());
treeMap.put(treeMap.lastKey()+waitingTime, new Location(placeType, wlan_id, x_pos, y_pos));
}
}
}
if(!placeFound){
SimLogger.printLine("impossible is occured! location cannot be assigned to the device!");

View File

@ -65,7 +65,7 @@ public class MM1Queue extends NetworkModel {
* source device is always mobile device in our simulation scenarios!
*/
@Override
public double getUploadDelay(int sourceDeviceId, int destDeviceId) {
public double getUploadDelay(int sourceDeviceId, int destDeviceId, double dataSize) {
double delay = 0;
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(sourceDeviceId,CloudSim.clock());
@ -93,7 +93,7 @@ public class MM1Queue extends NetworkModel {
* destination device is always mobile device in our simulation scenarios!
*/
@Override
public double getDownloadDelay(int sourceDeviceId, int destDeviceId) {
public double getDownloadDelay(int sourceDeviceId, int destDeviceId, double dataSize) {
//Special Case -> edge orchestrator to edge device
if(sourceDeviceId == SimSettings.EDGE_ORCHESTRATOR_ID &&
destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID){
@ -155,11 +155,13 @@ public class MM1Queue extends NetworkModel {
avgTaskSize = avgTaskSize * (double)1000; //convert from KB to Byte
Bps = bandwidth * (double)1000 / (double)8; //convert from Kbps to Byte per seconds
lamda = ((double)1/(double)PoissonMean); //task per seconds
lamda = ((double)1/(double)PoissonMean); //task per seconds
mu = Bps / avgTaskSize ; //task per seconds
double result = (double)1 / (mu-lamda*(double)deviceCount);
return result + propogationDelay;
result += propogationDelay;
return (result > 5) ? -1 : result;
}
private double getWlanDownloadDelay(Location accessPointLocation, double time) {
@ -193,4 +195,28 @@ public class MM1Queue extends NetworkModel {
avgTaskInputSize,
getDeviceCount(accessPointLocation, time));
}
@Override
public void uploadStarted(Location accessPointLocation, int destDeviceId) {
// TODO Auto-generated method stub
}
@Override
public void uploadFinished(Location accessPointLocation, int destDeviceId) {
// TODO Auto-generated method stub
}
@Override
public void downloadStarted(Location accessPointLocation, int sourceDeviceId) {
// TODO Auto-generated method stub
}
@Override
public void downloadFinished(Location accessPointLocation, int sourceDeviceId) {
// TODO Auto-generated method stub
}
}

View File

@ -13,6 +13,8 @@
package edu.boun.edgecloudsim.network;
import edu.boun.edgecloudsim.utils.Location;
public abstract class NetworkModel {
protected int numberOfMobileDevices;
@ -28,10 +30,19 @@ public abstract class NetworkModel {
/**
* calculates the upload delay from source to destination device
*/
public abstract double getUploadDelay(int sourceDeviceId, int destDeviceId);
public abstract double getUploadDelay(int sourceDeviceId, int destDeviceId, double dataSize);
/**
* calculates the download delay from source to destination device
*/
public abstract double getDownloadDelay(int sourceDeviceId, int destDeviceId);
public abstract double getDownloadDelay(int sourceDeviceId, int destDeviceId, double dataSize);
/**
* Mobile device manager should inform network manager about the network operation
* This information may be important for some network delay models
*/
public abstract void uploadStarted(Location accessPointLocation, int destDeviceId);
public abstract void uploadFinished(Location accessPointLocation, int destDeviceId);
public abstract void downloadStarted(Location accessPointLocation, int sourceDeviceId);
public abstract void downloadFinished(Location accessPointLocation, int sourceDeviceId);
}

View File

@ -50,9 +50,9 @@ public class mainApp {
else{
SimLogger.printLine("Simulation setting file, output folder and iteration number are not provided! Using default ones...");
String configName = "default_config";
configFile = "config/" + configName + ".properties";
applicationsFile = "config/applications.xml";
edgeDevicesFile = "config/edge_devices.xml";
configFile = "config/sample_application/" + configName + ".properties";
applicationsFile = "config/sample_application/applications.xml";
edgeDevicesFile = "config/sample_application/edge_devices.xml";
outputFolder = "D:/" + configName + "/ite" + iterationNumber;
}
@ -101,9 +101,13 @@ public class mainApp {
// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag, 0.01);
// Generate EdgeCloudsim Scenario Factory
ScenarioFactory sampleFactory = new SampleScenarioFactory(j,SS.getSimulationTime(), orchestratorPolicy, simScenario);
// Generate EdgeCloudSim Simulation Manager
SimManager manager = new SimManager(sampleFactory, j, simScenario);
// Start simulation
manager.startSimulation();
}
catch (Exception e)

View File

@ -20,7 +20,6 @@ import org.apache.commons.math3.distribution.ExponentialDistribution;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.core.SimSettings.APP_TYPES;
import edu.boun.edgecloudsim.utils.EdgeTask;
import edu.boun.edgecloudsim.utils.PoissonDistr;
import edu.boun.edgecloudsim.utils.SimLogger;
import edu.boun.edgecloudsim.utils.SimUtils;
@ -35,16 +34,16 @@ public class IdleActiveLoadGenerator extends LoadGeneratorModel{
taskList = new ArrayList<EdgeTask>();
//exponential number generator for file input size, file output size and task length
PoissonDistr[][] poissonRngList = new PoissonDistr[SimSettings.APP_TYPES.values().length][3];
ExponentialDistribution[][] expRngList = new ExponentialDistribution[SimSettings.APP_TYPES.values().length][3];
//create random number generator for each place
for(int i=0; i<SimSettings.APP_TYPES.values().length; i++) {
if(SimSettings.getInstance().getTaskLookUpTable()[i][0] ==0)
break;
continue;
poissonRngList[i][0] = new PoissonDistr(SimSettings.getInstance().getTaskLookUpTable()[i][5]);
poissonRngList[i][1] = new PoissonDistr(SimSettings.getInstance().getTaskLookUpTable()[i][6]);
poissonRngList[i][2] = new PoissonDistr(SimSettings.getInstance().getTaskLookUpTable()[i][7]);
expRngList[i][0] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][5]);
expRngList[i][1] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][6]);
expRngList[i][2] = new ExponentialDistribution(SimSettings.getInstance().getTaskLookUpTable()[i][7]);
}
//Each mobile device utilizes an app type (task type)
@ -87,7 +86,7 @@ public class IdleActiveLoadGenerator extends LoadGeneratorModel{
continue;
}
taskList.add(new EdgeTask(i,randomTaskType, virtualTime, poissonRngList));
taskList.add(new EdgeTask(i,randomTaskType, virtualTime, expRngList));
}
}
}

View File

@ -10,6 +10,8 @@
package edu.boun.edgecloudsim.utils;
import org.apache.commons.math3.distribution.ExponentialDistribution;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.core.SimSettings.APP_TYPES;
@ -20,14 +22,14 @@ public class EdgeTask {
public int pesNumber;
public int mobileDeviceId;
public EdgeTask(int _mobileDeviceId, APP_TYPES _taskType, double _startTime, PoissonDistr[][] poissonRngList) {
public EdgeTask(int _mobileDeviceId, APP_TYPES _taskType, double _startTime, ExponentialDistribution[][] expRngList) {
mobileDeviceId=_mobileDeviceId;
startTime=_startTime;
taskType=_taskType;
inputFileSize = (long)poissonRngList[_taskType.ordinal()][0].sample();
outputFileSize =(long)poissonRngList[_taskType.ordinal()][1].sample();
length = (long)poissonRngList[_taskType.ordinal()][2].sample();
inputFileSize = (long)expRngList[_taskType.ordinal()][0].sample();
outputFileSize =(long)expRngList[_taskType.ordinal()][1].sample();
length = (long)expRngList[_taskType.ordinal()][2].sample();
pesNumber = (int)SimSettings.getInstance().getTaskLookUpTable()[_taskType.ordinal()][8];
}

View File

@ -1,7 +1,7 @@
/*
* Title: EdgeCloudSim - Poisson Distribution
*
* Description: Poisson Distribution implementation
* Description: Wrapper class for colt Poisson Distribution
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
@ -9,28 +9,16 @@
package edu.boun.edgecloudsim.utils;
import java.util.Random;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import cern.jet.random.Poisson;
import cern.jet.random.engine.MersenneTwister;
import cern.jet.random.engine.RandomEngine;
public class PoissonDistr {
/** The num gen. */
private final Random numGen;
/** The mean. */
private final double mean;
/**
* Creates a new exponential number generator.
*
* @param seed the seed to be used.
* @param mean the mean for the distribution.
*/
public PoissonDistr(long seed, double mean) {
if (mean <= 0.0) {
throw new IllegalArgumentException("Mean must be greater than 0.0");
}
numGen = new Random(seed);
this.mean = mean;
}
Poisson poisson;
RandomEngine engine;
/**
* Creates a new exponential number generator.
@ -38,11 +26,17 @@ public class PoissonDistr {
* @param mean the mean for the distribution.
*/
public PoissonDistr(double mean) {
if (mean <= 0.0) {
throw new IllegalArgumentException("Mean must be greated than 0.0");
}
numGen = new Random(System.currentTimeMillis());
this.mean = mean;
engine = new MersenneTwister(new Date());
poisson = new Poisson(mean, engine);
//always sleep for some milliseconds in order not to have same seed for iterative PoissonDistr contruction
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException e) {
SimLogger.printLine("impossible is occured! Poisson random number cannot be created!");
e.printStackTrace();
System.exit(0);
}
}
/**
@ -51,13 +45,6 @@ public class PoissonDistr {
* @return the next random number in the sequence
*/
public double sample() {
double L = Math.exp(-mean);
int k = 0;
double p = 1.0;
do {
p = p * numGen.nextDouble();
k++;
} while (p > L);
return k - 1;
return poisson.nextDouble();
}
}

View File

@ -21,22 +21,17 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
public class SimLogger {
public static enum TASK_STATUS {CREATED,
UPLOADING,
PROCESSING,
DOWNLOADING,
COMLETED,
REJECTED_DUE_TO_VM_CAPACITY,
REJECTED_DUE_TO_BANDWIDTH,
UNFINISHED_DUE_TO_BANDWIDTH,
UNFINISHED_DUE_TO_MOBILITY
public static enum TASK_STATUS {
CREATED, UPLOADING, PROCESSING, DOWNLOADING, COMLETED, REJECTED_DUE_TO_VM_CAPACITY, REJECTED_DUE_TO_BANDWIDTH, UNFINISHED_DUE_TO_BANDWIDTH, UNFINISHED_DUE_TO_MOBILITY
}
private static boolean fileLogEnabled;
private static boolean printLogEnabled;
private String filePrefix;
@ -44,21 +39,21 @@ public class SimLogger {
private Map<Integer, LogItem> taskMap;
private LinkedList<VmLoadLogItem> vmLoadList;
private static SimLogger singleton = new SimLogger( );
private static SimLogger singleton = new SimLogger();
/* A private Constructor prevents any other
* class from instantiating.
/*
* A private Constructor prevents any other class from instantiating.
*/
private SimLogger(){
private SimLogger() {
fileLogEnabled = false;
printLogEnabled = false;
}
/* Static 'instance' method */
public static SimLogger getInstance( ) {
public static SimLogger getInstance() {
return singleton;
}
public static void enableFileLog() {
fileLogEnabled = true;
}
@ -66,39 +61,40 @@ public class SimLogger {
public static void enablePrintLog() {
printLogEnabled = true;
}
public static boolean isFileLogEnabled() {
return fileLogEnabled;
}
public static void disablePrintLog() {
printLogEnabled = false;
}
private void appendToFile(BufferedWriter bw, String line) throws IOException{
private void appendToFile(BufferedWriter bw, String line) throws IOException {
bw.write(line);
bw.newLine();
}
public static void printLine(String msg){
if(printLogEnabled)
public static void printLine(String msg) {
if (printLogEnabled)
System.out.println(msg);
}
public static void print(String msg){
if(printLogEnabled)
public static void print(String msg) {
if (printLogEnabled)
System.out.print(msg);
}
public void simStarted(String outFolder,String fileName) {
public void simStarted(String outFolder, String fileName) {
filePrefix = fileName;
outputFolder = outFolder;
taskMap = new HashMap<Integer, LogItem>();
vmLoadList = new LinkedList<VmLoadLogItem>();
}
public void addLog(double taskStartTime, int taskId, int taskType, int taskLenght, int taskInputType, int taskOutputSize) {
//printLine(taskId+"->"+taskStartTime);
public void addLog(double taskStartTime, int taskId, int taskType, int taskLenght, int taskInputType,
int taskOutputSize) {
// printLine(taskId+"->"+taskStartTime);
taskMap.put(taskId, new LogItem(taskStartTime, taskType, taskLenght, taskInputType, taskOutputSize));
}
@ -107,9 +103,9 @@ public class SimLogger {
}
public void uploaded(int taskId, int datacenterId, int hostId, int vmId, int vmType) {
taskMap.get(taskId).taskUploaded(datacenterId, hostId, vmId,vmType);
taskMap.get(taskId).taskUploaded(datacenterId, hostId, vmId, vmType);
}
public void downloadStarted(int taskId, double taskDownloadTime) {
taskMap.get(taskId).taskDownloadStarted(taskDownloadTime);
}
@ -122,233 +118,419 @@ public class SimLogger {
taskMap.get(taskId).taskRejectedDueToVMCapacity(taskRejectTime);
}
public void rejectedDueToBandwidth(int taskId, double taskRejectTime) {
taskMap.get(taskId).taskRejectedDueToBandwidth(taskRejectTime);
public void rejectedDueToBandwidth(int taskId, double taskRejectTime, int vmType) {
taskMap.get(taskId).taskRejectedDueToBandwidth(taskRejectTime, vmType);
}
public void failedDueToBandwidth(int taskId, double taskRejectTime) {
taskMap.get(taskId).taskFailedDueToBandwidth(taskRejectTime);
}
public void failedDueToMobility(int taskId, double time) {
taskMap.get(taskId).taskFailedDueToMobility(time);
}
public void addVmUtilizationLog(double time, double load) {
vmLoadList.add(new VmLoadLogItem(time, load));
}
public void simStopped() throws IOException {
File file1=null,file2=null,file3=null,file4=null,file5=null;
FileWriter fileWriter1=null,fileWriter2=null,fileWriter3=null,fileWriter4=null,fileWriter5=null;
BufferedWriter bufferedWriter1=null,bufferedWriter2=null,bufferedWriter3=null,bufferedWriter4=null,bufferedWriter5=null;
int uncompletedTaskOnCloudlet = 0;
int completedTaskOnCloudlet = 0;
int uncompletedTaskOnCloud = 0;
int completedTaskOnCloud = 0;
int rejectedTaskDoToVmCapacity = 0;
int rejectedTaskDoToBandwidth = 0;
int failedTaskDuetoBandwidth = 0;
int failedTaskDuetoMobility = 0;
int totalCompletedTask = 0;
int totalFailedTask = 0;
double totalCost = 0;
double totalLanDelay = 0;
double totalWanDelay = 0;
double totalServiceTime = 0;
double totalNetworkDelay = 0;
double totalProcessingTime = 0;
double totalVmLoad = 0;
int numOfAppTypes = SimSettings.getInstance().getTaskLookUpTable().length;
//open all files and prepare them for write
if(fileLogEnabled){
if(SimSettings.getInstance().getDeepFileLoggingEnabled()){
file1 = new File(outputFolder, filePrefix+"_SUCCESS.log");
fileWriter1 = new FileWriter(file1, true);
bufferedWriter1 = new BufferedWriter(fileWriter1);
file2 = new File(outputFolder, filePrefix+"_FAIL.log");
fileWriter2 = new FileWriter(file2, true);
bufferedWriter2 = new BufferedWriter(fileWriter2);
File successFile = null, failFile = null, vmLoadFile = null, locationFile = null;
FileWriter successFW = null, failFW = null, vmLoadFW = null, locationFW = null;
BufferedWriter successBW = null, failBW = null, vmLoadBW = null, locationBW = null;
// Save generic results to file for each app type. last index is average
// of all app types
File[] genericFiles = new File[numOfAppTypes + 1];
FileWriter[] genericFWs = new FileWriter[numOfAppTypes + 1];
BufferedWriter[] genericBWs = new BufferedWriter[numOfAppTypes + 1];
// extract following values for each app type. last index is average of
// all app types
int[] uncompletedTask = new int[numOfAppTypes + 1];
int[] uncompletedTaskOnCloud = new int[numOfAppTypes + 1];
int[] uncompletedTaskOnCloudlet = new int[numOfAppTypes + 1];
int[] completedTask = new int[numOfAppTypes + 1];
int[] completedTaskOnCloud = new int[numOfAppTypes + 1];
int[] completedTaskOnCloudlet = new int[numOfAppTypes + 1];
int[] failedTask = new int[numOfAppTypes + 1];
int[] failedTaskOnCloud = new int[numOfAppTypes + 1];
int[] failedTaskOnCloudlet = new int[numOfAppTypes + 1];
double[] networkDelay = new double[numOfAppTypes + 1];
double[] wanDelay = new double[numOfAppTypes + 1];
double[] lanDelay = new double[numOfAppTypes + 1];
double[] serviceTime = new double[numOfAppTypes + 1];
double[] serviceTimeOnCloud = new double[numOfAppTypes + 1];
double[] serviceTimeOnCloudlet = new double[numOfAppTypes + 1];
double[] processingTime = new double[numOfAppTypes + 1];
double[] processingTimeOnCloud = new double[numOfAppTypes + 1];
double[] processingTimeOnCloudlet = new double[numOfAppTypes + 1];
double[] cost = new double[numOfAppTypes + 1];
int[] failedTaskDuetoBw = new int[numOfAppTypes + 1];
int[] failedTaskDuetoLanBw = new int[numOfAppTypes + 1];
int[] failedTaskDuetoWanBw = new int[numOfAppTypes + 1];
int[] failedTaskDuetoMobility = new int[numOfAppTypes + 1];
int[] rejectedTaskDoToVmCapacity = new int[numOfAppTypes + 1];
// open all files and prepare them for write
if (fileLogEnabled) {
if (SimSettings.getInstance().getDeepFileLoggingEnabled()) {
successFile = new File(outputFolder, filePrefix + "_SUCCESS.log");
successFW = new FileWriter(successFile, true);
successBW = new BufferedWriter(successFW);
failFile = new File(outputFolder, filePrefix + "_FAIL.log");
failFW = new FileWriter(failFile, true);
failBW = new BufferedWriter(failFW);
}
file3 = new File(outputFolder, filePrefix+"_VM_LOAD.log");
fileWriter3 = new FileWriter(file3, true);
bufferedWriter3 = new BufferedWriter(fileWriter3);
file4 = new File(outputFolder, filePrefix+"_GENERIC.log");
fileWriter4 = new FileWriter(file4, true);
bufferedWriter4 = new BufferedWriter(fileWriter4);
vmLoadFile = new File(outputFolder, filePrefix + "_VM_LOAD.log");
vmLoadFW = new FileWriter(vmLoadFile, true);
vmLoadBW = new BufferedWriter(vmLoadFW);
file5 = new File(outputFolder, filePrefix+"_LOCATION.log");
fileWriter5 = new FileWriter(file5, true);
bufferedWriter5 = new BufferedWriter(fileWriter5);
if(SimSettings.getInstance().getDeepFileLoggingEnabled()){
appendToFile(bufferedWriter1, "# taskId;dataCenterId;hostId;vmId;vmType;taskType;taskLenght;taskInputType;taskOutputSize;taskStartTime;taskEndTime;nwDelay");
appendToFile(bufferedWriter2, "# taskId;dataCenterId;hostId;vmId;vmType;taskType;taskLenght;taskInputType;taskOutputSize;taskStartTime;taskEndTime;failReason");
locationFile = new File(outputFolder, filePrefix + "_LOCATION.log");
locationFW = new FileWriter(locationFile, true);
locationBW = new BufferedWriter(locationFW);
for (int i = 0; i < numOfAppTypes + 1; i++) {
String fileName = "ALL_APPS_GENERIC.log";
if (i < numOfAppTypes) {
// if related app is not used in this simulation, just
// discard it
if (SimSettings.getInstance().getTaskLookUpTable()[i][0] == 0)
continue;
fileName = SimSettings.APP_TYPES.values()[i] + "_GENERIC.log";
}
genericFiles[i] = new File(outputFolder, filePrefix + "_" + fileName);
genericFWs[i] = new FileWriter(genericFiles[i], true);
genericBWs[i] = new BufferedWriter(genericFWs[i]);
appendToFile(genericBWs[i], "#auto generated file!");
}
appendToFile(bufferedWriter3, "# time;load");
appendToFile(bufferedWriter4, "# completedTask;uncompletedTask;rejectedTask;failedDueToMobilityTask;avgFailure;avgServiceTime;avgNetworkDelay;avgServerLoad;avgCost");
appendToFile(bufferedWriter5, "# time;#ofClient@PlaceType1;#ofClient@PlaceTypen");
if (SimSettings.getInstance().getDeepFileLoggingEnabled()) {
appendToFile(successBW, "#auto generated file!");
appendToFile(failBW, "#auto generated file!");
}
appendToFile(vmLoadBW, "#auto generated file!");
appendToFile(locationBW, "#auto generated file!");
}
//extract the result of each task and write it to the file if required
// extract the result of each task and write it to the file if required
for (Map.Entry<Integer, LogItem> entry : taskMap.entrySet()) {
Integer key = entry.getKey();
LogItem value = entry.getValue();
if(value.isInWarmUpPeriod())
if (value.isInWarmUpPeriod())
continue;
if(value.getStatus() == SimLogger.TASK_STATUS.COMLETED){
if(value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal()){
completedTaskOnCloud++;
totalWanDelay += value.getNetworkDelay();
}
else{
completedTaskOnCloudlet++;
totalLanDelay += value.getNetworkDelay();
}
totalCost += value.getCost();
totalServiceTime += value.getServiceTime();
totalNetworkDelay += value.getNetworkDelay();
totalProcessingTime += (value.getServiceTime() - value.getNetworkDelay());
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(bufferedWriter1, value.toString(key));
}
else if(value.getStatus() == SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY){
rejectedTaskDoToVmCapacity++;
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(bufferedWriter2, value.toString(key));
}
else if(value.getStatus() == SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH){
rejectedTaskDoToBandwidth++;
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(bufferedWriter2, value.toString(key));
}
else if(value.getStatus() == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH){
failedTaskDuetoBandwidth++;
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(bufferedWriter2, value.toString(key));
}
else if(value.getStatus() == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY){
failedTaskDuetoMobility++;
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(bufferedWriter2, value.toString(key));
}
else {
if(value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
uncompletedTaskOnCloud++;
if (value.getStatus() == SimLogger.TASK_STATUS.COMLETED) {
completedTask[value.getTaskType()]++;
if (value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
completedTaskOnCloud[value.getTaskType()]++;
else
uncompletedTaskOnCloudlet++;
completedTaskOnCloudlet[value.getTaskType()]++;
} else {
failedTask[value.getTaskType()]++;
if (value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
failedTaskOnCloud[value.getTaskType()]++;
else
failedTaskOnCloudlet[value.getTaskType()]++;
}
if (value.getStatus() == SimLogger.TASK_STATUS.COMLETED) {
cost[value.getTaskType()] += value.getCost();
serviceTime[value.getTaskType()] += value.getServiceTime();
networkDelay[value.getTaskType()] += value.getNetworkDelay();
processingTime[value.getTaskType()] += (value.getServiceTime() - value.getNetworkDelay());
if (value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal()) {
wanDelay[value.getTaskType()] += value.getNetworkDelay();
serviceTimeOnCloud[value.getTaskType()] += value.getServiceTime();
processingTimeOnCloud[value.getTaskType()] += (value.getServiceTime() - value.getNetworkDelay());
} else {
lanDelay[value.getTaskType()] += value.getNetworkDelay();
serviceTimeOnCloudlet[value.getTaskType()] += value.getServiceTime();
processingTimeOnCloudlet[value.getTaskType()] += (value.getServiceTime() - value.getNetworkDelay());
}
if (fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(successBW, value.toString(key));
} else if (value.getStatus() == SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY) {
rejectedTaskDoToVmCapacity[value.getTaskType()]++;
if (value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
if (fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(failBW, value.toString(key));
} else if (value.getStatus() == SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH
|| value.getStatus() == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH) {
failedTaskDuetoBw[value.getTaskType()]++;
if (value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
failedTaskDuetoWanBw[value.getTaskType()]++;
else
failedTaskDuetoLanBw[value.getTaskType()]++;
if (fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(failBW, value.toString(key));
} else if (value.getStatus() == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY) {
failedTaskDuetoMobility[value.getTaskType()]++;
if (fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
appendToFile(failBW, value.toString(key));
} else {
uncompletedTask[value.getTaskType()]++;
if (value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
uncompletedTaskOnCloud[value.getTaskType()]++;
else
uncompletedTaskOnCloudlet[value.getTaskType()]++;
}
}
totalFailedTask = rejectedTaskDoToVmCapacity+rejectedTaskDoToBandwidth+failedTaskDuetoBandwidth;
totalCompletedTask = completedTaskOnCloudlet+completedTaskOnCloud;
//calculate server load
for(VmLoadLogItem entry : vmLoadList){
// calculate total values
uncompletedTask[numOfAppTypes] = IntStream.of(uncompletedTask).sum();
uncompletedTaskOnCloud[numOfAppTypes] = IntStream.of(uncompletedTaskOnCloud).sum();
uncompletedTaskOnCloudlet[numOfAppTypes] = IntStream.of(uncompletedTaskOnCloudlet).sum();
completedTask[numOfAppTypes] = IntStream.of(completedTask).sum();
completedTaskOnCloud[numOfAppTypes] = IntStream.of(completedTaskOnCloud).sum();
completedTaskOnCloudlet[numOfAppTypes] = IntStream.of(completedTaskOnCloudlet).sum();
failedTask[numOfAppTypes] = IntStream.of(failedTask).sum();
failedTaskOnCloud[numOfAppTypes] = IntStream.of(failedTaskOnCloud).sum();
failedTaskOnCloudlet[numOfAppTypes] = IntStream.of(failedTaskOnCloudlet).sum();
networkDelay[numOfAppTypes] = DoubleStream.of(networkDelay).sum();
lanDelay[numOfAppTypes] = DoubleStream.of(lanDelay).sum();
wanDelay[numOfAppTypes] = DoubleStream.of(wanDelay).sum();
serviceTime[numOfAppTypes] = DoubleStream.of(serviceTime).sum();
serviceTimeOnCloud[numOfAppTypes] = DoubleStream.of(serviceTimeOnCloud).sum();
serviceTimeOnCloudlet[numOfAppTypes] = DoubleStream.of(serviceTimeOnCloudlet).sum();
processingTime[numOfAppTypes] = DoubleStream.of(processingTime).sum();
processingTimeOnCloud[numOfAppTypes] = DoubleStream.of(processingTimeOnCloud).sum();
processingTimeOnCloudlet[numOfAppTypes] = DoubleStream.of(processingTimeOnCloudlet).sum();
cost[numOfAppTypes] = DoubleStream.of(cost).sum();
failedTaskDuetoBw[numOfAppTypes] = IntStream.of(failedTaskDuetoBw).sum();
failedTaskDuetoWanBw[numOfAppTypes] = IntStream.of(failedTaskDuetoWanBw).sum();
failedTaskDuetoLanBw[numOfAppTypes] = IntStream.of(failedTaskDuetoLanBw).sum();
failedTaskDuetoMobility[numOfAppTypes] = IntStream.of(failedTaskDuetoMobility).sum();
rejectedTaskDoToVmCapacity[numOfAppTypes] = IntStream.of(rejectedTaskDoToVmCapacity).sum();
// calculate server load
double totalVmLoad = 0;
for (VmLoadLogItem entry : vmLoadList) {
totalVmLoad += entry.getLoad();
if(fileLogEnabled)
appendToFile(bufferedWriter3, entry.toString());
if (fileLogEnabled)
appendToFile(vmLoadBW, entry.toString());
}
if(fileLogEnabled){
//write location info to file
for(int t=1; t<(SimSettings.getInstance().getSimulationTime()/SimSettings.getInstance().getVmLocationLogInterval()); t++){
if (fileLogEnabled) {
// write location info to file
for (int t = 1; t < (SimSettings.getInstance().getSimulationTime()
/ SimSettings.getInstance().getVmLocationLogInterval()); t++) {
int[] locationInfo = new int[SimSettings.PLACE_TYPES.values().length];
for(int i=0; i<SimManager.getInstance().getNumOfMobileDevice(); i++) {
Location loc = SimManager.getInstance().getMobilityModel().getLocation(i, t*SimSettings.getInstance().getVmLocationLogInterval());
Double time = t * SimSettings.getInstance().getVmLocationLogInterval();
if (time < SimSettings.getInstance().getWarmUpPeriod())
continue;
for (int i = 0; i < SimManager.getInstance().getNumOfMobileDevice(); i++) {
Location loc = SimManager.getInstance().getMobilityModel().getLocation(i, time);
SimSettings.PLACE_TYPES placeType = loc.getPlaceType();
locationInfo[placeType.ordinal()]++;
}
Double time=t*SimSettings.getInstance().getVmLocationLogInterval();
bufferedWriter5.write(time.toString());
for(int i=0; i<locationInfo.length; i++)
bufferedWriter5.write(SimSettings.DELIMITER + locationInfo[i]);
bufferedWriter5.newLine();
}
//write generic results
String genericResult = Integer.toString(completedTaskOnCloudlet) + SimSettings.DELIMITER +
Integer.toString(uncompletedTaskOnCloudlet) + SimSettings.DELIMITER +
Integer.toString(completedTaskOnCloud) + SimSettings.DELIMITER +
Integer.toString(uncompletedTaskOnCloud) + SimSettings.DELIMITER +
Integer.toString(rejectedTaskDoToVmCapacity) + SimSettings.DELIMITER +
Integer.toString(rejectedTaskDoToBandwidth) + SimSettings.DELIMITER +
Integer.toString(failedTaskDuetoBandwidth) + SimSettings.DELIMITER +
Integer.toString(failedTaskDuetoMobility) + SimSettings.DELIMITER +
Double.toString(((double)totalFailedTask*(double)100)/(double)(totalCompletedTask+totalFailedTask)) + SimSettings.DELIMITER +
Double.toString(totalServiceTime/(double)totalCompletedTask) + SimSettings.DELIMITER +
Double.toString(totalNetworkDelay/(double)totalCompletedTask) + SimSettings.DELIMITER +
Double.toString(totalLanDelay/(double)totalCompletedTask) + SimSettings.DELIMITER +
Double.toString(totalWanDelay/(double)totalCompletedTask) + SimSettings.DELIMITER +
Double.toString(totalProcessingTime/(double)totalCompletedTask) + SimSettings.DELIMITER +
Double.toString(totalVmLoad/(double)vmLoadList.size()) + SimSettings.DELIMITER +
Double.toString(totalCost/(double)totalCompletedTask);
appendToFile(bufferedWriter4,genericResult);
//close open files
if(SimSettings.getInstance().getDeepFileLoggingEnabled()){
bufferedWriter1.close();
bufferedWriter2.close();
}
bufferedWriter3.close();
bufferedWriter4.close();
bufferedWriter5.close();
}
//printout important results
printLine("# of uncompleted tasks on Cloudlet/Cloud: " + uncompletedTaskOnCloudlet + "/" + uncompletedTaskOnCloud);
printLine("# of completed task on Cloudlet/Cloud: " + (completedTaskOnCloudlet+uncompletedTaskOnCloudlet) + "/" + (completedTaskOnCloud+uncompletedTaskOnCloud));
printLine("# of rejected tasks (due to vm capacity): " + rejectedTaskDoToVmCapacity);
printLine("# of rejected tasks (due to bandwidth): " + rejectedTaskDoToBandwidth);
printLine("# of failed tasks (due to bandwidth): " + failedTaskDuetoBandwidth);
printLine("# of failed tasks (due to mobility): " + failedTaskDuetoMobility);
printLine("percentage of failed task: " + String.format("%.6f", ((double)totalFailedTask*(double)100)/(double)(totalCompletedTask+totalFailedTask)) + "%");
printLine("average service time: " + String.format("%.6f", totalServiceTime/(double)totalCompletedTask) + " seconds. ("
+ "processing time: " + String.format("%.6f", totalProcessingTime/(double)totalCompletedTask) + ")");
printLine("average netwrok delay: " + String.format("%.6f", totalNetworkDelay/(double)totalCompletedTask) + " seconds. ("
+ "LAN delay: " + String.format("%.6f", totalLanDelay/(double)totalCompletedTask) + ", "
+ "WAN delay: " + String.format("%.6f", totalWanDelay/(double)totalCompletedTask) + ")");
printLine("average server utilization: " + String.format("%.6f", totalVmLoad/(double)vmLoadList.size()) + "%");
printLine("average cost: " + totalCost/totalCompletedTask + "$");
//clear related collections (map list etc.)
locationBW.write(time.toString());
for (int i = 0; i < locationInfo.length; i++)
locationBW.write(SimSettings.DELIMITER + locationInfo[i]);
locationBW.newLine();
}
for (int i = 0; i < numOfAppTypes + 1; i++) {
if (i < numOfAppTypes) {
// if related app is not used in this simulation, just
// discard it
if (SimSettings.getInstance().getTaskLookUpTable()[i][0] == 0)
continue;
}
// check if the divisor is zero in order to avoid division by
// zero problem
double _serviceTime = (completedTask[i] == 0) ? 0.0 : (serviceTime[i] / (double) completedTask[i]);
double _networkDelay = (completedTask[i] == 0) ? 0.0 : (networkDelay[i] / (double) completedTask[i]);
double _processingTime = (completedTask[i] == 0) ? 0.0 : (processingTime[i] / (double) completedTask[i]);
double _vmLoad = (vmLoadList.size() == 0) ? 0.0 : (totalVmLoad / (double) vmLoadList.size());
double _cost = (completedTask[i] == 0) ? 0.0 : (cost[i] / (double) completedTask[i]);
// write generic results
String genericResult1 = Integer.toString(completedTask[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTask[i]) + SimSettings.DELIMITER
+ Integer.toString(uncompletedTask[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTaskDuetoBw[i]) + SimSettings.DELIMITER
+ Double.toString(_serviceTime) + SimSettings.DELIMITER
+ Double.toString(_processingTime) + SimSettings.DELIMITER
+ Double.toString(_networkDelay) + SimSettings.DELIMITER
+ Double.toString(_vmLoad) + SimSettings.DELIMITER
+ Double.toString(_cost) + SimSettings.DELIMITER
+ Integer.toString(rejectedTaskDoToVmCapacity[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTaskDuetoMobility[i]);
// check if the divisor is zero in order to avoid division by
// zero problem
double _lanDelay = (completedTaskOnCloudlet[i] == 0) ? 0.0
: (lanDelay[i] / (double) completedTaskOnCloudlet[i]);
double _serviceTimeOnCloudlet = (completedTaskOnCloudlet[i] == 0) ? 0.0
: (serviceTimeOnCloudlet[i] / (double) completedTaskOnCloudlet[i]);
double _processingTimeOnCloudlet = (completedTaskOnCloudlet[i] == 0) ? 0.0
: (processingTimeOnCloudlet[i] / (double) completedTaskOnCloudlet[i]);
String genericResult2 = Integer.toString(completedTaskOnCloudlet[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTaskOnCloudlet[i]) + SimSettings.DELIMITER
+ Integer.toString(uncompletedTaskOnCloudlet[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTaskDuetoLanBw[i]) + SimSettings.DELIMITER
+ Double.toString(_serviceTimeOnCloudlet) + SimSettings.DELIMITER
+ Double.toString(_processingTimeOnCloudlet) + SimSettings.DELIMITER
+ Double.toString(_lanDelay);
// check if the divisor is zero in order to avoid division by
// zero problem
double _wanDelay = (completedTaskOnCloud[i] == 0) ? 0.0
: (wanDelay[i] / (double) completedTaskOnCloud[i]);
double _serviceTimeOnCloud = (completedTaskOnCloud[i] == 0) ? 0.0
: (serviceTimeOnCloud[i] / (double) completedTaskOnCloud[i]);
double _processingTimeOnCloud = (completedTaskOnCloud[i] == 0) ? 0.0
: (processingTimeOnCloud[i] / (double) completedTaskOnCloud[i]);
String genericResult3 = Integer.toString(completedTaskOnCloud[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTaskOnCloud[i]) + SimSettings.DELIMITER
+ Integer.toString(uncompletedTaskOnCloud[i]) + SimSettings.DELIMITER
+ Integer.toString(failedTaskDuetoWanBw[i]) + SimSettings.DELIMITER
+ Double.toString(_serviceTimeOnCloud) + SimSettings.DELIMITER
+ Double.toString(_processingTimeOnCloud) + SimSettings.DELIMITER
+ Double.toString(_wanDelay);
appendToFile(genericBWs[i], genericResult1);
appendToFile(genericBWs[i], genericResult2);
appendToFile(genericBWs[i], genericResult3);
}
// close open files
if (SimSettings.getInstance().getDeepFileLoggingEnabled()) {
successBW.close();
failBW.close();
}
vmLoadBW.close();
locationBW.close();
for (int i = 0; i < numOfAppTypes + 1; i++) {
if (i < numOfAppTypes) {
// if related app is not used in this simulation, just
// discard it
if (SimSettings.getInstance().getTaskLookUpTable()[i][0] == 0)
continue;
}
genericBWs[i].close();
}
}
// printout important results
printLine("# of tasks (Cloudlet/Cloud): "
+ (failedTask[numOfAppTypes] + completedTask[numOfAppTypes]) + "("
+ (failedTaskOnCloudlet[numOfAppTypes] + completedTaskOnCloudlet[numOfAppTypes]) + "/"
+ (failedTaskOnCloud[numOfAppTypes]+ completedTaskOnCloud[numOfAppTypes]) + ")");
printLine("# of failed tasks (Cloudlet/Cloud): "
+ failedTask[numOfAppTypes] + "("
+ failedTaskOnCloudlet[numOfAppTypes]
+ "/" + failedTaskOnCloud[numOfAppTypes] + ")");
printLine("# of completed tasks (Cloudlet/Cloud): "
+ completedTask[numOfAppTypes] + "("
+ completedTaskOnCloudlet[numOfAppTypes]
+ "/" + completedTaskOnCloud[numOfAppTypes] + ")");
printLine("# of uncompleted tasks (Cloudlet/Cloud): "
+ uncompletedTask[numOfAppTypes] + "("
+ uncompletedTaskOnCloudlet[numOfAppTypes]
+ "/" + uncompletedTaskOnCloud[numOfAppTypes] + ")");
printLine("# of failed tasks due to vm capacity/LAN bw/WAN bw/mobility: "
+ rejectedTaskDoToVmCapacity[numOfAppTypes]
+ "/" + +failedTaskDuetoLanBw[numOfAppTypes]
+ "/" + +failedTaskDuetoWanBw[numOfAppTypes]
+ "/" + failedTaskDuetoMobility[numOfAppTypes]);
printLine("percentage of failed tasks: "
+ String.format("%.6f", ((double) failedTask[numOfAppTypes] * (double) 100)
/ (double) (completedTask[numOfAppTypes] + failedTask[numOfAppTypes]))
+ "%");
printLine("average service time: "
+ String.format("%.6f", serviceTime[numOfAppTypes] / (double) completedTask[numOfAppTypes])
+ " seconds. (" + "on Cloudlet: "
+ String.format("%.6f", serviceTimeOnCloudlet[numOfAppTypes] / (double) completedTaskOnCloudlet[numOfAppTypes])
+ ", " + "on Cloud: "
+ String.format("%.6f", serviceTimeOnCloud[numOfAppTypes] / (double) completedTaskOnCloud[numOfAppTypes])
+ ")");
printLine("average processing time: "
+ String.format("%.6f", processingTime[numOfAppTypes] / (double) completedTask[numOfAppTypes])
+ " seconds. (" + "on Cloudlet: "
+ String.format("%.6f", processingTimeOnCloudlet[numOfAppTypes] / (double) completedTaskOnCloudlet[numOfAppTypes])
+ ", " + "on Cloud: "
+ String.format("%.6f", processingTimeOnCloud[numOfAppTypes] / (double) completedTaskOnCloud[numOfAppTypes])
+ ")");
printLine("average netwrok delay: "
+ String.format("%.6f", networkDelay[numOfAppTypes] / (double) completedTask[numOfAppTypes])
+ " seconds. (" + "LAN delay: "
+ String.format("%.6f", lanDelay[numOfAppTypes] / (double) completedTaskOnCloudlet[numOfAppTypes])
+ ", " + "WAN delay: "
+ String.format("%.6f", wanDelay[numOfAppTypes] / (double) completedTaskOnCloud[numOfAppTypes]) + ")");
printLine("average server utilization: "
+ String.format("%.6f", totalVmLoad / (double) vmLoadList.size()) + "%");
printLine("average cost: " + cost[numOfAppTypes] / completedTask[numOfAppTypes] + "$");
// clear related collections (map list etc.)
taskMap.clear();
vmLoadList.clear();
}
}
class VmLoadLogItem
{
class VmLoadLogItem {
private double time;
private double vmLoad;
VmLoadLogItem(double _time, double _vmLoad)
{
VmLoadLogItem(double _time, double _vmLoad) {
time = _time;
vmLoad = _vmLoad;
}
public double getLoad()
{
public double getLoad() {
return vmLoad;
}
public String toString()
{
public String toString() {
return time + SimSettings.DELIMITER + vmLoad;
}
}
class LogItem
{
class LogItem {
private SimLogger.TASK_STATUS status;
private int datacenterId;
private int hostId;
@ -364,104 +546,118 @@ class LogItem
private double bwCost;
private double cpuCost;
private boolean isInWarmUpPeriod;
LogItem (double _taskStartTime, int _taskType, int _taskLenght, int _taskInputType, int _taskOutputSize)
{
LogItem(double _taskStartTime, int _taskType, int _taskLenght, int _taskInputType, int _taskOutputSize) {
taskStartTime = _taskStartTime;
taskType=_taskType;
taskLenght=_taskLenght;
taskInputType=_taskInputType;
taskOutputSize=_taskOutputSize;
taskType = _taskType;
taskLenght = _taskLenght;
taskInputType = _taskInputType;
taskOutputSize = _taskOutputSize;
status = SimLogger.TASK_STATUS.CREATED;
taskEndTime = 0;
if(_taskStartTime < SimSettings.getInstance().getWarmUpPeriod())
if (_taskStartTime < SimSettings.getInstance().getWarmUpPeriod())
isInWarmUpPeriod = true;
else
isInWarmUpPeriod = false;
}
public void taskUploadStarted(double taskUploadTime) {
networkDelay += taskUploadTime;
status = SimLogger.TASK_STATUS.UPLOADING;
}
public void taskUploaded(int _datacenterId, int _hostId, int _vmId, int _vmType) {
status = SimLogger.TASK_STATUS.PROCESSING;
datacenterId = _datacenterId;
hostId = _hostId;
vmId = _vmId;
vmType=_vmType;
vmType = _vmType;
}
public void taskDownloadStarted(double taskDownloadTime) {
networkDelay += taskDownloadTime;
status = SimLogger.TASK_STATUS.DOWNLOADING;
}
public void taskDownloaded(double _taskEndTime) {
taskEndTime = _taskEndTime;
status = SimLogger.TASK_STATUS.COMLETED;
}
public void taskRejectedDueToVMCapacity(double _taskRejectTime) {
taskEndTime = _taskRejectTime;
status = SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY;
}
public void taskRejectedDueToBandwidth(double _taskRejectTime) {
public void taskRejectedDueToBandwidth(double _taskRejectTime, int _vmType) {
vmType = _vmType;
taskEndTime = _taskRejectTime;
status = SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH;
}
public void taskFailedDueToBandwidth(double _time) {
taskEndTime = _time;
status = SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH;
}
public void taskFailedDueToMobility(double _time) {
taskEndTime = _time;
status = SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY;
}
public void setCost(double _bwCost, double _cpuCos) {
bwCost = _bwCost;
cpuCost = _cpuCos;
}
public boolean isInWarmUpPeriod(){
public boolean isInWarmUpPeriod() {
return isInWarmUpPeriod;
}
public double getCost() {
return bwCost + cpuCost;
}
public double getNetworkDelay() {
return networkDelay;
}
public double getServiceTime() {
return taskEndTime - taskStartTime;
}
public SimLogger.TASK_STATUS getStatus(){
public SimLogger.TASK_STATUS getStatus() {
return status;
}
public int getVmType(){
public int getVmType() {
return vmType;
}
public String toString (int taskId)
{
String result = taskId + SimSettings.DELIMITER +
datacenterId + SimSettings.DELIMITER +
hostId + SimSettings.DELIMITER +
vmId + SimSettings.DELIMITER +
vmType + SimSettings.DELIMITER +
taskType + SimSettings.DELIMITER +
taskLenght + SimSettings.DELIMITER +
taskInputType + SimSettings.DELIMITER +
taskOutputSize + SimSettings.DELIMITER +
taskStartTime + SimSettings.DELIMITER +
taskEndTime + SimSettings.DELIMITER;
if(status == SimLogger.TASK_STATUS.COMLETED)
public int getTaskType() {
return taskType;
}
public String toString(int taskId) {
String result = taskId + SimSettings.DELIMITER + datacenterId + SimSettings.DELIMITER + hostId
+ SimSettings.DELIMITER + vmId + SimSettings.DELIMITER + vmType + SimSettings.DELIMITER + taskType
+ SimSettings.DELIMITER + taskLenght + SimSettings.DELIMITER + taskInputType + SimSettings.DELIMITER
+ taskOutputSize + SimSettings.DELIMITER + taskStartTime + SimSettings.DELIMITER + taskEndTime
+ SimSettings.DELIMITER;
if (status == SimLogger.TASK_STATUS.COMLETED)
result += networkDelay;
else if(status == SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY)
result +="1"; //failure reason 1
else if(status == SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH)
result +="2"; //failure reason 2
else if(status == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH)
result +="3"; //failure reason 3
else if(status == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY)
result +="4"; //failure reason 4
else if (status == SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY)
result += "1"; // failure reason 1
else if (status == SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH)
result += "2"; // failure reason 2
else if (status == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH)
result += "3"; // failure reason 3
else if (status == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY)
result += "4"; // failure reason 4
else
result +="0"; //default failure reason
result += "0"; // default failure reason
return result;
}
}