Logo AND Algorithmique Numérique Distribuée

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