Logo AND Algorithmique Numérique Distribuée

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