Search in sources :

Example 36 with MediaDriver

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

Example 37 with MediaDriver

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...");
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) NoOpIdleStrategy(org.agrona.concurrent.NoOpIdleStrategy) BackoffIdleStrategy(org.agrona.concurrent.BackoffIdleStrategy)

Example 38 with MediaDriver

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

Example 39 with MediaDriver

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...");
    }
}
Also used : ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) MediaDriver(io.aeron.driver.MediaDriver) BusySpinIdleStrategy(org.agrona.concurrent.BusySpinIdleStrategy)

Example 40 with MediaDriver

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);
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) FragmentHandler(io.aeron.logbuffer.FragmentHandler) ContinueBarrier(org.agrona.console.ContinueBarrier)

Aggregations

MediaDriver (io.aeron.driver.MediaDriver)59 Aeron (io.aeron.Aeron)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)22 Subscription (io.aeron.Subscription)13 FragmentHandler (io.aeron.logbuffer.FragmentHandler)11 ContinueBarrier (org.agrona.console.ContinueBarrier)11 Test (org.junit.jupiter.api.Test)10 Publication (io.aeron.Publication)9 IdleStrategy (org.agrona.concurrent.IdleStrategy)9 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)9 InterruptAfter (io.aeron.test.InterruptAfter)8 ExecutorService (java.util.concurrent.ExecutorService)8 BusySpinIdleStrategy (org.agrona.concurrent.BusySpinIdleStrategy)8 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)7 Archive (io.aeron.archive.Archive)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Tests (io.aeron.test.Tests)5 DirectBuffer (org.agrona.DirectBuffer)5 CommonContext (io.aeron.CommonContext)4 File (java.io.File)4