use of org.nustaq.fastcast.util.RateMeasure in project fast-cast by RuedigerMoeller.
the class BatchingController method main.
//
// public void block() {
// while ( packetCounter >= maxRatePerInterval) {
// while( (System.nanoTime() - lastCheck) < interValNanos ) {
// // spin
// }
// lastCheck = System.nanoTime();
// packetCounter -= maxRatePerInterval;
// }
// }
public static void main(String[] arg) {
// System.out.println(new BatchingController(100));
// System.out.println(new BatchingController(200));
// System.out.println(new BatchingController(1000));
// System.out.println(new BatchingController(2000));
// System.out.println(new BatchingController(5000));
// System.out.println(new BatchingController(10000));
// System.out.println(new BatchingController(15000));
// System.out.println(new BatchingController(20000));
// System.out.println(new BatchingController(30000));
// System.out.println(new BatchingController(50000));
// System.out.println(new BatchingController(70000));
// System.out.println(new BatchingController(100000));
// System.out.println(new BatchingController(500000));
BatchingController limiter = new BatchingController(10000);
RateMeasure m = new RateMeasure("msg rate");
RateMeasure pm = new RateMeasure("packet rate");
int msgPerPackAssumption = 4;
int batchCount = 0;
while (true) {
// LockSupport.parkNanos(1_000);
// Sleeper.spinMicros(300);
Action a = limiter.getAction();
if (a == Action.NONE) {
limiter.countPacket();
pm.count();
m.count();
} else if (a == Action.BATCH) {
if (batchCount == msgPerPackAssumption) {
limiter.countPacket();
pm.count();
batchCount = 0;
}
batchCount++;
m.count();
} else /*block*/
{
int x = 0;
}
}
}
use of org.nustaq.fastcast.util.RateMeasure in project fast-cast by RuedigerMoeller.
the class SendReceive method send.
// @Test
public void send() throws InterruptedException {
initFC();
TestMsg template = new TestMsg();
FSTStructAllocator allocator = new FSTStructAllocator(0);
TestMsg toSend = allocator.newStruct(template);
FCPublisher sender = fc.onTransport("default").publish(fc.getPublisherConf("test"));
toSend.getString().setString("H");
RateMeasure measure = new RateMeasure("msg send " + toSend.getByteSize());
final Bytez base = toSend.getBase();
final int byteSize = toSend.getByteSize();
final long offset = toSend.getOffset();
long tim = System.currentTimeMillis();
while (true) {
Sleeper.spinMicros(50);
toSend.setTimeNanos(System.nanoTime());
while (!sender.offer(null, base, offset, byteSize, true)) {
// System.out.println("offer rejected !");
}
measure.count();
// System.out.println("sent msg");
if (System.currentTimeMillis() - tim > 5000) {
break;
}
}
}
use of org.nustaq.fastcast.util.RateMeasure in project fast-cast by RuedigerMoeller.
the class StructSubscriber method main.
public static void main(String[] arg) {
Protocol.initStructFactory();
// 5 chars MAX !!
FastCast.getFastCast().setNodeId("SUB");
StructPublisher.configureFastCast();
final RateMeasure rateMeasure = new RateMeasure("receive rate");
FastCast.getFastCast().onTransport("default").subscribe(new SubscriberConf(1).receiveBufferPackets(33_000), new FCSubscriber() {
PriceUpdateStruct msg = FSTStructFactory.getInstance().createEmptyStructPointer(PriceUpdateStruct.class);
@Override
public void messageReceived(String sender, long sequence, Bytez b, long off, int len) {
msg.baseOn(b, (int) off);
rateMeasure.count();
// instanceof'ing in case of various messages
// Class msgStruct = msg.getPointedClass(); otherStructClass = msg.detachTo(otherStructClass);
}
@Override
public boolean dropped() {
System.out.println("fatal, could not keep up. exiting");
System.exit(0);
return false;
}
@Override
public void senderTerminated(String senderNodeId) {
System.out.println("sender died " + senderNodeId);
}
@Override
public void senderBootstrapped(String receivesFrom, long seqNo) {
System.out.println("bootstrap " + receivesFrom);
}
});
}
use of org.nustaq.fastcast.util.RateMeasure in project fast-cast by RuedigerMoeller.
the class SendReceive method testSleeper.
public void testSleeper() {
RateMeasure rm = new RateMeasure("ticks ps");
Sleeper sl = new Sleeper();
while (true) {
sl.spinMicros(80);
rm.count();
}
}
use of org.nustaq.fastcast.util.RateMeasure in project fast-cast by RuedigerMoeller.
the class AsyncSubStruct method initFastCast.
public void initFastCast() throws Exception {
fastCast = FastCast.getFastCast();
fastCast.setNodeId("SUB");
fastCast.loadConfig(AsyncLatPublisher.CFG_FILE_PATH);
backPub = fastCast.onTransport("back").publish("back");
// pointer to message
final FSTStruct msg = FSTStructFactory.getInstance().createEmptyStructPointer(FSTStruct.class);
final RateMeasure measure = new RateMeasure("receive rate");
fastCast.onTransport("default").subscribe("stream", new FCSubscriber() {
int count = 0;
@Override
public void messageReceived(String sender, long sequence, Bytez b, long off, final int len) {
measure.count();
if (++count == 10 || len < 30) /*"END" marker*/
{
count = 0;
final byte[] copy = pool.getBA();
if (// prevent segfault :) !
len < copy.length) {
b.getArr(off, copy, 0, len);
count = 0;
// do bounce back in different thread, else blocking on send will pressure back to
// sender resulting in whacky behaviour+throughput
bounceBackExec.execute(new Runnable() {
@Override
public void run() {
while (!backPub.offer(null, copy, 0, len, true)) {
// spin
}
// give back to pool
pool.returnBA(copy);
}
});
} else {
throw new RuntimeException("was soll das ?");
}
}
}
@Override
public boolean dropped() {
// fatal, exit
System.out.println("process dropped ");
System.exit(-1);
return false;
}
@Override
public void senderTerminated(String senderNodeId) {
}
@Override
public void senderBootstrapped(String receivesFrom, long seqNo) {
}
});
}
Aggregations