为了不让缓冲区大小影响到两个路由协议性能的比较,将缓冲区大小设成无限大,不失是个好选择。本文介绍如何设置无限缓冲区。
1. 概述
The ONE的变量设置大概是这样的:程序中定义一些初始变量(如Message.java
中的public static final int INFINITE_TTL = -1
);仿真初始化时,将default_settings.txt
读入;读入诸如my_settings.txt
覆盖之前的值。建议将default_settings.txt
删掉。
理解了这点,设置无限制缓冲区就很简单了。实际上,The ONE在MessageRouter.java
将bufferSize
初始为Integer.MAX_VALUE
(即231-1),所以只需将default_settings.txt
和my_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.txt
的bufferSize
,将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); } }赞赏
微信赞赏
支付宝赞赏
您好,我将default_settings.txt和my_settings.txt中含有Group.bufferSize的行注释掉了。但运行的时候提示:
“Can’t start: error in configuration file(s)
Can’t find setting ‘Group.bufferSize’”
确定直接注释删除可以运行吗?还是要设置成一个比较大的值?
还有关于消息生存时间,如果要设置成无限,怎么处理,源码中:
this.msgTtl = Message.INFINITE_TTL; //将msgTtl初始为-1
很显然是不能直接注释掉的,那设置成运行时间?
The ONE我使用的版本是
one_1.5.1-rc2
,你试试Group.bufferSize=Integer.MAX_VALUE
。将消息的TTL设为无限,在你的设备文件添加
Group.msgTtl = -1
。Pingback: The ONE使用笔记:目录 | Spark & Shine