Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move MSG and SimDag examples out of the sight of users
[simgrid.git] / examples / deprecated / java / cloud / migration / Test.java
1 /* Copyright (c) 2014-2019. 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[] vmDstLoad = {
82         0,
83         40,
84         90,
85         100,
86         0,
87         80,
88     };
89
90     for (int i=1 ; i <= vmDstLoad.length ; i++){
91       tmp = new XVM(host1, "vm"+(i+vmSrcLoad.length),
92           2048, // Ramsize,
93           125, // Net bandwidth,
94           dpRate // Memory intensity
95           );
96       vms.add(tmp);
97       tmp.start();
98       tmp.setLoad(vmDstLoad[i-1]);
99     }
100
101     Msg.info("Round trip of VM1 (load "+load1+"%)");
102     vm1.setLoad(load1);
103     doMigration(vm1, host0, host1);
104     doMigration(vm1, host1, host0);
105     Msg.info("");
106     Msg.info("");
107     Msg.info("Round trip of VM1 (load "+load2+"%)");
108     vm1.setLoad(load2);
109     doMigration(vm1, host0, host1);
110     doMigration(vm1, host1, host0);
111
112     Main.setEndOfTest();
113     Msg.info("Forcefully destroy VMs");
114     for (VM vm: vms)
115       vm.destroy();
116   }
117 }