我一直在对 Chronicle 队列进行一些性能测试,但我没有得到 Chronicle 声称的微秒延迟。我有一个作家和读者设置。写入器将当前时间写入队列,读取器从队列中读取并获取当前时间并进行差异获取延迟。我对一百万条消息执行此操作,然后取平均值。
我的作家的代码:
public class Client {
public static void main(String[] args) {
String path = "/dev/shm/queue";
SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).build();
ExcerptAppender appender = queue.acquireAppender();
Scanner read = new Scanner(System.in);
for (int i = 0;i<1;i++){
for (int j=0;j<1000000;j++) {
long time = System.nanoTime();
appender.writeText(Long.toString(time));
}
}
appender.writeText("end");
}
}
我的读者
public class Server {
public static void main(String[] args) {
String path = "/dev/shm/queue";
SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(path).build();
ExcerptTailer tailer = queue.createTailer();
DescriptiveStatistics results = new DescriptiveStatistics();
while (true) {
String text = tailer.readText();
if (text == null) {
Jvm.pause(10);
} else if (text.equals("end")) {
System.out.println("Results: " + results.getMean() / 1000);
break;
}
else {
long cur = System.nanoTime();
long recv = Long.parseLong(text);
long diff = cur - recv;
results.addValue(diff);
}
}
}
}
我得到了几十甚至几百毫秒的延迟。有什么可以帮助我的吗?我认为我做的事情显然是错误的。