Logo AND Algorithmique Numérique Distribuée

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