Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Cavalcante
cloudsimplus
Commits
212db8ca
Commit
212db8ca
authored
Jul 19, 2018
by
Lucas Cavalcante
Browse files
merge with origin
parents
0a361921
e0401313
Changes
4
Hide whitespace changes
Inline
Side-by-side
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/allocationpolicies/migration/VmAllocationPolicyMigrationSlaFixedTightHost.java
View file @
212db8ca
...
...
@@ -19,7 +19,8 @@ import org.cloudbus.cloudsim.vms.Vm;
* versa.
*
* The creation of the 'Tight' hosts is dynamic. Although,
* the maximum number of 'Tight' hosts is static
* the maximum number of 'Tight' hosts is static and depends of
* the variable 'vmsThreshold'.
*
* For more information, please refer to this paper:
*
...
...
@@ -29,10 +30,13 @@ import org.cloudbus.cloudsim.vms.Vm;
public
class
VmAllocationPolicyMigrationSlaFixedTightHost
extends
VmAllocationPolicyMigrationSla
{
private
int
vmsThreshold
=
0
;
private
int
limitTightHosts
=
0
;
private
int
actualTightHosts
=
0
;
public
VmAllocationPolicyMigrationSlaFixedTightHost
(
VmAllocationPolicy
allocationPolicy
,
int
migrationTime
,
int
vmTresshold
)
{
public
VmAllocationPolicyMigrationSlaFixedTightHost
(
VmAllocationPolicy
allocationPolicy
,
int
migrationTime
,
int
vmTresshold
,
int
limitTightHosts
)
{
super
(
allocationPolicy
,
migrationTime
);
setVmsThreshold
(
vmTresshold
);
setLimitTightHosts
(
limitTightHosts
);
}
@Override
...
...
@@ -41,16 +45,24 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
int
numberCreditVms
=
getVmsWithEnoughCredit
(
getHostsWithLooseSla
()).
size
();
if
(
numberCreditVms
>=
getVmsThreshold
())
{
// Check if the number of vms with credit also consider the vms with credit that are
// in the Tight hosts (Check vms that are current migrating)
if
(
numberCreditVms
>=
getVmsThreshold
()
&&
actualTightHosts
<
getLimitTightHosts
())
{
// The Tight host can be created
// Select the Loose host with more credit Vms
Host
bestCandidateHost
=
getHostCandidate
();
// Make it a Tight host
bestCandidateHost
.
setIopsProvisioner
(
new
ResourceProvisionerShared
());
// Increse the number of Tight hosts
actualTightHosts
++;
}
// Run Migration Sla Algorithm
return
super
.
getOptimizedAllocationMap
(
vmList
);
Map
<
Vm
,
Host
>
migrationMap
=
super
.
getOptimizedAllocationMap
(
vmList
);
// Consolidate Loose hosts
return
migrationMap
;
}
/*
...
...
@@ -64,18 +76,19 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
final
double
clock
=
getDatacenter
().
getSimulation
().
clock
();
int
actual
HighestCreditVms
=
0
;
int
current
HighestCreditVms
=
0
;
Host
bestCandidateHost
=
null
;
for
(
Host
host
:
looseHosts
)
{
for
(
Host
host
:
looseHosts
)
{
// Check how good candidate this host is
int
creditVms
=
0
;
for
(
Vm
vm
:
host
.
getVmList
())
{
if
(
vm
.
getMonitor
().
get
Vm
Credit
(
clock
)
-
getMIGRATION_TIME
()
>
0
)
{
if
(
vm
.
getMonitor
().
get
Cumulative
Credit
(
clock
)
-
getMIGRATION_TIME
()
>
0
)
{
creditVms
++;
}
}
if
(
creditVms
>
actual
HighestCreditVms
)
{
actual
HighestCreditVms
=
creditVms
;
if
(
creditVms
>
current
HighestCreditVms
)
{
current
HighestCreditVms
=
creditVms
;
bestCandidateHost
=
host
;
}
}
...
...
@@ -83,6 +96,10 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
return
bestCandidateHost
;
}
private
boolean
isTightHost
(
Host
host
)
{
return
host
.
getIopsProvisioner
()
instanceof
ResourceProvisionerShared
;
}
private
int
getVmsThreshold
()
{
return
vmsThreshold
;
}
...
...
@@ -91,4 +108,11 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
this
.
vmsThreshold
=
newThreshold
;
}
private
int
getLimitTightHosts
()
{
return
limitTightHosts
;
}
private
void
setLimitTightHosts
(
int
newLimit
)
{
this
.
limitTightHosts
=
newLimit
;
}
}
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/util/CsvGenerator.java
View file @
212db8ca
...
...
@@ -163,7 +163,7 @@ public class CsvGenerator {
writer
.
append
(
','
);
writer
.
append
(
String
.
valueOf
(
cl
.
getVm
().
getMonitor
().
getCumulativeVmViolationTime
(
i
)));
writer
.
append
(
','
);
writer
.
append
(
String
.
valueOf
(
cl
.
getVm
().
getMonitor
().
get
Vm
Credit
(
i
)));
writer
.
append
(
String
.
valueOf
(
cl
.
getVm
().
getMonitor
().
get
Cumulative
Credit
(
i
)));
writer
.
append
(
'\n'
);
}
}
...
...
cloudsim-plus/src/main/java/org/cloudsimplus/slametrics/SlaMonitor.java
View file @
212db8ca
...
...
@@ -29,6 +29,7 @@ public class SlaMonitor {
public
SlaMonitor
(
Vm
vm
)
{
this
.
vm
=
vm
;
this
.
credits
=
new
HashMap
<
Integer
,
Double
>();
this
.
violations
=
new
HashMap
<
Integer
,
Boolean
>();
this
.
lastElement
=
0
;
this
.
lastUtilization
=
0
;
}
...
...
@@ -75,11 +76,10 @@ public double getCumulativeCredit(double time) {
}
if
(
stateList
.
get
(
lastElement
-
1
).
getTime
()
<
time
)
{
VmStateHistoryEntry
last
=
stateList
.
get
(
lastElement
-
1
);
Double
previous
=
credits
.
get
((
int
)
last
.
getTime
());
Double
previous
=
credits
.
get
((
int
)
stateList
.
get
(
lastElement
-
1
).
getTime
());
Double
preprevious
=
credits
.
get
((
int
)
stateList
.
get
(
lastElement
-
2
).
getTime
());;
if
(
previous
>
preprevious
)
{
if
(
last
.
getAllocatedIops
()
<
provisioned
)
{
cumulativeCredit
=
previous
-
(((
int
)
time
-
stateList
.
get
(
lastElement
-
1
).
getTime
()))
*
(
1
/
availability
);
}
else
{
cumulativeCredit
=
previous
+
(((
int
)
time
-
stateList
.
get
(
lastElement
-
1
).
getTime
()))
*
(
1
/
availability
);
...
...
@@ -166,10 +166,6 @@ public double getCumulativeCredit(double time) {
return
false
;
}
public
double
getVmCredit
(
double
time
){
return
Math
.
max
(
0
,
getMaximumAllowedSlaViolationTime
()
-
getCumulativeVmViolationTime
(
time
));
}
public
long
getInstantaneousVmViolationTime
(
int
time
){
if
(
violations
.
containsKey
(
time
)){
return
violations
.
get
(
time
)?
1
:
0
;
...
...
cloudsim-plus/src/test/java/org/cloudsimplus/slametrics/SlaMonitorTest.java
View file @
212db8ca
...
...
@@ -19,7 +19,7 @@ public class SlaMonitorTest {
private
static
final
long
MINIMUM_IOPS
=
500
;
private
static
final
double
MINIMUM_AVAILABILITY
=
99.9
;
private
static
final
double
STEP_CREDIT
=
1
/
MINIMUM_AVAILABILITY
;
private
static
final
long
INITIAL_CREDIT
=
(
long
)
((
100
-
MINIMUM_AVAILABILITY
)*
SlaMonitor
.
SECONDS_OF_A_MONTH
);
private
static
SlaContract
contract
;
private
static
double
imprecision
=
0.0001
;
...
...
@@ -76,7 +76,7 @@ public class SlaMonitorTest {
}
@Test
public
void
getVmCredit_test
1
()
{
public
void
getVmCredit_test
()
{
Vm
vm
=
new
VmSimple
(
0
,
0
);
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
1
,
0
,
0
,
400
,
0
,
false
));
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
2
,
0
,
0
,
500
,
0
,
false
));
...
...
@@ -99,28 +99,7 @@ public class SlaMonitorTest {
assertEquals
(
1184
*
STEP_CREDIT
,
vm
.
getMonitor
().
getCumulativeCredit
(
1196
),
imprecision
);
}
@Test
public
void
getVmCredit_test
()
{
Vm
vm
=
new
VmSimple
(
0
,
0
);
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
1
,
0
,
0
,
400
,
0
,
false
));
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
2
,
0
,
0
,
500
,
0
,
false
));
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
3
,
0
,
0
,
500
,
0
,
false
));
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
4
,
0
,
0
,
600
,
0
,
false
));
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
5
,
0
,
0
,
600
,
0
,
false
));
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
11
,
0
,
0
,
400
,
0
,
false
));
vm
.
setContract
(
contract
);
assertEquals
(
INITIAL_CREDIT
,
vm
.
getMonitor
().
getVmCredit
(
0
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
1
,
vm
.
getMonitor
().
getVmCredit
(
1
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
1
,
vm
.
getMonitor
().
getVmCredit
(
2
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
1
,
vm
.
getMonitor
().
getVmCredit
(
3
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
1
,
vm
.
getMonitor
().
getVmCredit
(
4
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
1
,
vm
.
getMonitor
().
getVmCredit
(
5
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
2
,
vm
.
getMonitor
().
getVmCredit
(
11
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
6
,
vm
.
getMonitor
().
getVmCredit
(
15
),
imprecision
);
assertEquals
(
0
,
vm
.
getMonitor
().
getVmCredit
(
INITIAL_CREDIT
+
10000
),
imprecision
);
}
@Test
public
void
getVmCreditAfterOneMonth_test
()
{
Vm
vm
=
new
VmSimple
(
0
,
0
);
...
...
@@ -129,11 +108,15 @@ public class SlaMonitorTest {
vm
.
addStateHistoryEntry
(
new
VmStateHistoryEntry
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
5
,
0
,
0
,
400
,
0
,
false
));
vm
.
setContract
(
contract
);
assertEquals
(
INITIAL_CREDIT
,
vm
.
getMonitor
().
getVmCredit
(
0
),
imprecision
);
assertEquals
(
0
,
vm
.
getMonitor
().
getVmCredit
(
INITIAL_CREDIT
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
,
vm
.
getMonitor
().
getVmCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
1
,
vm
.
getMonitor
().
getVmCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
5
),
imprecision
);
assertEquals
(
INITIAL_CREDIT
-
101
,
vm
.
getMonitor
().
getVmCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
105
),
imprecision
);
assertEquals
(
0
,
vm
.
getMonitor
().
getCumulativeCredit
(
0
),
imprecision
);
assertEquals
(-
1
*
STEP_CREDIT
,
vm
.
getMonitor
().
getCumulativeCredit
(
1
),
0
);
// starts indebted
assertEquals
((-
1
*
STEP_CREDIT
)
*
(
SlaMonitor
.
SECONDS_OF_A_MONTH
-
1
),
vm
.
getMonitor
().
getCumulativeCredit
((
SlaMonitor
.
SECONDS_OF_A_MONTH
-
1
)),
imprecision
);
assertEquals
((-
1
*
STEP_CREDIT
)
*
(
SlaMonitor
.
SECONDS_OF_A_MONTH
-
2
),
vm
.
getMonitor
().
getCumulativeCredit
((
SlaMonitor
.
SECONDS_OF_A_MONTH
)),
imprecision
);
assertEquals
((-
1
*
STEP_CREDIT
)
*
(
SlaMonitor
.
SECONDS_OF_A_MONTH
-
6
),
vm
.
getMonitor
().
getCumulativeCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
4
),
imprecision
);
assertEquals
((
STEP_CREDIT
)
*
(-
1
*
SlaMonitor
.
SECONDS_OF_A_MONTH
-
5
),
vm
.
getMonitor
().
getCumulativeCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
5
),
0.2
);
assertEquals
((
STEP_CREDIT
)
*
(-
1
*
SlaMonitor
.
SECONDS_OF_A_MONTH
-
15
),
vm
.
getMonitor
().
getCumulativeCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
15
),
0.2
);
assertEquals
((
STEP_CREDIT
)
*
(-
1
*
SlaMonitor
.
SECONDS_OF_A_MONTH
-
55
),
vm
.
getMonitor
().
getCumulativeCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
55
),
0.2
);
assertEquals
((
STEP_CREDIT
)
*
(-
1
*
SlaMonitor
.
SECONDS_OF_A_MONTH
-
101
),
vm
.
getMonitor
().
getCumulativeCredit
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
101
),
0.2
);
}
@Test
...
...
@@ -164,7 +147,7 @@ public class SlaMonitorTest {
vm
.
setContract
(
contract
);
assertEquals
(
0
,
vm
.
getMonitor
().
getCumulativeVmViolationTime
(
0
));
assertEquals
(
1
,
vm
.
getMonitor
().
getCumulativeVmViolationTime
(
1
));
assertEquals
(
1
,
vm
.
getMonitor
().
getCumulativeVmViolationTime
(
1
));
assertEquals
(
100
,
vm
.
getMonitor
().
getCumulativeVmViolationTime
(
100
));
assertEquals
(
0
,
vm
.
getMonitor
().
getCumulativeVmViolationTime
(
SlaMonitor
.
SECONDS_OF_A_MONTH
));
assertEquals
(
1
,
vm
.
getMonitor
().
getCumulativeVmViolationTime
(
SlaMonitor
.
SECONDS_OF_A_MONTH
+
5
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment