use of org.nustaq.kontraktor.util.RateMeasure in project kontraktor by RuedigerMoeller.
the class AsyncServerSocketTest method serialSync.
@Test
public void serialSync() throws Exception {
AtomicInteger COUNT = new AtomicInteger(0);
TCPObjectServer tcpObjectServer = new TCPObjectServer(8082);
RateMeasure measure = new RateMeasure("count");
tcpObjectServer.start((client) -> {
try {
while (true) {
Object request = client.readObject();
if (request == null)
// connection closed
return;
COUNT.incrementAndGet();
measure.count();
}
} catch (EOFException eof) {
// e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
});
Thread.sleep(1000);
HashMap testMap = new HashMap();
testMap.put("pok", 13);
testMap.put("yes", "no");
testMap.put("true", "maybe");
ExecutorService executorService = Executors.newCachedThreadPool();
int MSG_COUNT = 10_000_000;
int NUM_CLIENTS = 100;
for (int ii = 0; ii < NUM_CLIENTS; ii++) {
final int finalIi = ii;
executorService.execute(() -> {
TCPObjectSocket sock = null;
try {
sock = new TCPObjectSocket("localhost", 8082);
// System.out.println("start "+finalIi);
for (int i = 0; i < MSG_COUNT / NUM_CLIENTS; i++) {
sock.writeObject(testMap);
sock.flush();
}
sock.close();
// System.out.println("finished "+ finalIi);
} catch (Exception e) {
e.printStackTrace();
}
});
}
Thread.sleep(3000);
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.DAYS);
int to = 0;
while (to < 7 && COUNT.get() < MSG_COUNT) {
Thread.sleep(1000);
System.out.println("COUNT " + COUNT.get());
to++;
}
Assert.assertTrue(COUNT.get() == MSG_COUNT);
}
use of org.nustaq.kontraktor.util.RateMeasure in project kontraktor by RuedigerMoeller.
the class AkkaInterop method akkaConsumes.
@Test
public void akkaConsumes() throws InterruptedException {
final int NUM_MSG = 20_000_000;
final ActorSystem system = ActorSystem.create("reactive-interop");
// Attention: buffer + batchsizes of Akka need increase in order to get performance
final ActorMaterializer mat = ActorMaterializer.create(ActorMaterializerSettings.create(system).withInputBuffer(4096, 4096), system);
KxReactiveStreams kxStreams = KxReactiveStreams.get();
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Source.from(kxStreams.produce(IntStream.range(0, NUM_MSG))).runWith(Sink.foreach(elem -> {
rm.count();
count.countDown();
}), mat);
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + count.getCount());
Thread.sleep(1000);
}
system.shutdown();
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
use of org.nustaq.kontraktor.util.RateMeasure in project kontraktor by RuedigerMoeller.
the class AkkaInterop method akkaAkka.
@Test
public void akkaAkka() throws InterruptedException {
final int NUM_MSG = 10_000_000;
final ActorSystem system = ActorSystem.create("reactive-interop");
// Attention: buffer + batchsizes of Akka need increase in order to get performance
final ActorMaterializer mat = ActorMaterializer.create(ActorMaterializerSettings.create(system).withInputBuffer(4096, 4096), system);
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
Source.from(it).runWith(Sink.foreach(elem -> {
rm.count();
count.countDown();
}), mat);
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + count.getCount());
Thread.sleep(1000);
}
system.shutdown();
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
use of org.nustaq.kontraktor.util.RateMeasure in project kontraktor by RuedigerMoeller.
the class AkkaInterop method serveAkka_RemoteToKontraktor.
@Test
public void serveAkka_RemoteToKontraktor() throws InterruptedException {
final int NUM_MSG = 50_000_000;
final ActorSystem system = ActorSystem.create("reactive-interop");
final Materializer mat = ActorMaterializer.create(system);
KxReactiveStreams kxStreams = KxReactiveStreams.get();
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
Publisher<Integer> pub = (Publisher<Integer>) Source.from(it).runWith(Sink.publisher(), mat);
kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6790).urlPath("akka"));
// subscribe with kontraktor client
new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6790/akka")).subscribe((res, err) -> {
if (Actors.isResult(err)) {
rm.count();
count.countDown();
}
});
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + count.getCount());
Thread.sleep(1000);
}
system.shutdown();
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
use of org.nustaq.kontraktor.util.RateMeasure in project kontraktor by RuedigerMoeller.
the class AkkaInterop method same_as_serveAkkaKontraktorAsBridge_use_RxJavaAtReceiverSide.
@Test
public void same_as_serveAkkaKontraktorAsBridge_use_RxJavaAtReceiverSide() throws InterruptedException {
Log.setLevel(Log.DEBUG);
final int NUM_MSG = 20_000_000;
final ActorSystem system = ActorSystem.create("reactive-interop");
// Attention: buffer + batchsizes of Akka need increase in order to get performance
final ActorMaterializer mat = ActorMaterializer.create(ActorMaterializerSettings.create(system).withInputBuffer(8192, 8192), system);
KxReactiveStreams kxStreams = KxReactiveStreams.get();
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
Publisher<Integer> pub = (Publisher<Integer>) Source.from(it).runWith(Sink.publisher(), mat);
kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6789).urlPath("akka"));
AtomicInteger kontraktorCount = new AtomicInteger(0);
// subscribe with akka client
KxPublisher<Integer> remotedPublisher = new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6789/akka")).map(x -> {
// (*)
kontraktorCount.incrementAndGet();
return x;
});
RxReactiveStreams.toObservable(remotedPublisher).forEach(i -> {
rm.count();
count.countDown();
});
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + (NUM_MSG - count.getCount()) + " kontraktor count:" + kontraktorCount.get());
Thread.sleep(1000);
}
system.shutdown();
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
Aggregations