use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class EmbeddedExclusiveThroughput method main.
public static void main(final String[] args) throws Exception {
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 AtomicBoolean running = new AtomicBoolean(true);
try (MediaDriver ignore = MediaDriver.launch();
Aeron aeron = Aeron.connect();
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 payload length %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 (LINGER_TIMEOUT_MS > 0) {
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 io.aeron.driver.MediaDriver in project aeron by real-logic.
the class EmbeddedPingPong method main.
public static void main(final String[] args) throws Exception {
loadPropertiesFiles(args);
final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).conductorIdleStrategy(new BackoffIdleStrategy(1, 1, 1, 1)).receiverIdleStrategy(new NoOpIdleStrategy()).senderIdleStrategy(new NoOpIdleStrategy());
try (MediaDriver ignored = MediaDriver.launch(ctx)) {
final Thread pongThread = startPong(ignored.aeronDirectoryName());
pongThread.start();
runPing(ignored.aeronDirectoryName());
RUNNING.set(false);
pongThread.join();
System.out.println("Shutdown Driver...");
}
}
use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class FileReceiver method main.
public static void main(final String[] args) {
final File storageDir;
if (args.length > 1) {
storageDir = new File(args[0]);
if (!storageDir.isDirectory()) {
System.out.println(args[0] + " is not a directory");
System.exit(1);
}
} else {
storageDir = new File(IoUtil.tmpDirName());
}
System.out.println("Files stored to " + storageDir.getAbsolutePath());
final IdleStrategy idleStrategy = new SleepingMillisIdleStrategy(1);
final AtomicBoolean running = new AtomicBoolean(true);
SigInt.register(() -> running.set(false));
try (MediaDriver ignore = MediaDriver.launch();
Aeron aeron = Aeron.connect();
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
System.out.println("Receiving from " + CHANNEL + " on stream Id " + STREAM_ID);
final FileReceiver fileReceiver = new FileReceiver(storageDir, subscription);
while (running.get()) {
idleStrategy.idle(fileReceiver.doWork());
}
}
}
use of io.aeron.driver.MediaDriver in project aeron by real-logic.
the class LowLatencyMediaDriver method main.
public static void main(final String[] args) {
loadPropertiesFiles(args);
final MediaDriver.Context ctx = new MediaDriver.Context().termBufferSparseFile(false).threadingMode(ThreadingMode.DEDICATED).conductorIdleStrategy(new BusySpinIdleStrategy()).receiverIdleStrategy(new BusySpinIdleStrategy()).senderIdleStrategy(new BusySpinIdleStrategy());
try (MediaDriver ignored = MediaDriver.launch(ctx)) {
new ShutdownSignalBarrier().await();
System.out.println("Shutdown Driver...");
}
}
use of io.aeron.driver.MediaDriver 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);
}
Aggregations