Time 在CloudSim中打印迁移时间
我想在cloud sim中实现虚拟机迁移时间公式,我做了一个简单的方法,但它给了我错误的结果,问题是我需要模拟中迁移的虚拟机列表,这样我才能最终计算并打印总迁移时间,如果你有任何想法,请帮助我Time 在CloudSim中打印迁移时间,time,migration,virtual-machine,cloudsim,Time,Migration,Virtual Machine,Cloudsim,我想在cloud sim中实现虚拟机迁移时间公式,我做了一个简单的方法,但它给了我错误的结果,问题是我需要模拟中迁移的虚拟机列表,这样我才能最终计算并打印总迁移时间,如果你有任何想法,请帮助我 public static double getTotalMigrationTime(List<Vm> vms){ double Tmigr = 0; for(Vm vm:vms){ if(vm.isInMigration()){ double
public static double getTotalMigrationTime(List<Vm> vms){
double Tmigr = 0;
for(Vm vm:vms){
if(vm.isInMigration()){
double Cj = vm.getRam();
double BWj = vm.getBw();
Tmigr += Cj/BWj;
}
}
return Tmigr;
}
publicstaticdouble-getTotalMigrationTime(列出虚拟机){
双Tmigr=0;
用于(虚拟机:虚拟机){
if(vm.isInMigration()){
双Cj=vm.getRam();
double BWj=vm.getBw();
Tmigr+=Cj/BWj;
}
}
返回Tmigr;
}
您必须在PowerDatacenter类中添加迁移和能量公式,更准确地说,是在UpdateLoudletProcessing方法中,还必须在不忘记类中局部变量的情况下添加set和get方法,以节省迁移时间和能量
// Migration Time
public double Tmigr = 0;
// Migration Energy
public double Emigr;
@Override
protected void updateCloudletProcessing() {
if (getCloudletSubmitted() == -1 || getCloudletSubmitted() == CloudSim.clock()) {
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.VM_DATACENTER_EVENT));
schedule(getId(), getSchedulingInterval(), CloudSimTags.VM_DATACENTER_EVENT);
return;
}
double currentTime = CloudSim.clock();
double Pm = 4.5;
double sum = 0;
// if some time passed since last processing
if (currentTime > getLastProcessTime()) {
System.out.print(currentTime + " ");
double minTime = updateCloudetProcessingWithoutSchedulingFutureEventsForce();
if (!isDisableMigrations()) {
List<Map<String, Object>> migrationMap = getVmAllocationPolicy().optimizeAllocation(
getVmList());
if (migrationMap != null) {
for (Map<String, Object> migrate : migrationMap) {
Vm vm = (Vm) migrate.get("vm");
PowerHost targetHost = (PowerHost) migrate.get("host");
PowerHost oldHost = (PowerHost) vm.getHost();
// Calculates migration time and energy
double Cj = vm.getRam();
double BWj = (double)targetHost.getBw()/(2*8000);
Tmigr = Tmigr + Cj/BWj; // Time
sum = sum + Pm*(Cj/BWj);
Emigr = 4*sum; //energy
if (oldHost == null) {
Log.formatLine(
"%.2f: Migration of VM #%d to Host #%d is started",
currentTime,
vm.getId(),
targetHost.getId());
} else {
Log.formatLine(
"%.2f: Migration of VM #%d from Host #%d to Host #%d is started",
currentTime,
vm.getId(),
oldHost.getId(),
targetHost.getId());
}
targetHost.addMigratingInVm(vm);
incrementMigrationCount();
/** VM migration delay = RAM / bandwidth **/
// we use BW / 2 to model BW available for migration purposes, the other
// half of BW is for VM communication
// around 16 seconds for 1024 MB using 1 Gbit/s network
send(
getId(),
vm.getRam() / ((double) targetHost.getBw() / (2 * 8000)),
CloudSimTags.VM_MIGRATE,
migrate);
}
}
}
// schedules an event to the next time
if (minTime != Double.MAX_VALUE) {
CloudSim.cancelAll(getId(), new PredicateType(CloudSimTags.VM_DATACENTER_EVENT));
send(getId(), getSchedulingInterval(), CloudSimTags.VM_DATACENTER_EVENT);
}
setLastProcessTime(currentTime);
}
setMigrationTime(Tmigr); // Update Total Migration Time
setMigrationEnergy(Emigr); // Update Total Migration Energy
}
// sets migration time
public void setMigrationTime(double Tm){
Tmigr = Tm;
}
//gets migration time
public double getMigrationTime(){
return Tmigr;
}
//sets migration Energy
public void setMigrationEnergy(double Em){
Emigr = Em;
}
//gets total migration energy
public double getMigrationEnergy(){
return Emigr;
}
//get Migration Time and energy from PowerDatacenter class
double Tmigr = datacenter.getMigrationTime();
double Emigr = datacenter.getMigrationEnergy()/(3600*1000);
Log.printLine(String.format("Migration Time : %.2f sec",Tmigr));
Log.printLine(String.format("Migration Energy : %.5f kWh",Emigr));