Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more consistant identifier names around Java objects' finalization
[simgrid.git] / examples / java / cloud / migration / Test.java
1 /* Copyright (c) 2014. 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
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11 import java.util.ArrayList;
12 import java.util.List;
13
14 public class Test extends Process{
15
16     Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException  {
17         super(host, name, args);
18     }
19
20     public void main(String[] strings) throws MsgException {
21
22        double startTime = 0;
23        double endTime = 0;
24
25        /* get hosts 1 and 2*/
26         Host host0 = null;
27         Host host1 = null;
28
29         try {
30             host0 = Host.getByName("host0");
31             host1 = Host.getByName("host1");
32         }catch (HostNotFoundException e) {
33             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
34         }
35
36         List<VM> vms = new ArrayList<VM>();
37
38       /* Create VM1 */
39         int dpRate = 70;
40         int load1 = 90;
41         int load2 = 80;
42
43
44                   Msg.info("This example evaluates the migration time of a VM in presence of collocated VMs on the source and the dest nodes");
45                   Msg.info("The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% \"(see cloudcom 2013 paper \"Adding a Live Migration Model Into SimGrid\" for further information) ");
46
47                   Msg.info("Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see whether it impacts or not the migration time");
48         XVM vm1 = null;
49         vm1 = new XVM(
50                 host0,
51                 "vm0",
52                 1, // Nb of vcpu
53                 2048, // Ramsize,
54                 125, // Net Bandwidth
55                 null, //VM disk image
56                 -1,   //size of disk image,
57                 125, // Net bandwidth,
58                 dpRate // Memory intensity
59         );
60         vms.add(vm1);
61         vm1.start();
62
63         /* Collocated VMs */
64         int collocatedSrc = 6;
65         int vmSrcLoad[] = {
66                 80,
67                 0,
68                 90,
69                 40,
70                 30,
71                 90,
72         };
73
74         XVM tmp = null;
75         for (int i=1 ; i<= collocatedSrc ; i++){
76             tmp = new XVM(
77                     host0,
78                     "vm"+i,
79                     1, // Nb of vcpu
80                     2048, // Ramsize,
81                     125, // Net Bandwidth
82                     null, //VM disk image
83                     -1,   //size of disk image,
84                     125, // Net bandwidth,
85                     dpRate // Memory intensity
86             );
87             vms.add(tmp);
88             tmp.start();
89             tmp.setLoad(vmSrcLoad[i-1]);
90         }
91
92         int collocatedDst = 6;
93         int vmDstLoad[] = {
94                 0,
95                 40,
96                 90,
97                 100,
98                 0,
99                 80,
100         };
101
102         for (int i=1 ; i <= collocatedDst ; i++){
103             tmp = new XVM(
104                     host1,
105                     "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         Msg.info("     - Launch migration from host 0 to host 1");
122         startTime = Msg.getClock();
123         vm1.migrate(host1);
124         endTime = Msg.getClock();
125         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
126         Msg.info("     - Launch migration from host 1 to host 0");
127         startTime = Msg.getClock();
128         vm1.migrate(host0);
129         endTime = Msg.getClock();
130         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
131
132
133         Msg.info("\n \n \nRound trip of VM1 (load "+load2+"%)");
134         vm1.setLoad(load2);
135         Msg.info("     - Launch migration from host 0 to host 1");
136         startTime = Msg.getClock();
137         vm1.migrate(host1);
138         endTime = Msg.getClock();
139         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
140         Msg.info("     - Launch migration from host 1 to host 0");
141         startTime = Msg.getClock();
142         vm1.migrate(host0);
143         endTime = Msg.getClock();
144         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
145
146         Main.setEndOfTest();
147         // no need to destroy the VMs: the garbage collector will get them all
148     }
149 }