CoralLog Latency Test
package com.coralblocks.corallog.bench;
import java.io.File;
import java.nio.ByteBuffer;
import com.coralblocks.coralbits.bench.Benchmarker;
import com.coralblocks.coralbits.util.SystemUtils;
import com.coralblocks.corallog.AsyncThread;
import com.coralblocks.corallog.Log;
import com.coralblocks.corallog.LogConfig;
import com.coralblocks.corallog.Logger;
import com.coralblocks.coralthreads.Affinity;
public class Latency {
public static void main(String[] args) throws Exception {
int msgSize = Integer.parseInt(args[0]);
int warmup = Integer.parseInt(args[1]);
int messages = Integer.parseInt(args[2]);
byte[] msgBytes = new byte[msgSize];
// build a dummy message:
for(int i = 0; i < msgBytes.length; i++) {
msgBytes[i] = (byte) String.valueOf(i % 10).charAt(0);
}
int procToBindProducer = SystemUtils.getInt("procToBindProducer", -1);
if (procToBindProducer != -1) Affinity.set(procToBindProducer);
String filename = "latency.log";
LogConfig logConfig = new LogConfig(filename);
logConfig.includeTimestamp = SystemUtils.getBoolean("includeTimestamp", true);
Logger logger = Log.createLogger(logConfig);
ByteBuffer bb = ByteBuffer.allocateDirect(1024);
bb.put(msgBytes);
bb.flip();
boolean detailedBenchmarker = SystemUtils.getBoolean("detailedBenchmarker", true);
Benchmarker bench = Benchmarker.create(warmup, detailedBenchmarker);
int total = warmup + messages;
for(int i = 0; i < total; i++) {
bb.position(0);
bench.mark();
logger.log(bb);
bench.measure();
if ((i + 1) % AsyncThread.getCapacity() == 0) {
// for latency we never want queue contention
logger.drainAndWait();
}
}
System.out.println();
System.out.println(bench.results());
System.out.println();
logger.drainCloseAndWait();
boolean deleteFile = SystemUtils.getBoolean("deleteFile", true);
if (deleteFile) {
File f = new File(filename);
f.delete();
}
AsyncThread.drainAndDie(); // just so the vm will exit... (async thread is not daemon)
}
}