-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.java
More file actions
857 lines (775 loc) · 27.3 KB
/
Copy pathHelper.java
File metadata and controls
857 lines (775 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
package MyProject;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerDynamicWorkload;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.HostDynamicWorkload;
import org.cloudbus.cloudsim.HostStateHistoryEntry;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicy;
import org.cloudbus.cloudsim.VmSchedulerTimeSharedOverSubscription;
import org.cloudbus.cloudsim.VmStateHistoryEntry;
import org.cloudbus.cloudsim.power.PowerDatacenter;
import org.cloudbus.cloudsim.power.PowerDatacenterBroker;
import org.cloudbus.cloudsim.power.PowerHost;
import org.cloudbus.cloudsim.power.PowerHostUtilizationHistory;
import org.cloudbus.cloudsim.power.PowerVm;
import org.cloudbus.cloudsim.power.PowerVmAllocationPolicyMigrationAbstract;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
import org.cloudbus.cloudsim.util.MathUtil;
import com.sun.corba.se.spi.orbutil.fsm.State;
import MyProject.LAutomata.Status;
/**
* The Class Helper.
*
* If you are using any algorithms, policies or workload included in the power
* package, please cite
*
* Anton Beloglazov, and Rajkumar Buyya, "Optimal Online Deterministic
* Algorithms and Adaptive Heuristics for Energy and Performance Efficient
* Dynamic Consolidation of Virtual Machines in Cloud Data Centers", Concurrency
* and Computation: Practice and Experience (CCPE), Volume 24, Issue 13, Pages:
* 1397-1420, John Wiley & Sons, Ltd, New York, USA, 2012
*
* @author Anton Beloglazov
*/
public class Helper extends Datacenter {
public Helper(String name, DatacenterCharacteristics characteristics,
VmAllocationPolicy vmAllocationPolicy, List<Storage> storageList,
double schedulingInterval) throws Exception {
super(name, characteristics, vmAllocationPolicy, storageList,
schedulingInterval);
// TODO Auto-generated constructor stub
}
public static List<PowerHost> hostList = new ArrayList<PowerHost>();
public static HashMap<Integer, PowerHost> host = new HashMap<Integer, PowerHost>();
public static int u = 0;
static LAPlacementVM REcount = new LAPlacementVM();
/**
* Creates the vm list.
*
* @param brokerId
* the broker id
* @param vmsNumber
* the vms number
*
* @return the list< vm>
*/
public static List<Vm> createVmList(int brokerId, int vmsNumber) {
List<Vm> vms = new ArrayList<Vm>();
for (int i = 0; i < vmsNumber; i++) {
int vmType = i
/ (int) Math.ceil((double) vmsNumber / Constants.VM_TYPES);
vms.add(new PowerVm(
i,
brokerId,
Constants.VM_MIPS[vmType],
Constants.VM_PES[vmType],
Constants.VM_RAM[vmType],
Constants.VM_BW,
Constants.VM_SIZE,
1,
"Xen",
new CloudletSchedulerDynamicWorkload(
Constants.VM_MIPS[vmType], Constants.VM_PES[vmType]),
Constants.SCHEDULING_INTERVAL));
}
return vms;
}
/**
* Creates the host list.
*
* @param hostsNumber
* the hosts number
*
* @return the list< power host>
*/
public static List<PowerHost> createHostList(int hostsNumber) {
for (int i = 0; i < hostsNumber; i++) {
int hostType = i % Constants.HOST_TYPES;
List<Pe> peList = new ArrayList<Pe>();
for (int j = 0; j < Constants.HOST_PES[hostType]; j++) {
peList.add(new Pe(j, new PeProvisionerSimple(
Constants.HOST_MIPS[hostType])));
}
hostList.add(new PowerHostUtilizationHistory(i,
new RamProvisionerSimple(Constants.HOST_RAM[hostType]),
new BwProvisionerSimple(Constants.HOST_BW),
Constants.HOST_STORAGE, peList,
new VmSchedulerTimeSharedOverSubscription(peList),
Constants.HOST_POWER[hostType]));
}
return hostList;
}
/**
* Creates the broker.
*
* @return the datacenter broker
*/
public static DatacenterBroker createBroker() {
DatacenterBroker broker = null;
try {
broker = new PowerDatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return broker;
}
/**
* Creates the datacenter.
*
* @param name
* the name
* @param datacenterClass
* the datacenter class
* @param hostList
* the host list
* @param vmAllocationPolicy
* the vm allocation policy
* @param simulationLength
*
* @return the power datacenter
*
* @throws Exception
* the exception
*/
public static Datacenter createDatacenter(String name,
Class<? extends Datacenter> datacenterClass,
List<PowerHost> hostList, VmAllocationPolicy vmAllocationPolicy)
throws Exception {
String arch = "x86"; // system architecture
String os = "Linux"; // operating system
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource located
double cost = 3.0; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.001; // the cost of using storage in this
// resource
double costPerBw = 0.0; // the cost of using bw in this resource
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);
Datacenter datacenter = null;
try {
datacenter = datacenterClass.getConstructor(String.class,
DatacenterCharacteristics.class, VmAllocationPolicy.class,
List.class, Double.TYPE).newInstance(name, characteristics,
vmAllocationPolicy, new LinkedList<Storage>(),
Constants.SCHEDULING_INTERVAL);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return datacenter;
}
/**
* Gets the times before host shutdown.
*
* @param hosts
* the hosts
* @return the times before host shutdown
*/
public static List<Double> getTimesBeforeHostShutdown(List<Host> hosts) {
List<Double> timeBeforeShutdown = new LinkedList<Double>();
for (Host host : hosts) {
boolean previousIsActive = true;
double lastTimeSwitchedOn = 0;
for (HostStateHistoryEntry entry : ((HostDynamicWorkload) host)
.getStateHistory()) {
if (previousIsActive == true && entry.isActive() == false) {
timeBeforeShutdown
.add(entry.getTime() - lastTimeSwitchedOn);
}
if (previousIsActive == false && entry.isActive() == true) {
lastTimeSwitchedOn = entry.getTime();
}
previousIsActive = entry.isActive();
}
}
return timeBeforeShutdown;
}
/**
* Gets the times before vm migration.
*
* @param vms
* the vms
* @return the times before vm migration
*/
public static List<Double> getTimesBeforeVmMigration(List<Vm> vms) {
List<Double> timeBeforeVmMigration = new LinkedList<Double>();
for (Vm vm : vms) {
boolean previousIsInMigration = false;
double lastTimeMigrationFinished = 0;
for (VmStateHistoryEntry entry : vm.getStateHistory()) {
if (previousIsInMigration == true
&& entry.isInMigration() == false) {
timeBeforeVmMigration.add(entry.getTime()
- lastTimeMigrationFinished);
}
if (previousIsInMigration == false
&& entry.isInMigration() == true) {
lastTimeMigrationFinished = entry.getTime();
}
previousIsInMigration = entry.isInMigration();
}
}
return timeBeforeVmMigration;
}
/**
* Gets the sla time per active host.
*
* @param hosts
* the hosts
* @return the sla time per active host
*/
protected static double getSlaTimePerActiveHost(List<Host> hosts) {
double slaViolationTimePerHost = 0;
double totalTime = 0;
for (Host _host : hosts) {
HostDynamicWorkload host = (HostDynamicWorkload) _host;
double previousTime = -1;
double previousAllocated = 0;
double previousRequested = 0;
boolean previousIsActive = true;
for (HostStateHistoryEntry entry : host.getStateHistory()) {
if (previousTime != -1 && previousIsActive) {
double timeDiff = entry.getTime() - previousTime;
totalTime += timeDiff;
if (previousAllocated < previousRequested) {
slaViolationTimePerHost += timeDiff;
}
}
previousAllocated = entry.getAllocatedMips();
previousRequested = entry.getRequestedMips();
previousTime = entry.getTime();
previousIsActive = entry.isActive();
}
}
return slaViolationTimePerHost / totalTime;
}
/**
* Gets the sla time per host.
*
* @param hosts
* the hosts
* @return the sla time per host
*/
protected static double getSlaTimePerHost(List<Host> hosts) {
double slaViolationTimePerHost = 0;
double totalTime = 0;
for (Host _host : hosts) {
HostDynamicWorkload host = (HostDynamicWorkload) _host;
double previousTime = -1;
double previousAllocated = 0;
double previousRequested = 0;
for (HostStateHistoryEntry entry : host.getStateHistory()) {
if (previousTime != -1) {
double timeDiff = entry.getTime() - previousTime;
totalTime += timeDiff;
if (previousAllocated < previousRequested) {
slaViolationTimePerHost += timeDiff;
}
}
previousAllocated = entry.getAllocatedMips();
previousRequested = entry.getRequestedMips();
previousTime = entry.getTime();
}
}
return slaViolationTimePerHost / totalTime;
}
/**
* Gets the sla metrics.
*
* @param vms
* the vms
* @return the sla metrics
*/
protected static Map<String, Double> getSlaMetrics(List<Vm> vms) {
Map<String, Double> metrics = new HashMap<String, Double>();
List<Double> slaViolation = new LinkedList<Double>();
double totalAllocated = 0;
double totalRequested = 0;
double totalUnderAllocatedDueToMigration = 0;
for (Vm vm : vms) {
double vmTotalAllocated = 0;
double vmTotalRequested = 0;
double vmUnderAllocatedDueToMigration = 0;
double previousTime = -1;
double previousAllocated = 0;
double previousRequested = 0;
boolean previousIsInMigration = false;
for (VmStateHistoryEntry entry : vm.getStateHistory()) {
if (previousTime != -1) {
double timeDiff = entry.getTime() - previousTime;
vmTotalAllocated += previousAllocated * timeDiff;
vmTotalRequested += previousRequested * timeDiff;
if (previousAllocated < previousRequested) {
slaViolation
.add((previousRequested - previousAllocated)
/ previousRequested);
if (previousIsInMigration) {
vmUnderAllocatedDueToMigration += (previousRequested - previousAllocated)
* timeDiff;
}
}
}
previousAllocated = entry.getAllocatedMips();
previousRequested = entry.getRequestedMips();
previousTime = entry.getTime();
previousIsInMigration = entry.isInMigration();
}
totalAllocated += vmTotalAllocated;
totalRequested += vmTotalRequested;
totalUnderAllocatedDueToMigration += vmUnderAllocatedDueToMigration;
}
metrics.put("overall", (totalRequested - totalAllocated)
/ totalRequested);
if (slaViolation.isEmpty()) {
metrics.put("average", 0.);
} else {
metrics.put("average", MathUtil.mean(slaViolation));
}
metrics.put("underallocated_migration",
totalUnderAllocatedDueToMigration / totalRequested);
return metrics;
}
/**
* Write data column.
*
* @param data
* the data
* @param outputPath
* the output path
*/
public static void writeDataColumn(List<? extends Number> data,
String outputPath) {
File file = new File(outputPath);
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
System.exit(0);
}
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
for (Number value : data) {
writer.write(value.toString() + "\n");
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
/**
* Write data row.
*
* @param data
* the data
* @param outputPath
* the output path
*/
public static void writeDataRow(String data, String outputPath) {
File file = new File(outputPath);
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
System.exit(0);
}
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(data);
writer.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
/**
* Write metric history.
*
* @param hosts
* the hosts
* @param vmAllocationPolicy
* the vm allocation policy
* @param outputPath
* the output path
*/
public static void writeMetricHistory(List<? extends Host> hosts,
PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy,
String outputPath) {
// for (Host host : hosts) {
for (int j = 0; j < 10; j++) {
Host host = hosts.get(j);
if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) {
continue;
}
File file = new File(outputPath + "_" + host.getId() + ".csv");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
System.exit(0);
}
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
List<Double> timeData = vmAllocationPolicy.getTimeHistory()
.get(host.getId());
List<Double> utilizationData = vmAllocationPolicy
.getUtilizationHistory().get(host.getId());
List<Double> metricData = vmAllocationPolicy.getMetricHistory()
.get(host.getId());
for (int i = 0; i < timeData.size(); i++) {
writer.write(String.format("%.2f,%.2f,%.2f\n",
timeData.get(i), utilizationData.get(i),
metricData.get(i)));
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
}
/**
* Prints the Cloudlet objects.
*
* @param list
* list of Cloudlets
*/
public static void printCloudletList(List<Cloudlet> list) {
int size = list.size();
Cloudlet cloudlet;
String indent = "\t";
Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
+ "Resource ID" + indent + "VM ID" + indent + "Time" + indent
+ "Start Time" + indent + "Finish Time");
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId());
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
Log.printLine(indent + "SUCCESS" + indent + indent
+ cloudlet.getResourceId() + indent
+ cloudlet.getVmId() + indent
+ dft.format(cloudlet.getActualCPUTime()) + indent
+ dft.format(cloudlet.getExecStartTime()) + indent
+ indent + dft.format(cloudlet.getFinishTime()));
}
}
}
/**
* Prints the metric history.
*
* @param hosts
* the hosts
* @param vmAllocationPolicy
* the vm allocation policy
*/
public static void printMetricHistory(List<? extends Host> hosts,
PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy) {
for (int i = 0; i < 10; i++) {
Host host = hosts.get(i);
Log.printLine("Host #" + host.getId());
Log.printLine("Time:");
if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) {
continue;
}
for (Double time : vmAllocationPolicy.getTimeHistory().get(
host.getId())) {
Log.format("%.2f, ", time);
}
Log.printLine();
for (Double utilization : vmAllocationPolicy
.getUtilizationHistory().get(host.getId())) {
Log.format("%.2f, ", utilization);
}
Log.printLine();
for (Double metric : vmAllocationPolicy.getMetricHistory().get(
host.getId())) {
Log.format("%.2f, ", metric);
}
Log.printLine();
}
}
public static void printResults(PowerDatacenter datacenter, List<Vm> vms,
double lastClock, boolean outputInCsv, String outputFolder) {
Log.enable();
List<Host> hosts = datacenter.getHostList();
String experimentName = "VM Placement by using CALA & FALA";
int numberOfHosts = hosts.size();
int numberOfVms = vms.size();
double totalSimulationTime = lastClock;
double energy = datacenter.getPower() / (3600 * 1000);
int numberOfMigrations = datacenter.getMigrationCount();
Map<String, Double> slaMetrics = getSlaMetrics(vms);
double slaOverall = slaMetrics.get("overall");
double slaAverage = slaMetrics.get("average");
double slaDegradationDueToMigration = slaMetrics
.get("underallocated_migration");
double slaTimePerActiveHost = getSlaTimePerActiveHost(hosts);
double sla = slaTimePerActiveHost * slaDegradationDueToMigration;
List<Double> timeBeforeHostShutdown = getTimesBeforeHostShutdown(hosts);
int numberOfHostShutdowns = timeBeforeHostShutdown.size();
int accIdleStateCount = REcount.numberofsetaction[0];
int rejIdleStateCount = REcount.numberofsetaction[1];
int accAvgStateCount = REcount.numberofsetaction[2];
int rejAvgStateCount = REcount.numberofsetaction[3];
int accActiveStateCount = REcount.numberofsetaction[4];
int rejActiveStateCount = REcount.numberofsetaction[5];
int accOverStateCount = REcount.numberofsetaction[6];
int rejOverStateCount = REcount.numberofsetaction[7];
double meanTimeBeforeHostShutdown = Double.NaN;
double stDevTimeBeforeHostShutdown = Double.NaN;
if (!timeBeforeHostShutdown.isEmpty()) {
meanTimeBeforeHostShutdown = MathUtil.mean(timeBeforeHostShutdown);
stDevTimeBeforeHostShutdown = MathUtil
.stDev(timeBeforeHostShutdown);
}
List<Double> timeBeforeVmMigration = getTimesBeforeVmMigration(vms);
double meanTimeBeforeVmMigration = Double.NaN;
double stDevTimeBeforeVmMigration = Double.NaN;
if (!timeBeforeVmMigration.isEmpty()) {
meanTimeBeforeVmMigration = MathUtil.mean(timeBeforeVmMigration);
stDevTimeBeforeVmMigration = MathUtil.stDev(timeBeforeVmMigration);
}
if (outputInCsv) {
File folder = new File(outputFolder);
if (!folder.exists()) {
folder.mkdir();
}
File folder1 = new File(outputFolder + "/stats");
if (!folder1.exists()) {
folder1.mkdir();
}
File folder2 = new File(outputFolder + "/time_before_host_shutdown");
if (!folder2.exists()) {
folder2.mkdir();
}
File folder3 = new File(outputFolder + "/time_before_vm_migration");
if (!folder3.exists()) {
folder3.mkdir();
}
File folder4 = new File(outputFolder + "/metrics");
if (!folder4.exists()) {
folder4.mkdir();
}
StringBuilder data = new StringBuilder();
String delimeter = ",";
data.append(String.format("%d", numberOfHosts) + delimeter);
data.append(String.format("%d", numberOfVms) + delimeter);
data.append(String.format("%.2f", totalSimulationTime) + delimeter);
data.append(String.format("%.5f", energy) + delimeter);
data.append(String.format("%d", numberOfMigrations) + delimeter);
data.append(String.format("%d", accIdleStateCount) + delimeter);
data.append(String.format("%d", rejIdleStateCount) + delimeter);
data.append(String.format("%d", accAvgStateCount) + delimeter);
data.append(String.format("%d", rejAvgStateCount) + delimeter);
data.append(String.format("%d", accActiveStateCount) + delimeter);
data.append(String.format("%d", rejActiveStateCount) + delimeter);
data.append(String.format("%d", accOverStateCount) + delimeter);
data.append(String.format("%d", rejOverStateCount) + delimeter);
data.append(String.format("%.10f", sla) + delimeter);
data.append(String.format("%.10f", slaTimePerActiveHost)
+ delimeter);
data.append(String.format("%.10f", slaDegradationDueToMigration)
+ delimeter);
data.append(String.format("%.10f", slaAverage) + delimeter);
data.append(String.format("%d", numberOfHostShutdowns) + delimeter);
data.append(String.format("%.2f", meanTimeBeforeHostShutdown)
+ delimeter);
data.append(String.format("%.2f", stDevTimeBeforeHostShutdown)
+ delimeter);
data.append(String.format("%.2f", meanTimeBeforeVmMigration)
+ delimeter);
data.append(String.format("%.2f", stDevTimeBeforeVmMigration)
+ delimeter);
if (datacenter.getVmAllocationPolicy() instanceof PowerVmAllocationPolicyMigrationAbstract) {
PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy = (PowerVmAllocationPolicyMigrationAbstract) datacenter
.getVmAllocationPolicy();
double executionTimeVmSelectionMean = MathUtil
.mean(vmAllocationPolicy
.getExecutionTimeHistoryVmSelection());
double executionTimeVmSelectionStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryVmSelection());
double executionTimeHostSelectionMean = MathUtil
.mean(vmAllocationPolicy
.getExecutionTimeHistoryHostSelection());
double executionTimeHostSelectionStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryHostSelection());
double executionTimeVmReallocationMean = MathUtil
.mean(vmAllocationPolicy
.getExecutionTimeHistoryVmReallocation());
double executionTimeVmReallocationStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryVmReallocation());
double executionTimeTotalMean = MathUtil
.mean(vmAllocationPolicy.getExecutionTimeHistoryTotal());
double executionTimeTotalStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryTotal());
data.append(String.format("%.5f", executionTimeVmSelectionMean)
+ delimeter);
data.append(String
.format("%.5f", executionTimeVmSelectionStDev)
+ delimeter);
data.append(String.format("%.5f",
executionTimeHostSelectionMean) + delimeter);
data.append(String.format("%.5f",
executionTimeHostSelectionStDev) + delimeter);
data.append(String.format("%.5f",
executionTimeVmReallocationMean) + delimeter);
data.append(String.format("%.5f",
executionTimeVmReallocationStDev) + delimeter);
data.append(String.format("%.5f", executionTimeTotalMean)
+ delimeter);
data.append(String.format("%.5f", executionTimeTotalStDev)
+ delimeter);
writeMetricHistory(hosts, vmAllocationPolicy, outputFolder
+ "/metrics/" + "" + "_metric");
}
data.append("\n");
writeDataRow(data.toString(), outputFolder + "/stats/"
+ experimentName + "_stats.csv");
writeDataColumn(timeBeforeHostShutdown, outputFolder
+ "/time_before_host_shutdown/" + experimentName
+ "_time_before_host_shutdown.csv");
writeDataColumn(timeBeforeVmMigration, outputFolder
+ "/time_before_vm_migration/" + experimentName
+ "_time_before_vm_migration.csv");
} else {
Log.setDisabled(false);
Log.printLine();
Log.printLine(String.format("Experiment name: " + experimentName));
Log.printLine(String.format("Number of hosts: " + numberOfHosts));
Log.printLine(String.format("Number of VMs: " + numberOfVms));
Log.printLine(String.format("Total simulation time: %.2f sec",
totalSimulationTime));
Log.printLine(String.format("Energy consumption: %.2f kWh", energy));
Log.printLine(String.format("Number of VM migrations: %d",
numberOfMigrations));
Log.printLine(String.format("SLA: %.5f%%", sla * 100));
Log.printLine(String.format(
"SLA perf degradation due to migration: %.2f%%",
slaDegradationDueToMigration * 100));
Log.printLine(String.format("SLA time per active host: %.2f%%",
slaTimePerActiveHost * 100));
Log.printLine(String.format("Average SLA violation: %.2f%%",
slaAverage * 100));
Log.printLine(String.format("Number of host shutdowns: %d",
numberOfHostShutdowns));
Log.printLine(String.format("Number of Acc action choose in IdleSt"
+ accIdleStateCount));
Log.printLine(String.format("Number of Rej action choose in IdleSt"
+ rejIdleStateCount)
);
Log.printLine(String.format("Number of Acc action choose in AvgeSt"
+ accAvgStateCount)
);
Log.printLine(String.format("Number of Rej action choose in AvgSt"
+ rejAvgStateCount)
);
Log.printLine(String.format("Number of Acc action choose in ActiveSt"
+ accActiveStateCount)
);
Log.printLine(String.format("Number of Rej action choose in ActiveSt"
+ rejActiveStateCount)
);
Log.printLine(String.format("Number of Acc action choose in OverSt"
+ accOverStateCount)
);
Log.printLine(String.format("Number of Rej action choose in OverSt"
+ rejOverStateCount)
);
Log.printLine(String.format(
"Mean time before a host shutdown: %.2f sec",
meanTimeBeforeHostShutdown));
Log.printLine(String.format(
"StDev time before a host shutdown: %.2f sec",
stDevTimeBeforeHostShutdown));
Log.printLine(String.format(
"Mean time before a VM migration: %.2f sec",
meanTimeBeforeVmMigration));
Log.printLine(String.format(
"StDev time before a VM migration: %.2f sec",
stDevTimeBeforeVmMigration));
if (datacenter.getVmAllocationPolicy() instanceof PowerVmAllocationPolicyMigrationAbstract) {
PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy = (PowerVmAllocationPolicyMigrationAbstract) datacenter
.getVmAllocationPolicy();
double executionTimeVmSelectionMean = MathUtil
.mean(vmAllocationPolicy
.getExecutionTimeHistoryVmSelection());
double executionTimeVmSelectionStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryVmSelection());
double executionTimeHostSelectionMean = MathUtil
.mean(vmAllocationPolicy
.getExecutionTimeHistoryHostSelection());
double executionTimeHostSelectionStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryHostSelection());
double executionTimeVmReallocationMean = MathUtil
.mean(vmAllocationPolicy
.getExecutionTimeHistoryVmReallocation());
double executionTimeVmReallocationStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryVmReallocation());
double executionTimeTotalMean = MathUtil
.mean(vmAllocationPolicy.getExecutionTimeHistoryTotal());
double executionTimeTotalStDev = MathUtil
.stDev(vmAllocationPolicy
.getExecutionTimeHistoryTotal());
Log.printLine(String.format(
"Execution time - VM selection mean: %.5f sec",
executionTimeVmSelectionMean));
Log.printLine(String.format(
"Execution time - VM selection stDev: %.5f sec",
executionTimeVmSelectionStDev));
Log.printLine(String.format(
"Execution time - host selection mean: %.5f sec",
executionTimeHostSelectionMean));
Log.printLine(String.format(
"Execution time - host selection stDev: %.5f sec",
executionTimeHostSelectionStDev));
Log.printLine(String.format(
"Execution time - VM reallocation mean: %.5f sec",
executionTimeVmReallocationMean));
Log.printLine(String.format(
"Execution time - VM reallocation stDev: %.5f sec",
executionTimeVmReallocationStDev));
Log.printLine(String.format(
"Execution time - total mean: %.5f sec",
executionTimeTotalMean));
Log.printLine(String.format(
"Execution time - total stDev: %.5f sec",
executionTimeTotalStDev));
}
Log.printLine();
}
Log.setDisabled(true);
}
}