CloudSim4.0 Learning(1)
文章目录
Example1
1 CloudSim初始化
int num_user = 1;
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false;
CloudSim.init(num_user, calendar, trace_flag);
这一部分代码主要是初始化模拟程序
num_user是控制用户数量的一个参数
calendar是控制时间的参数
trace_flag 控制日志的输出[有待进一步查证]我改成true之后毫无变化
1.1 CloudSim.init(num_user, calendar, trace_flag)
调用CloudSim类中的initCommonVariable(cal, traceFlag, numUser);
设置calendar、numUser、traceFlag。
cis = new CloudInformationService("CloudInformationService");
则是声明一个新的CIS对象,用来存储仿真信息。 原文的相关表述如下:A Cloud Information Service (CIS) is an entity that provides cloud resource registration
CIS提供的应该是注册表的服务,会记录所有的Entity的ID,但不负责具体的信息的管理。
public static void init(int numUser, Calendar cal, boolean traceFlag) {
try {
initCommonVariable(cal, traceFlag, numUser);
// create a CIS object
cis = new CloudInformationService("CloudInformationService");//初始化CloudInformationService
// set all the above entity IDs
cisId = cis.getId();
Log.printLine("cisId:"+cisId);
} catch (IllegalArgumentException s) {
Log.printLine("CloudSim.init(): The simulation has been terminated due to an unexpected error");
Log.printLine(s.getMessage());
} catch (Exception e) {
Log.printLine("CloudSim.init(): The simulation has been terminated due to an unexpected error");
Log.printLine(e.getMessage());
}
}
1.2 initCommonVariable(cal, traceFlag, numUser);
该函数主要是为了设置calendar、traceFlag和numUser
还调用了CloudSimShutdown shutdown = new CloudSimShutdown("CloudSimShutdown", numUser);
根据源代码的注释来看就是个结束的标识。原文如下:This object signals the end of simulation to CloudInformationService (CIS) entity.
private static void initCommonVariable(Calendar _calendar, boolean _traceFlag, int numUser)
throws Exception {
initialize();
// NOTE: the order for the below 3 lines are important
traceFlag = _traceFlag;
// Set the current Wall clock time as the starting time of
// simulation
if (_calendar == null) {
calendar = Calendar.getInstance();
} else {
calendar = _calendar;
}
// creates a CloudSimShutdown object
CloudSimShutdown shutdown = new CloudSimShutdown("CloudSimShutdown", numUser);
shutdownId = shutdown.getId();
Log.print(shutdownId+"\n");
}
2 DataCenter初始化
Datacenter datacenter0 = createDatacenter("Datacenter_0");
创建了一个名为’Datacenter_0’的datacenter0变量
Datacenter类
包含如下域:
characteristics是DatacenterCharacteristics类,主要负责存储datacenter的特征。
regionalCisName主要是负责存储原始的CIS信息。
vmAllocationPolicy主要负责控制虚拟机的分配策略。
lastProcessTime负责记录云任务列表最后一次被运行的时间
vmList负责记录虚拟机的列表
schedulingInterval调度间隔,每隔多长时间调度一次event
/** The characteristics. */
private DatacenterCharacteristics characteristics;
/** The regional Cloud Information Service (CIS) name.*@see org.cloudbus.cloudsim.core.CloudInformationService*/
private String regionalCisName;
/** The vm provisioner. */
private VmAllocationPolicy vmAllocationPolicy;
/** The last time some cloudlet was processed in the datacenter. */
private double lastProcessTime;
/** The storage list. */
private List<Storage> storageList;
/** The vm list. */
private List<? extends Vm> vmList;