use of org.HdrHistogram.Histogram in project fast-cast by RuedigerMoeller.
the class AsyncLatPublisher method initFastCast.
public void initFastCast() throws Exception {
fastCast = FastCast.getFastCast();
fastCast.setNodeId("PUB");
fastCast.loadConfig(CFG_FILE_PATH);
pub = new ObjectPublisher(fastCast.onTransport("default").publish("stream"), AsyncLatMessage.class);
fastCast.onTransport("back").subscribe("back", new ObjectSubscriber(false, AsyncLatMessage.class) {
@Override
protected void objectReceived(String s, long l, Object o) {
if ("END".equals(o)) {
final Histogram oldHi = hi;
hi = new Histogram(TimeUnit.SECONDS.toNanos(2), 3);
// no lambdas to stay 1.7 compatible
// move printing out of the receiving thread
dumper.execute(new Runnable() {
@Override
public void run() {
oldHi.outputPercentileDistribution(System.out, 1000.0);
}
});
// hi.reset();
return;
}
final long value = System.nanoTime() - ((AsyncLatMessage) o).getSendTimeStampNanos();
if (value < 1_000_000_000)
hi.recordValue(value);
}
@Override
public boolean dropped() {
System.exit(-2);
return false;
}
});
}
use of org.HdrHistogram.Histogram in project fast-cast by RuedigerMoeller.
the class AsyncPubStruct method initFastCast.
public void initFastCast() throws Exception {
fastCast = FastCast.getFastCast();
fastCast.setNodeId("PUB");
fastCast.loadConfig(CFG_FILE_PATH);
pub = fastCast.onTransport("default").publish("stream");
// pointer to message
final FSTStruct msg = FSTStructFactory.getInstance().createEmptyStructPointer(FSTStruct.class);
fastCast.onTransport("back").subscribe("back", new FCSubscriber() {
@Override
public void messageReceived(String sender, long sequence, Bytez b, long off, int len) {
// as structs decode literally in zero time, we can decode inside receiver thread
msg.baseOn(b, (int) off);
Class type = msg.getPointedClass();
if (type == StructString.class) {
// sequence end, print histogram
final Histogram oldHi = hi;
hi = new Histogram(TimeUnit.SECONDS.toNanos(2), 3);
// no lambdas to stay 1.7 compatible
// move printing out of the receiving thread
dumper.execute(new Runnable() {
@Override
public void run() {
oldHi.outputPercentileDistribution(System.out, 1000.0);
}
});
} else {
// a regular message, record latency
AsyncLatMessageStruct mdata = msg.cast();
long value = System.nanoTime() - mdata.getSendTimeStampNanos();
if (value < 1_000_000_000) {
// avoid AIOB during init + JITTING
hi.recordValue(value);
}
// a real app would need to copy the message (recycle byte arrays/objects !) and
// run msg processing in an executor to get out of the receiving thread.
// mdata gets invalid on finish of this method
}
}
@Override
public boolean dropped() {
System.out.println("DROPPED");
System.exit(-1);
return false;
}
@Override
public void senderTerminated(String senderNodeId) {
}
@Override
public void senderBootstrapped(String receivesFrom, long seqNo) {
}
});
}
Aggregations