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
f86e954b
Commit
f86e954b
authored
Jun 28, 2018
by
Eduardo Falcão
Browse files
fixed bug in iops provisioning
parent
7b304c2e
Changes
10
Hide whitespace changes
Inline
Side-by-side
cloudsim-plus-examples/src/main/java/org/cloudbus/cloudsim/examples/autonomic/simulations/InfoAwareSimulation.java
View file @
f86e954b
...
...
@@ -249,8 +249,8 @@ public class InfoAwareSimulation {
/* Checks if the time specified in the scheduling interval has passed. */
if
(
time
==
SCHEDULING_INTERVAL
)
{
//
Log.printLine("\n" + info.getTime() + ": # Changing Vm Allocation Policy to: Info-Aware");
//
datacenter = ((DatacenterSimple) datacenter).setVmAllocationPolicy(new VmAllocationPolicyInfoAware());
Log
.
printLine
(
"\n"
+
info
.
getTime
()
+
": # Changing Vm Allocation Policy to: Info-Aware"
);
datacenter
=
((
DatacenterSimple
)
datacenter
).
setVmAllocationPolicy
(
new
VmAllocationPolicyInfoAware
());
List
<
Vm
>
listVmsLaunched
=
new
ArrayList
<>(
NUMBER_VMS_LAUNCHED
);
...
...
cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/resourceusage/UtilizationModelDynamicExample.java
View file @
f86e954b
...
...
@@ -132,6 +132,7 @@ public class UtilizationModelDynamicExample {
long
ram
=
2048
;
// host memory (MEGABYTE)
long
storage
=
1000000
;
// host storage (MEGABYTE)
long
bw
=
10000
;
//in Megabits/s
long
iops
=
1000
;
List
<
Pe
>
peList
=
new
ArrayList
<>();
//List of CPU cores
...
...
@@ -141,9 +142,10 @@ public class UtilizationModelDynamicExample {
peList
.
add
(
new
PeSimple
(
mips
,
new
PeProvisionerSimple
()));
}
return
new
HostSimple
(
ram
,
bw
,
storage
,
peList
)
return
new
HostSimple
(
ram
,
iops
,
bw
,
storage
,
peList
)
.
setRamProvisioner
(
new
ResourceProvisionerSimple
())
.
setBwProvisioner
(
new
ResourceProvisionerSimple
())
.
setIopsProvisioner
(
new
ResourceProvisionerSimple
())
.
setVmScheduler
(
new
VmSchedulerTimeShared
());
}
...
...
@@ -152,11 +154,13 @@ public class UtilizationModelDynamicExample {
long
storage
=
10000
;
// vm image size (MEGABYTE)
int
ram
=
512
;
// vm memory (MEGABYTE)
long
bw
=
1000
;
// vm bandwidth (Megabits/s)
long
iops
=
500
;
int
pesNumber
=
2
;
// number of CPU cores
return
new
VmSimple
(
vmList
.
size
(),
mips
,
pesNumber
)
.
setRam
(
ram
)
.
setBw
(
bw
)
.
setIops
(
iops
)
.
setSize
(
storage
)
.
setCloudletScheduler
(
new
CloudletSchedulerTimeShared
());
}
...
...
@@ -173,12 +177,13 @@ public class UtilizationModelDynamicExample {
UtilizationModel
utilizationHalfCapacity
=
new
UtilizationModelDynamic
(
0.5
);
Cloudlet
cloudlet
=
new
CloudletSimple
(
cloudletList
.
size
(),
length
,
numberOfCpuCores
)
cloudletList
.
size
(),
length
,
500
*
100
,
numberOfCpuCores
)
.
setFileSize
(
fileSize
)
.
setOutputSize
(
outputSize
)
.
setUtilizationModelBw
(
utilizationFull
)
.
setUtilizationModelRam
(
utilizationFull
)
.
setUtilizationModelCpu
(
utilizationHalfCapacity
)
.
setUtilizationModelIops
(
utilizationFull
)
.
setVm
(
vm
);
return
cloudlet
;
...
...
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/datacenters/DatacenterSimple.java
View file @
f86e954b
...
...
@@ -409,8 +409,10 @@ public class DatacenterSimple extends CloudSimEntity implements Datacenter {
vm
.
setCreated
(
true
);
}
final
List
<
Double
>
mipsList
=
vm
.
getHost
().
getVmScheduler
().
getAllocatedMips
(
vm
);
final
double
iops
=
vm
.
getHost
().
getVmScheduler
().
getAllocatedIops
(
vm
);
final
List
<
Double
>
mipsList
=
vm
.
getHost
().
getVmScheduler
().
getAllocatedMips
(
vm
);
//final double iops = vm.getHost().getVmScheduler().getAllocatedIops(vm);
final
double
iops
=
vm
.
getIops
().
getAllocatedResource
();
System
.
out
.
println
(
"Teste1! Vm id="
+
vm
.
getId
()+
", iops="
+
iops
);
vm
.
updateProcessing
(
getSimulation
().
clock
(),
mipsList
,
iops
);
}
...
...
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/hosts/HostSimple.java
View file @
f86e954b
...
...
@@ -242,6 +242,7 @@ public class HostSimple implements Host {
* e.g., in cases when Vm is destroyed during simulation execution.*/
for
(
int
i
=
0
;
i
<
vmList
.
size
();
i
++)
{
final
Vm
vm
=
vmList
.
get
(
i
);
//System.out.println("Teste1.2! Host id="+id+", vmId="+vm.getId()+", iops="+iops);
final
double
nextTime
=
vm
.
updateProcessing
(
currentTime
,
vmScheduler
.
getAllocatedMips
(
vm
),
vmScheduler
.
getAllocatedIops
(
vm
));
nextSimulationTime
=
Math
.
min
(
nextTime
,
nextSimulationTime
);
}
...
...
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/provisioners/ResourceProvisionerShared.java
View file @
f86e954b
...
...
@@ -8,23 +8,17 @@
package
org.cloudbus.cloudsim.provisioners
;
import
org.apache.commons.lang3.tuple.Triple
;
import
org.cloudbus.cloudsim.resources.Pe
;
import
org.cloudbus.cloudsim.vms.Vm
;
import
org.cloudbus.cloudsim.resources.ResourceManageable
;
import
org.cloudbus.cloudsim.util.Log
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.Map.Entry
;
import
java.util.Objects
;
import
org.cloudbus.cloudsim.resources.Pe
;
import
org.cloudbus.cloudsim.resources.ResourceManageable
;
import
org.cloudbus.cloudsim.vms.Vm
;
/**
* ResourceProvisionerShared is a {@link ResourceProvisioner} implementation
* that splits the available resources between the Vms constrained by the
...
...
@@ -59,6 +53,8 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
@Override
public
boolean
allocateResourceForVm
(
final
Vm
vm
,
final
long
newTotalVmResourceCapacity
)
{
System
.
out
.
println
(
"vm id = "
+
vm
.
getId
()+
"; resource: "
+
getResourceClass
().
getCanonicalName
());
Objects
.
requireNonNull
(
vm
);
if
(!
isSuitableForVm
(
vm
,
newTotalVmResourceCapacity
))
{
return
false
;
...
...
@@ -124,13 +120,13 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
class
VmRequestedAllocated
implements
Comparable
<
VmRequestedAllocated
>{
private
Vm
vm
;
private
Long
requested
,
allocated
;
private
Long
requested
,
newCapacity
;
public
VmRequestedAllocated
(
Vm
vm
,
Long
requested
,
Long
allocated
)
{
public
VmRequestedAllocated
(
Vm
vm
,
Long
requested
,
Long
newCapacity
)
{
super
();
this
.
vm
=
vm
;
this
.
requested
=
requested
;
this
.
allocated
=
allocated
;
this
.
newCapacity
=
newCapacity
;
}
@Override
...
...
@@ -168,16 +164,16 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
this
.
requested
-=
requested
;
}
public
Long
get
Allocated
()
{
return
allocated
;
public
Long
get
NewCapacity
()
{
return
newCapacity
;
}
public
void
set
Allocated
(
Long
allocated
)
{
this
.
allocated
=
allocated
;
public
void
set
NewCapacity
(
Long
newCapacity
)
{
this
.
newCapacity
=
newCapacity
;
}
public
void
add
Allocated
(
Long
extra
Allocation
)
{
this
.
allocated
+=
extraAllocation
;
public
void
add
NewCapacity
(
Long
extra
Capacity
)
{
this
.
newCapacity
+=
extraCapacity
;
}
}
...
...
@@ -199,11 +195,9 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
long
capacity
=
getResource
().
getCapacity
();
long
a
llocated
=
0L
;
long
capacityA
llocated
=
0L
;
long
available
=
capacity
;
int
numVms
=
vmRequestedAndAllocatedList
.
size
();
Collections
.
sort
(
vmRequestedAndAllocatedList
);
/**
...
...
@@ -217,13 +211,13 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
Iterator
<
VmRequestedAllocated
>
it2
=
vmRequestedAndAllocatedList
.
listIterator
();
while
(
it2
.
hasNext
())
{
VmRequestedAllocated
vra2
=
it2
.
next
();
vra2
.
add
Allocated
(
toBeAllocated
);
//increase the current
allocation
by the requested value
vra2
.
add
NewCapacity
(
toBeAllocated
);
//increase the current
capacity
by the requested value
vra2
.
subtractRequested
(
toBeAllocated
);
//and subtract the current requested by the recently allocated value
if
(
vra2
.
getRequested
()
==
0
){
//if this vm is satisfied
finalList
.
add
(
vra2
);
//add it on final list
it2
.
remove
();
//and remove from the main list
}
a
llocated
+=
toBeAllocated
;
//updates allocated and available
capacityA
llocated
+=
toBeAllocated
;
//updates allocated and available
available
-=
toBeAllocated
;
}
}
else
{
...
...
@@ -231,11 +225,11 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
Iterator
<
VmRequestedAllocated
>
it2
=
vmRequestedAndAllocatedList
.
listIterator
();
while
(
it2
.
hasNext
())
{
VmRequestedAllocated
vra2
=
it2
.
next
();
vra2
.
add
Allocated
(
toBeAllocated
);
//increase the current allocation by the requested value
vra2
.
add
NewCapacity
(
toBeAllocated
);
//increase the current allocation by the requested value
vra2
.
subtractRequested
(
toBeAllocated
);
//and subtract the current requested by the recently allocated value
finalList
.
add
(
vra2
);
//add it on final list because its the final allocation
it2
.
remove
();
//and remove from the main list
a
llocated
+=
toBeAllocated
;
//updates allocated and available
capacityA
llocated
+=
toBeAllocated
;
//updates allocated and available
available
-=
toBeAllocated
;
}
}
...
...
@@ -243,13 +237,32 @@ public class ResourceProvisionerShared extends ResourceProvisionerAbstract {
it
=
vmRequestedAndAllocatedList
.
listIterator
();
//update iterator with new state of the list
}
deallocateResourceForAllVms
();
for
(
VmRequestedAllocated
vra
:
finalList
){
//Allocates the requested resource from the physical resource
getResource
().
allocateResource
(
vra
.
getAllocated
());
getResourceAllocationMap
().
put
(
vra
.
getVm
(),
vra
.
getAllocated
());
vra
.
getVm
().
getResource
(
getResourceClass
()).
setAllocatedResource
(
vra
.
getAllocated
());
final
long
prevVmResourceAllocation
=
vra
.
getVm
().
getResource
(
getResourceClass
()).
getAllocatedResource
();
if
(
getResourceAllocationMap
().
containsKey
(
vra
.
getVm
()))
{
//Deallocates any amount of the resource assigned to the Vm in order to allocate a new capacity
deallocateResourceForVm
(
vra
.
getVm
());
}
/*
Pe resources are not stored in the VM resource List.
Only the provisioner keeps track of Pe allocation for VM.
This way, if the resource is not found inside the VM
and it is a Pe, it's OK (as it is expected)
*/
if
(!
getResource
().
isObjectSubClassOf
(
Pe
.
class
)
&&
!
vra
.
getVm
().
getResource
(
getResourceClass
()).
setCapacity
(
vra
.
getNewCapacity
())){
continue
;
}
//Allocates the requested resource from the physical resource
getResource
().
allocateResource
(
vra
.
getNewCapacity
());
getResourceAllocationMap
().
put
(
vra
.
getVm
(),
vra
.
getNewCapacity
());
vra
.
getVm
().
getResource
(
getResourceClass
()).
setAllocatedResource
(
prevVmResourceAllocation
);
}
}
@Override
...
...
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/schedulers/cloudlet/CloudletSchedulerAbstract.java
View file @
f86e954b
...
...
@@ -20,8 +20,10 @@ import java.util.stream.Stream;
import
org.cloudbus.cloudsim.cloudlets.Cloudlet
;
import
org.cloudbus.cloudsim.cloudlets.Cloudlet.Status
;
import
org.cloudbus.cloudsim.cloudlets.CloudletExecution
;
import
org.cloudbus.cloudsim.resources.Iops
;
import
org.cloudbus.cloudsim.resources.Ram
;
import
org.cloudbus.cloudsim.resources.ResourceManageable
;
import
org.cloudbus.cloudsim.resources.ResourceManageableAbstract
;
import
org.cloudbus.cloudsim.schedulers.cloudlet.network.PacketScheduler
;
import
org.cloudbus.cloudsim.util.Conversion
;
...
...
@@ -69,7 +71,7 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
*/
private
List
<
Double
>
currentMipsShare
;
private
double
iops
Capacity
;
private
double
iops
Allocated
;
/**
* @see #getCloudletExecList()
*/
...
...
@@ -102,7 +104,7 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
cloudletWaitingList
=
new
ArrayList
<>();
cloudletReturnedList
=
new
HashSet
<>();
currentMipsShare
=
new
ArrayList
<>();
iops
Capacity
=
0
;
iops
Allocated
=
0
;
packetScheduler
=
PacketScheduler
.
NULL
;
}
...
...
@@ -128,7 +130,7 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
@Override
public
double
getCurrentIops
()
{
return
iops
Capacity
;
return
iops
Allocated
;
}
/**
...
...
@@ -146,17 +148,16 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
}
/**
* Sets the current iops a
vailable
for the VM using the
* Sets the current iops a
llocated
for the VM using the
* scheduler.
*
* @param iops the new current iops
* @see #getCurrentMipsShare()
* @param iopsAllocated the new current iops
*/
protected
void
setCurrentIops
(
final
double
iops
)
{
if
(
iops
>
vm
.
getIops
().
getCapacity
()){
Log
.
printFormattedLine
(
"Requested %f iops but %s has just %d"
,
iops
,
vm
,
vm
.
getIops
().
getCapacity
());
protected
void
setCurrentIops
Allocated
(
final
double
iops
Allocated
)
{
if
(
iops
Allocated
>
vm
.
getIops
().
getCapacity
()){
Log
.
printFormattedLine
(
"Requested %f iops but %s has just %d"
,
iops
Allocated
,
vm
,
vm
.
getIops
().
getCapacity
());
}
this
.
iops
Capacity
=
iops
;
this
.
iops
Allocated
=
iopsAllocated
;
}
/**
...
...
@@ -199,7 +200,8 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
* @return the amount of available Iops.
*/
private
double
getAvailableIops
(
CloudletExecution
ce
){
return
ce
.
getCloudlet
().
getVm
().
getIops
().
getAllocatedResource
();
ResourceManageableAbstract
io
=
(
ResourceManageableAbstract
)
ce
.
getCloudlet
().
getVm
().
getIops
();
return
io
.
getAvailableResource
();
}
private
Double
getPeCapacity
()
{
...
...
@@ -516,7 +518,7 @@ public abstract class CloudletSchedulerAbstract implements CloudletScheduler {
@Override
public
double
updateProcessing
(
final
double
currentTime
,
final
List
<
Double
>
mipsShare
,
double
iops
)
{
setCurrentMipsShare
(
mipsShare
);
setCurrentIops
(
iops
);
setCurrentIops
Allocated
(
iops
);
if
(
cloudletExecList
.
isEmpty
()
&&
cloudletWaitingList
.
isEmpty
())
{
setPreviousTime
(
currentTime
);
...
...
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/schedulers/vm/VmSchedulerAbstract.java
View file @
f86e954b
...
...
@@ -209,7 +209,6 @@ public abstract class VmSchedulerAbstract implements VmScheduler {
@Override
public
double
getAllocatedIops
(
final
Vm
vm
)
{
// final double iops = vm.getIops().getCapacity();
final
double
iops
=
vm
.
getIops
().
getAllocatedResource
();
return
iops
;
}
...
...
cloudsim-plus/src/main/java/org/cloudbus/cloudsim/vms/VmSimple.java
View file @
f86e954b
...
...
@@ -232,6 +232,8 @@ public class VmSimple implements Vm {
@Override
public
double
updateProcessing
(
final
double
currentTime
,
final
List
<
Double
>
mipsShare
,
double
iops
)
{
Objects
.
requireNonNull
(
mipsShare
);
//System.out.println("Teste2! Vm id="+id+", iops="+iops);
if
(!
cloudletScheduler
.
getCloudletExecList
().
isEmpty
()){
this
.
lastBuzyTime
=
getSimulation
().
clock
();
...
...
cloudsim-plus/src/test/java/org/cloudbus/cloudsim/hosts/HostSimpleTest.java
View file @
f86e954b
...
...
@@ -173,7 +173,7 @@ public class HostSimpleTest {
final
List
<
Vm
>
vms
=
new
ArrayList
<>(
numberOfVms
);
for
(
int
i
=
0
;
i
<
numberOfVms
;
i
++)
{
final
Vm
vm
=
VmSimpleTest
.
createVm
(
i
,
MIPS
/
numberOfVms
,
1
,
RAM
/
numberOfVms
,
BW
/
numberOfVms
,
STORAGE
/
numberOfVms
);
i
,
MIPS
/
numberOfVms
,
1
,
RAM
/
numberOfVms
,
IOPS
/
numberOfVms
,
BW
/
numberOfVms
,
STORAGE
/
numberOfVms
,
CloudletScheduler
.
NULL
);
if
(
i
==
0
)
{
/*considers that one of the migrating in VMs already was placed at the host,
thus, it will not be added again to the host vm list.
...
...
@@ -515,13 +515,13 @@ public class HostSimpleTest {
@Test
public
void
testGetAllocatedBw
()
{
assertEquals
(
host
.
getAllocatedBw
(),
1000
0
);
assertEquals
(
host
.
getAllocatedBw
(),
0
);
}
@Test
public
void
testGetAllocatedRam
()
{
assertEquals
(
host
.
getAllocatedRam
(),
1024
);
assertEquals
(
host
.
getAllocatedRam
(),
0
);
}
@Test
...
...
@@ -548,7 +548,7 @@ public class HostSimpleTest {
@Test
public
void
testGetAllocatedIops
()
{
assertEquals
(
host
.
getAllocatedIops
(),
500
0
);
assertEquals
(
host
.
getAllocatedIops
(),
0
);
}
@Test
...
...
cloudsim-plus/src/test/java/org/cloudbus/cloudsim/schedulers/cloudlet/CloudletSchedulerTimeSharedTest.java
View file @
f86e954b
...
...
@@ -127,7 +127,7 @@ public class CloudletSchedulerTimeSharedTest {
final
List
<
Double
>
mipsList
=
CloudletSchedulerUtil
.
createMipsList
(
numberOfPes
,
mipsOfEachPe
);
scheduler
.
setCurrentMipsShare
(
mipsList
);
scheduler
.
setVm
((
new
VmSimple
(
0
,
mipsOfEachPe
,
numberOfPes
)).
setIops
(
iops
));
scheduler
.
setCurrentIops
((
double
)
iops
);
scheduler
.
setCurrentIops
Allocated
((
double
)
iops
);
return
scheduler
;
}
...
...
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