The ONE使用笔记:设置无限缓冲区

为了不让缓冲区大小影响到两个路由协议性能的比较,将缓冲区大小设成无限大,不失是个好选择。本文介绍如何设置无限缓冲区。

1. 概述

The ONE的变量设置大概是这样的:程序中定义一些初始变量(如Message.java中的public static final int INFINITE_TTL = -1);仿真初始化时,将default_settings.txt读入读入诸如my_settings.txt覆盖之前的值建议将default_settings.txt删掉。

理解了这点,设置无限制缓冲区就很简单了。实际上,The ONE在MessageRouter.javabufferSize初始为Integer.MAX_VALUE(即231-1),所以只需将default_settings.txtmy_settings.txt中含有Group.bufferSize的行删除或者注释即可值得注意的是,设置成无限缓冲区,仿真非常耗时。

1.1 估计缓冲区大小

假设参数设置如下:

Scenario.endTime = 432000

Events2.class = MessageEventGenerator
Events2.interval = 25,35    # 取30秒
Events2.size = 5k,10k       # 取10k

所需缓冲区大约需要(这里,假设消息生存时间TTL也是无限的):432000/30 * 10k,约144M。

2.相关源代码

2.1 读入default_settings.txt

Settings初始化init将default_settings.txt读入内存,供后续使用,主要源代码如下:

// Settings.java
protected static Properties props;
public static final String DEF_SETTINGS_FILE ="default_settings.txt";
public static void init(String propFile) throws SettingsError {
    String outFile;
    if (new File(DEF_SETTINGS_FILE).exists()) {
        Properties defProperties = new Properties();
        defProperties.load(new FileInputStream(DEF_SETTINGS_FILE));
        props = new Properties(defProperties);
    }
    outFile = props.getProperty(SETTING_OUTPUT_S);
}

Properties是Java内建的类,可以理解成由一系列键-值对属性值组成,官官介绍如下:

The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

2.2 读入my_settings.txt

DTNSim.java的主函数main调用initSettings(confFiles, firstConfIndex)读入my_settings.txt,相关源代码如下:

//DTNSim.java
private static void initSettings(String[] confFiles, int firstIndex) {  //firstIndex指示从哪里读取设置文件
    int i = firstIndex;
    Settings.init(confFiles[i]);
    for (i=firstIndex+1; i<confFiles.length; i++) {
        Settings.addSettings(confFiles[i]);
    }
}

可见,命令行可以包含多个设置文件,但后面的字段会覆盖之前的字段。

2.3 设置bufferSize

经历了上面两步,my_settings.txt已替换了default_settings.txtbufferSize,将my_settings.txt中的bufferSize读入bufferSize,相关源代码如下:

public static final int INFINITE_TTL = -1;  //在Message.java定义

//MessageRouter.java
public static final String B_SIZE_S = "bufferSize";
public static final String MSG_TTL_S = "msgTtl";
public MessageRouter(Settings s) {
    this.bufferSize = Integer.MAX_VALUE; //将bufferSize初始为MAX_VALUE
    this.msgTtl = Message.INFINITE_TTL;  //将msgTtl初始为-1
    
    if (s.contains(B_SIZE_S)) {
        this.bufferSize = s.getInt(B_SIZE_S);   //覆盖bufferSize
    }
    if (s.contains(MSG_TTL_S)) {
        this.msgTtl = s.getInt(MSG_TTL_S);  
    }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

One thought on “The ONE使用笔记:设置无限缓冲区