// String tmp = System.getProperty("user.home");
String gw2pePath = tmp + "/demo/gw2pe" + gwId;
String pePath = tmp + "/demo/pe";
// setup
IndexedChronicle gw2pe = new IndexedChronicle(gw2pePath);
gw2pe.useUnsafe(true);
Gw2PeWriter gw2PeWriter = new Gw2PeWriter(gw2pe.createExcerpt());
IndexedChronicle pe2gw = new IndexedChronicle(pePath);
pe2gw.useUnsafe(true);
final Histogram times = new Histogram(10000, 100);
final AtomicInteger reportCount = new AtomicInteger();
Pe2GwEvents listener = new Pe2GwEvents() {
@Override
public void report(@NotNull MetaData metaData, SmallReport smallReport) {
if (metaData.sourceId != gwId) return;
if (!throughputTest)
times.sample(metaData.inReadTimestamp7Delta * 100);
reportCount.getAndIncrement();
}
};
Pe2GwReader pe2GwReader = new Pe2GwReader(gwId, pe2gw.createExcerpt(), listener);
// synchronize the start.
if (gwId > 1) {
int startTime = (int) ((System.currentTimeMillis() / 1000 - 5) % 10) + 5;
System.out.println("Count down");
for (int i = startTime; i > 0; i--) {
System.out.print(i + " ");
System.out.flush();
Thread.sleep(1000);
}
}
System.out.println("Started");
long start = System.nanoTime();
// run loop
SmallCommand command = new SmallCommand();
@SuppressWarnings("MismatchedQueryAndUpdateOfStringBuilder")
StringBuilder clientOrderId = command.clientOrderId;
for (int i = 0; i < orders; i++) {
clientOrderId.setLength(0);
clientOrderId.append("clientOrderId-");
clientOrderId.append(gwId);
clientOrderId.append('-');
clientOrderId.append(i);
command.instrument = "XAU/EUR";
command.price = 1209.41;
command.quantity = 1000;
command.side = (i & 1) == 0 ? Side.BUY : Side.SELL;
gw2PeWriter.small(null, command);
if (throughputTest) {
do {
/* read another */
} while (pe2GwReader.readOne());
} else {
do {
/* read another */
} while (pe2GwReader.readOne() || reportCount.get() < i - 1);
}
}
while (reportCount.get() < orders) {
pe2GwReader.readOne();
}
long time = System.nanoTime() - start;
System.out.printf("Processed %,d events in and out in %.1f seconds%n", orders, time / 1e9);
if (!throughputTest) {
System.out.printf("The latency distribution was %.1f, %.1f/%.1f/%.1f us for the 1, 90/99/99.9 %%tile%n",
times.percentile(0.01) / 1e3,
times.percentile(0.90) / 1e3,
times.percentile(0.99) / 1e3,
times.percentile(0.999) / 1e3
);
}
gw2pe.close();
pe2gw.close();
}