cloudsimplus / cloudsimplus

State-of-the-art Framework 🏗 for Cloud Computing ⛅️ Simulation: a modern, full-featured, easier-to-use, highly extensible 🧩, faster 🚀 and more accurate ☕️ Java 17+ tool for cloud computing research 🎓. Examples: https://github.com/cloudsimplus/cloudsimplus-examples

Home Page:https://cloudsimplus.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementing a synchronous simulation

pkoperek opened this issue · comments

Hi!

First of all - I find Cloud Sim Plus very useful - thanks for the great work you're doing!
I plan to use it in a new project and was wondering if the scenario I'm considering could be implemented with use of APIs which the library already exposes, or there would have to be some extensions done.

Detailed information about how the feature should work

I would like to use Cloud Sim Plus environment in a "synchronous" way:

  • be able to run it for a quant of time (e.g. a second or a minute - in terms of simulated time, not the wall-clock time)
  • check some metrics afterwards
  • potentially execute some action (e.g. schedule more cloudlets or schedule removing of a VM)

Is that currently possible? If not, where is the best place to start implementing this?

An example scenario where this feature should be used

Using the simulation as an environment for Reinforcement Learning agents where they can observe and interact with simulated cloud resources.

A brief explanation of why you think this feature is useful

I'm doing some research in this area - such mode of execution would be super useful to me.

How to use this feature

This feature basically enables you to run your simulation inside a loop and collect any data you want after each step, as shown in the code snippet below:

//realize it uses startSync() instead of start()
simulation.startSync(); 
while(simulation.isRunning()){
    simulation.runFor(INTERVAL);
    collectAndPrintSomeDataSuchAsResourceUtilization();
}

The SynchronousSimulationExample1 provides a complete example.

Hello @pkoperek

First of all - I find Cloud Sim Plus very useful - thanks for the great work you're doing!

Thank you. Really appreciated.

Detailed information about how the feature should work

I would like to use Cloud Sim Plus environment in a "synchronous" way:

  • be able to run it for a quant of time (e.g. a second or a minute - in terms of simulated time, not the wall-clock time)

Probably what you're looking for is the CloudSim.terminateAt() method. It enables you to keep the simulation running until a defined time in seconds. Check KeepSimulationRunningExample.java.

  • check some metrics afterwards
  • potentially execute some action (e.g. schedule more cloudlets or schedule removing of a VM)

This can be achieved using lots of CloudSim Plus event listeners available across multiple classes, as can be seen in the listeners package. There are some examples available here.

You can schedule more cloudlets or other actions easily. Just check the examples here.

Is that currently possible? If not, where is the best place to start implementing this?

I think the examples I mentioned enable you to perform what you need. If not, give me more details and I'll try to help you.

An example scenario where this feature should be used

Using the simulation as an environment for Reinforcement Learning agents where they can observe and interact with simulated cloud resources.

I think it's great. A lot of new algorithms may come up from this approach.

A brief explanation of why you think this feature is useful

I'm doing some research in this area - such mode of execution would be super useful to me.

I saw you've created a python gateway for CloudSim Plus. It's really great. I just didn't see how to use it, or some examples.
It would be very useful if you include that. I'll be happy to add a link in CloudSim Plus page to your project.

Finally, I'll be thankful if you could include a link to http://cloudsimplus.org in your repositories that mention CloudSim Plus. If you need anything that I can help, feel free to keep in touch.

You may also be interested in CloudSim Plus Automation, a tool that enables creating simulation scenarios from a YAML file and executing in CloudSim Plus.

Hi @manoelcampos !

Thanks for the information - need to read through it. I'm just starting with the project - as you might have noticed right now it is just a rather ugly hack which works under very specific conditions :).

I'll add some more info in the next few days (i'll make sure to include link to you project).

Thanks and regards.

Hi @manoelcampos ,

I had a look at the example you pointed to. What I'm looking for is something slightly different. In KeepSimulationRunningExample you start a simulation which has a fixed lifespan:

        simulation.terminateAt(TIME_TO_TERMINATE_SIMULATION);

and then in order to interact with the simulation, you use listeners.

What I'm looking for on the other hand is to do something similar to this:

CloudSim cloudsim = new CloudSim();

// prepare simulation objects 

cloudsim.startRunning(); // set running to true internally
while(cloudsim.isRunning()) {
    cloudsim.pause(cloudsim.clock() + 1.0);
    cloudsim.resume();
}

I think part of the issue is how the event loop works: I think it jumps between distant events of the simulation if nothing happens between them. In the example from README the processing is like this:

11:41:13.101 [Thread-0] INFO  DatacenterBroker - 0.1: DatacenterBrokerSimple1: Sending Cloudlet 0 to Vm 0 in Host 0/DC 2.
11:41:13.101 [Thread-0] INFO  DatacenterBroker - 0.1: DatacenterBrokerSimple1: Sending Cloudlet 1 to Vm 0 in Host 0/DC 2.
11:41:13.102 [Thread-0] INFO  DatacenterBroker - 0.1: DatacenterBrokerSimple1: All waiting Cloudlets submitted to some VM.
### I would like to pause here at every full second between 0 and 40 seconds
11:41:15.122 [Thread-0] INFO  DatacenterBroker - 40.1: DatacenterBrokerSimple1: Cloudlet 0 finished and returned to broker.
11:41:15.123 [Thread-0] INFO  DatacenterBroker - 40.1: DatacenterBrokerSimple1: Cloudlet 1 finished and returned to broker.
11:41:15.125 [Thread-0] INFO  CloudSim - 40.21: Processing last events before simulation shutdown.
11:41:15.125 [Thread-0] INFO  DatacenterBroker - 40.21: DatacenterBrokerSimple1 is shutting down...
11:41:15.125 [Thread-0] INFO  DatacenterBroker - 40.21: DatacenterBrokerSimple1: Requesting Vm 0 destruction.
11:41:15.131 [Thread-0] INFO  DatacenterSimple - 40,21: DatacenterSimple: Vm 0/Broker 1 destroyed on Host 0/DC 2. 

Does that make sense to you?

If yes, what would be your recommended way of implementing this? I came up with two approaches:

  • have a special kind of event which just "starts" at the beginning of every second and keep adding it until the simulation is not finished
  • introduce new methods which would allow to control event loop processing from outside CloudSim class (e.g. startSynchronous() which just switches the state of simulation to "running" and a method runUntil which would try to process all events until X and then end)

What do you think?

Cheers,
Pawel

Hello @pkoperek

I can see a couple of scenarios this feature can be used. It will provide more freedom to the researcher in the way to interact with the simulation and collect data. It's an alternative to listeners, making data collection even easier. For large scale simulations, too many listeners might reduce simulation performance and I've been tackling performance issues for a while.

Could you present some other utilization scenarios?

About the utilization of this feature, I think it would be like below:

CloudSim cloudsim = new CloudSim();

// prepare simulation objects 

cloudsim.startSync();
while(cloudsim.isRunning()) {
    cloudsim.runFor(1.0); //run for 1 second
    // perform any desired operations, such as data collection
}
cloudsim.finalizeSimulation();

The issue here is the requirement to call cloudsim.finalizeSimulation(). This method was required to be called directly in CloudSim. In CloudSim Plus I just made it private and it's called internally. That approach avoids the researcher to worry about that call.
In the current state, that loop will run forever, since just the finalizeSimulation() sets the running flag to false.

I think it's a nice feature and we can move on to include it in CloudSim Plus. I'm going to review your PR and give you some feedback. Thanks for contributing.