Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d3d6a09aa16d23e96483b3ece82bcab81ad84b48
[simgrid.git] / examples / java / cloud / migration / Test.java
1 /* Copyright (c) 2014, 2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package cloud.migration;
8 import java.util.ArrayList;
9 import java.util.List;
10
11 import org.simgrid.msg.*;
12 import org.simgrid.msg.Process;
13
14 public class Test extends Process{
15
16   Test(String hostname, String name) throws HostNotFoundException, NativeException  {
17     super(hostname, name);
18   }
19
20   public void doMigration(VM vm, Host src, Host dst) throws HostFailureException{
21     Msg.info("     - Launch migration from "+ src.getName() +" to " + dst.getName());
22     double startTime = Msg.getClock();
23     vm.migrate(dst);
24     double endTime = Msg.getClock();
25     Msg.info("     - End of Migration from "+ src.getName() +" to " + dst.getName()+ " (duration:" +
26              (endTime-startTime)+")");
27   }
28
29   public void main(String[] strings) throws MsgException {
30     Host host0 = null;
31     Host host1 = null;
32     try {
33     /* get hosts 1 and 2*/
34       host0 = Host.getByName("PM0");
35       host1 = Host.getByName("PM1");
36     }catch (HostNotFoundException e) {
37       e.printStackTrace();
38     }
39
40     List<VM> vms = new ArrayList<>();
41
42     /* Create VM1 */
43     int dpRate = 70;
44     int load1 = 90;
45     int load2 = 80;
46
47     Msg.info("This example evaluates the migration time of a VM in presence of collocated VMs on the source and "
48              + "the dest nodes");
49     Msg.info("The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% \" "
50              +"(see cloudcom 2013 paper \"Adding a Live Migration Model Into SimGrid\" for further information) ");
51
52     Msg.info("Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see "
53              + "whether it impacts or not the migration time");
54     XVM vm1 = new XVM(host0, "vm0",
55         1, // Nb of vcpu
56         2048, // Ramsize,
57         125, // Net Bandwidth
58         null, //VM disk image
59         -1,   //size of disk image,
60         125, // Net bandwidth,
61         dpRate // Memory intensity
62         );
63     vms.add(vm1);
64     vm1.start();
65
66     /* Collocated VMs */
67     int collocatedSrc = 6;
68     int[] vmSrcLoad = {
69         80,
70         0,
71         90,
72         40,
73         30,
74         90,
75     };
76
77     XVM tmp;
78     for (int i=1 ; i<= collocatedSrc ; i++){
79       tmp = new XVM(host0, "vm"+i,
80           1, // Nb of vcpu
81           2048, // Ramsize,
82           125, // Net Bandwidth
83           null, //VM disk image
84           -1,   //size of disk image,
85           125, // Net bandwidth,
86           dpRate // Memory intensity
87           );
88       vms.add(tmp);
89       tmp.start();
90       tmp.setLoad(vmSrcLoad[i-1]);
91     }
92
93     int collocatedDst = 6;
94     int[] vmDstLoad = {
95         0,
96         40,
97         90,
98         100,
99         0,
100         80,
101     };
102
103     for (int i=1 ; i <= collocatedDst ; i++){
104       tmp = new XVM(host1, "vm"+(i+collocatedSrc),
105           1, // Nb of vcpu
106           2048, // Ramsize,
107           125, // Net Bandwidth
108           null, //VM disk image
109           -1,   //size of disk image,
110           125, // Net bandwidth,
111           dpRate // Memory intensity
112           );
113       vms.add(tmp);
114       tmp.start();
115       tmp.setLoad(vmDstLoad[i-1]);
116     }
117
118     Msg.info("Round trip of VM1 (load "+load1+"%)");
119     vm1.setLoad(load1);
120     doMigration(vm1, host0, host1);
121     doMigration(vm1, host1, host0);
122     Msg.info("");
123     Msg.info("");
124     Msg.info("Round trip of VM1 (load "+load2+"%)");
125     vm1.setLoad(load2);
126     doMigration(vm1, host0, host1);
127     doMigration(vm1, host1, host0);
128
129     Main.setEndOfTest();
130     Msg.info("Forcefully destroy VMs");
131     for (VM vm: vms)
132       vm.destroy();
133   }
134 }