use of io.aeron.driver.MediaDriver in project Aeron by real-logic.
the class EmbeddedThroughput method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
* @throws InterruptedException if the thread is interrupted during linger.
*/
public static void main(final String[] args) throws InterruptedException {
loadPropertiesFiles(args);
final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), EmbeddedThroughput::printRate);
final ExecutorService executor = Executors.newFixedThreadPool(2);
final AtomicBoolean running = new AtomicBoolean(true);
try (MediaDriver mediaDriver = MediaDriver.launch();
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) {
executor.execute(reporter);
executor.execute(() -> SamplesUtil.subscriberLoop(rateReporterHandler(reporter), FRAGMENT_COUNT_LIMIT, running).accept(subscription));
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
final IdleStrategy idleStrategy = SampleConfiguration.newIdleStrategy();
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++) {
OFFER_BUFFER.putLong(0, i);
idleStrategy.reset();
while (publication.offer(OFFER_BUFFER, 0, MESSAGE_LENGTH, null) < 0) {
backPressureCount++;
idleStrategy.idle();
}
}
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 EmbeddedExclusiveBufferClaimIpcThroughput method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
* @throws InterruptedException if the join on the created threads is interrupted.
*/
public static void main(final String[] args) throws InterruptedException {
loadPropertiesFiles(args);
final AtomicBoolean running = new AtomicBoolean(true);
SigInt.register(() -> running.set(false));
final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED);
try (MediaDriver mediaDriver = MediaDriver.launch(ctx);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
Publication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) {
final ImageRateSubscriber subscriber = new ImageRateSubscriber(FRAGMENT_COUNT_LIMIT, running, subscription);
final Thread subscriberThread = new Thread(subscriber);
subscriberThread.setName("subscriber");
final Thread publisherThread = new Thread(new Publisher(running, publication));
publisherThread.setName("publisher");
final Thread rateReporterThread = new Thread(new ImageRateReporter(MESSAGE_LENGTH, running, subscriber));
rateReporterThread.setName("rate-reporter");
rateReporterThread.start();
subscriberThread.start();
publisherThread.start();
subscriberThread.join();
publisherThread.join();
rateReporterThread.join();
}
}
use of io.aeron.driver.MediaDriver in project Aeron by real-logic.
the class EmbeddedExclusiveSpiedThroughput method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
* @throws InterruptedException if interrupted during linger.
*/
public static void main(final String[] args) throws InterruptedException {
loadPropertiesFiles(args);
final RateReporter reporter = new RateReporter(TimeUnit.SECONDS.toNanos(1), EmbeddedExclusiveSpiedThroughput::printRate);
final ExecutorService executor = Executors.newFixedThreadPool(2);
final AtomicBoolean running = new AtomicBoolean(true);
final MediaDriver.Context ctx = new MediaDriver.Context().spiesSimulateConnection(true);
try (MediaDriver mediaDriver = MediaDriver.launch(ctx);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(CommonContext.SPY_PREFIX + CHANNEL, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) {
executor.execute(reporter);
executor.execute(() -> SamplesUtil.subscriberLoop(rateReporterHandler(reporter), FRAGMENT_COUNT_LIMIT, running).accept(subscription));
final ContinueBarrier barrier = new ContinueBarrier("Execute again?");
final IdleStrategy idleStrategy = SampleConfiguration.newIdleStrategy();
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++) {
OFFER_BUFFER.putLong(0, i);
idleStrategy.reset();
while (publication.offer(OFFER_BUFFER, 0, MESSAGE_LENGTH, null) < 0) {
backPressureCount++;
idleStrategy.idle();
}
}
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 EmbeddedExclusiveVectoredIpcThroughput method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
* @throws InterruptedException if the thread is interrupted while waiting on the threads to join.
*/
public static void main(final String[] args) throws InterruptedException {
loadPropertiesFiles(args);
final AtomicBoolean running = new AtomicBoolean(true);
SigInt.register(() -> running.set(false));
final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED);
try (MediaDriver mediaDriver = MediaDriver.launch(ctx);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID)) {
final ImageRateSubscriber subscriber = new ImageRateSubscriber(FRAGMENT_COUNT_LIMIT, running, subscription);
final Thread subscriberThread = new Thread(subscriber);
subscriberThread.setName("subscriber");
final Thread publisherThread = new Thread(new Publisher(running, publication));
publisherThread.setName("publisher");
final Thread rateReporterThread = new Thread(new ImageRateReporter(MESSAGE_LENGTH, running, subscriber));
rateReporterThread.setName("rate-reporter");
rateReporterThread.start();
subscriberThread.start();
publisherThread.start();
subscriberThread.join();
publisherThread.join();
rateReporterThread.join();
}
}
use of io.aeron.driver.MediaDriver in project Aeron by real-logic.
the class EmbeddedPingPong method main.
/**
* Main method for launching the process.
*
* @param args passed to the process.
* @throws InterruptedException if the thread is interrupted.
*/
public static void main(final String[] args) throws InterruptedException {
loadPropertiesFiles(args);
final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).conductorIdleStrategy(new BackoffIdleStrategy(1, 1, 1000, 1000)).receiverIdleStrategy(NoOpIdleStrategy.INSTANCE).senderIdleStrategy(NoOpIdleStrategy.INSTANCE);
try (MediaDriver mediaDriver = MediaDriver.launch(ctx);
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()))) {
final Thread pongThread = startPong(aeron);
pongThread.start();
runPing(aeron);
RUNNING.set(false);
pongThread.join();
System.out.println("Shutdown Driver...");
}
}
Aggregations