use of org.agrona.console.ContinueBarrier in project Aeron by real-logic.
the class EmbeddedExclusiveThroughput method main.
public static void main(final String[] args) throws Exception {
MediaDriver.loadPropertiesFiles(args);
final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), EmbeddedExclusiveThroughput::printRate);
final FragmentHandler rateReporterHandler = rateReporterHandler(reporter);
final ExecutorService executor = Executors.newFixedThreadPool(2);
final Aeron.Context context = new Aeron.Context();
final AtomicBoolean running = new AtomicBoolean(true);
try (MediaDriver ignore = MediaDriver.launch();
Aeron aeron = Aeron.connect(context);
ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID);
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
executor.execute(reporter);
executor.execute(() -> SamplesUtil.subscriberLoop(rateReporterHandler, FRAGMENT_COUNT_LIMIT, running).accept(subscription));
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
do {
System.out.format("%nStreaming %,d messages of size %d bytes to %s on stream Id %d%n", NUMBER_OF_MESSAGES, MESSAGE_LENGTH, CHANNEL, STREAM_ID);
printingActive = true;
long backPressureCount = 0;
for (long i = 0; i < NUMBER_OF_MESSAGES; i++) {
ATOMIC_BUFFER.putLong(0, i);
OFFER_IDLE_STRATEGY.reset();
while (publication.offer(ATOMIC_BUFFER, 0, ATOMIC_BUFFER.capacity()) < 0) {
OFFER_IDLE_STRATEGY.idle();
backPressureCount++;
}
}
System.out.println("Done streaming. backPressureRatio=" + ((double) backPressureCount / NUMBER_OF_MESSAGES));
if (0 < LINGER_TIMEOUT_MS) {
System.out.println("Lingering for " + LINGER_TIMEOUT_MS + " milliseconds...");
Thread.sleep(LINGER_TIMEOUT_MS);
}
printingActive = false;
} while (barrier.await());
running.set(false);
reporter.halt();
executor.shutdown();
}
}
use of org.agrona.console.ContinueBarrier in project Aeron by real-logic.
the class EmbeddedPingPong method runPing.
private static void runPing(final String embeddedDirName) throws InterruptedException {
final Aeron.Context ctx = new Aeron.Context().availableImageHandler(EmbeddedPingPong::availablePongImageHandler).aeronDirectoryName(embeddedDirName);
System.out.println("Publishing Ping at " + PING_CHANNEL + " on stream Id " + PING_STREAM_ID);
System.out.println("Subscribing Pong at " + PONG_CHANNEL + " on stream Id " + PONG_STREAM_ID);
System.out.println("Message size of " + MESSAGE_LENGTH + " bytes");
final FragmentAssembler dataHandler = new FragmentAssembler(EmbeddedPingPong::pongHandler);
try (Aeron aeron = Aeron.connect(ctx);
Publication pingPublication = aeron.addPublication(PING_CHANNEL, PING_STREAM_ID);
Subscription pongSubscription = aeron.addSubscription(PONG_CHANNEL, PONG_STREAM_ID)) {
System.out.println("Waiting for new image from Pong...");
PONG_IMAGE_LATCH.await();
System.out.println("Warming up... " + WARMUP_NUMBER_OF_ITERATIONS + " iterations of " + WARMUP_NUMBER_OF_MESSAGES + " messages");
for (int i = 0; i < WARMUP_NUMBER_OF_ITERATIONS; i++) {
roundTripMessages(dataHandler, pingPublication, pongSubscription, WARMUP_NUMBER_OF_MESSAGES);
}
Thread.sleep(100);
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
do {
HISTOGRAM.reset();
System.out.println("Pinging " + NUMBER_OF_MESSAGES + " messages");
roundTripMessages(dataHandler, pingPublication, pongSubscription, NUMBER_OF_MESSAGES);
System.out.println("Histogram of RTT latencies in microseconds.");
HISTOGRAM.outputPercentileDistribution(System.out, 1000.0);
} while (barrier.await());
}
}
use of org.agrona.console.ContinueBarrier in project Aeron by real-logic.
the class Ping method main.
public static void main(final String[] args) throws Exception {
final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
final Aeron.Context ctx = new Aeron.Context().availableImageHandler(Ping::availablePongImageHandler);
final FragmentHandler fragmentHandler = new FragmentAssembler(Ping::pongHandler);
if (EMBEDDED_MEDIA_DRIVER) {
ctx.aeronDirectoryName(driver.aeronDirectoryName());
}
System.out.println("Publishing Ping at " + PING_CHANNEL + " on stream Id " + PING_STREAM_ID);
System.out.println("Subscribing Pong at " + PONG_CHANNEL + " on stream Id " + PONG_STREAM_ID);
System.out.println("Message length of " + MESSAGE_LENGTH + " bytes");
try (Aeron aeron = Aeron.connect(ctx)) {
System.out.println("Warming up... " + WARMUP_NUMBER_OF_ITERATIONS + " iterations of " + WARMUP_NUMBER_OF_MESSAGES + " messages");
try (Publication publication = aeron.addPublication(PING_CHANNEL, PING_STREAM_ID);
Subscription subscription = aeron.addSubscription(PONG_CHANNEL, PONG_STREAM_ID)) {
LATCH.await();
for (int i = 0; i < WARMUP_NUMBER_OF_ITERATIONS; i++) {
roundTripMessages(fragmentHandler, publication, subscription, WARMUP_NUMBER_OF_MESSAGES);
}
Thread.sleep(100);
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
do {
HISTOGRAM.reset();
System.out.println("Pinging " + NUMBER_OF_MESSAGES + " messages");
roundTripMessages(fragmentHandler, publication, subscription, NUMBER_OF_MESSAGES);
System.out.println("Histogram of RTT latencies in microseconds.");
HISTOGRAM.outputPercentileDistribution(System.out, 1000.0);
} while (barrier.await());
}
}
CloseHelper.quietClose(driver);
}
use of org.agrona.console.ContinueBarrier in project Aeron by real-logic.
the class StreamingPublisher method main.
public static void main(final String[] args) throws Exception {
if (MESSAGE_LENGTH < SIZE_OF_LONG) {
throw new IllegalArgumentException(String.format("Message length must be at least %d bytes", SIZE_OF_LONG));
}
final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null;
final Aeron.Context context = new Aeron.Context();
if (EMBEDDED_MEDIA_DRIVER) {
context.aeronDirectoryName(driver.aeronDirectoryName());
}
final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), StreamingPublisher::printRate);
final ExecutorService executor = Executors.newFixedThreadPool(1);
executor.execute(reporter);
// clean up resources when this try block is finished.
try (Aeron aeron = Aeron.connect(context);
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) {
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
do {
printingActive = true;
System.out.format("%nStreaming %,d messages of%s size %d bytes to %s on stream Id %d%n", NUMBER_OF_MESSAGES, (RANDOM_MESSAGE_LENGTH) ? " random" : "", MESSAGE_LENGTH, CHANNEL, STREAM_ID);
long backPressureCount = 0;
for (long i = 0; i < NUMBER_OF_MESSAGES; i++) {
final int length = LENGTH_GENERATOR.getAsInt();
ATOMIC_BUFFER.putLong(0, i);
OFFER_IDLE_STRATEGY.reset();
while (publication.offer(ATOMIC_BUFFER, 0, length) < 0L) {
// The offer failed, which is usually due to the publication
// being temporarily blocked. Retry the offer after a short
// spin/yield/sleep, depending on the chosen IdleStrategy.
backPressureCount++;
OFFER_IDLE_STRATEGY.idle();
}
reporter.onMessage(1, length);
}
System.out.println("Done streaming. Back pressure ratio " + ((double) backPressureCount / NUMBER_OF_MESSAGES));
if (0 < LINGER_TIMEOUT_MS) {
System.out.println("Lingering for " + LINGER_TIMEOUT_MS + " milliseconds...");
Thread.sleep(LINGER_TIMEOUT_MS);
}
printingActive = false;
} while (barrier.await());
}
reporter.halt();
executor.shutdown();
CloseHelper.quietClose(driver);
}
use of org.agrona.console.ContinueBarrier in project Aeron by real-logic.
the class EmbeddedThroughput method main.
public static void main(final String[] args) throws Exception {
MediaDriver.loadPropertiesFiles(args);
final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), EmbeddedThroughput::printRate);
final FragmentHandler rateReporterHandler = rateReporterHandler(reporter);
final ExecutorService executor = Executors.newFixedThreadPool(2);
final Aeron.Context context = new Aeron.Context();
final AtomicBoolean running = new AtomicBoolean(true);
try (MediaDriver ignore = MediaDriver.launch();
Aeron aeron = Aeron.connect(context);
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID);
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
executor.execute(reporter);
executor.execute(() -> SamplesUtil.subscriberLoop(rateReporterHandler, FRAGMENT_COUNT_LIMIT, running).accept(subscription));
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
do {
System.out.format("%nStreaming %,d messages of size %d bytes to %s on stream Id %d%n", NUMBER_OF_MESSAGES, MESSAGE_LENGTH, CHANNEL, STREAM_ID);
printingActive = true;
long backPressureCount = 0;
for (long i = 0; i < NUMBER_OF_MESSAGES; i++) {
ATOMIC_BUFFER.putLong(0, i);
OFFER_IDLE_STRATEGY.reset();
while (publication.offer(ATOMIC_BUFFER, 0, ATOMIC_BUFFER.capacity()) < 0) {
OFFER_IDLE_STRATEGY.idle();
backPressureCount++;
}
}
System.out.println("Done streaming. backPressureRatio=" + ((double) backPressureCount / NUMBER_OF_MESSAGES));
if (0 < LINGER_TIMEOUT_MS) {
System.out.println("Lingering for " + LINGER_TIMEOUT_MS + " milliseconds...");
Thread.sleep(LINGER_TIMEOUT_MS);
}
printingActive = false;
} while (barrier.await());
running.set(false);
reporter.halt();
executor.shutdown();
}
}
Aggregations