Search in sources :

Example 46 with MediaDriver

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver) IdleStrategy(org.agrona.concurrent.IdleStrategy) ExecutorService(java.util.concurrent.ExecutorService) ConcurrentPublication(io.aeron.ConcurrentPublication) Publication(io.aeron.Publication) ContinueBarrier(org.agrona.console.ContinueBarrier) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron)

Example 47 with MediaDriver

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver)

Example 48 with MediaDriver

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();
    }
}
Also used : CommonContext(io.aeron.CommonContext) IdleStrategy(org.agrona.concurrent.IdleStrategy) ContinueBarrier(org.agrona.console.ContinueBarrier) ExclusivePublication(io.aeron.ExclusivePublication) Aeron(io.aeron.Aeron) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver) ExecutorService(java.util.concurrent.ExecutorService) Subscription(io.aeron.Subscription)

Example 49 with MediaDriver

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaDriver(io.aeron.driver.MediaDriver)

Example 50 with MediaDriver

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...");
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) Aeron(io.aeron.Aeron)

Aggregations

MediaDriver (io.aeron.driver.MediaDriver)78 Aeron (io.aeron.Aeron)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 Test (org.junit.jupiter.api.Test)20 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)17 InterruptAfter (io.aeron.test.InterruptAfter)16 Subscription (io.aeron.Subscription)14 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)14 IdleStrategy (org.agrona.concurrent.IdleStrategy)14 ContinueBarrier (org.agrona.console.ContinueBarrier)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Publication (io.aeron.Publication)10 Archive (io.aeron.archive.Archive)10 FragmentHandler (io.aeron.logbuffer.FragmentHandler)10 Tests (io.aeron.test.Tests)10 CommonContext (io.aeron.CommonContext)8 ExecutorService (java.util.concurrent.ExecutorService)8 DirectBuffer (org.agrona.DirectBuffer)7 BusySpinIdleStrategy (org.agrona.concurrent.BusySpinIdleStrategy)7 AeronCluster (io.aeron.cluster.client.AeronCluster)6