org.agrona.concurrent.BusySpinIdleStrategy Java Examples
The following examples show how to use
org.agrona.concurrent.BusySpinIdleStrategy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LowLatencyMediaDriver.java From rpc-bench with Apache License 2.0 | 6 votes |
@SuppressWarnings("checkstyle:UncommentedMain") public static void main(final String... args) { MediaDriver.loadPropertiesFiles(args); setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true"); setProperty("aeron.mtu.length", "16384"); setProperty("aeron.socket.so_sndbuf", "2097152"); setProperty("aeron.socket.so_rcvbuf", "2097152"); setProperty("aeron.rcv.initial.window.length", "2097152"); final MediaDriver.Context ctx = new MediaDriver.Context() .threadingMode(ThreadingMode.DEDICATED) .dirsDeleteOnStart(true) .termBufferSparseFile(false) .conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); try (MediaDriver ignored = MediaDriver.launch(ctx)) { new SigIntBarrier().await(); } }
Example #2
Source File: LowResourceEngineSchedulerTest.java From artio with Apache License 2.0 | 6 votes |
@Test public void shouldPrintErrorIfRepeatedlyThrown() throws Exception { when(configuration.framerIdleStrategy()).thenReturn(new BusySpinIdleStrategy()); when(configuration.threadFactory()).thenReturn(Thread::new); when(framer.doWork()).thenThrow(IOException.class); try (EngineScheduler scheduler = new LowResourceEngineScheduler()) { scheduler.launch( configuration, mockErrorHandler, framer, archivingAgent, monitoringAgent, conductorAgent, recordingCoordinator); assertEventuallyTrue( "Failed to invoke monitoring agent", () -> verify(monitoringAgent, atLeastOnce()).doWork() ); } }
Example #3
Source File: LowLatencyMediaDriver.java From deeplearning4j with Apache License 2.0 | 6 votes |
@SuppressWarnings("checkstyle:UncommentedMain") public static void main(final String... args) { MediaDriver.loadPropertiesFiles(args); setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true"); setProperty("aeron.mtu.length", "16384"); setProperty("aeron.socket.so_sndbuf", "2097152"); setProperty("aeron.socket.so_rcvbuf", "2097152"); setProperty("aeron.rcv.initial.window.length", "2097152"); final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); try (MediaDriver ignored = MediaDriver.launch(ctx)) { new SigIntBarrier().await(); } }
Example #4
Source File: AeronUtil.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * Get a media driver context * for sending ndarrays * based on a given length * where length is the length (number of elements) * in the ndarrays hat are being sent * @param length the length to based the ipc length * @return the media driver context based on the given length */ public static MediaDriver.Context getMediaDriverContext(int length) { //length of array * sizeof(float) int ipcLength = length * 16; //padding for NDArrayMessage ipcLength += 64; //must be a power of 2 ipcLength *= 2; //ipc length must be positive power of 2 while (!BitUtil.isPowerOfTwo(ipcLength)) ipcLength += 2; // System.setProperty("aeron.term.buffer.size",String.valueOf(ipcLength)); final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true) /* .ipcTermBufferLength(ipcLength) .publicationTermBufferLength(ipcLength) .maxTermBufferLength(ipcLength)*/ .conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); return ctx; }
Example #5
Source File: AeronExclusiveIpcBenchmark.java From benchmarks with Apache License 2.0 | 6 votes |
public void run() { while (!subscription.isConnected()) { Thread.yield(); } final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); while (true) { final int frameCount = subscription.poll(this, FRAGMENT_LIMIT); if (0 == frameCount) { if (!running.get()) { break; } } idleStrategy.idle(frameCount); } }
Example #6
Source File: AeronIpcBenchmark.java From benchmarks with Apache License 2.0 | 6 votes |
public void run() { while (!subscription.isConnected()) { Thread.yield(); } final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); while (true) { final int frameCount = subscription.poll(this, FRAGMENT_LIMIT); if (0 == frameCount) { if (!running.get()) { break; } } idleStrategy.idle(frameCount); } }
Example #7
Source File: LowLatencyMediaDriver.java From nd4j with Apache License 2.0 | 6 votes |
@SuppressWarnings("checkstyle:UncommentedMain") public static void main(final String... args) { MediaDriver.loadPropertiesFiles(args); setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true"); setProperty("aeron.mtu.length", "16384"); setProperty("aeron.socket.so_sndbuf", "2097152"); setProperty("aeron.socket.so_rcvbuf", "2097152"); setProperty("aeron.rcv.initial.window.length", "2097152"); final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); try (MediaDriver ignored = MediaDriver.launch(ctx)) { new SigIntBarrier().await(); } }
Example #8
Source File: LowLatencyMediaDriver.java From aeron with Apache License 2.0 | 6 votes |
public static void main(final String[] args) { loadPropertiesFiles(args); final MediaDriver.Context ctx = new MediaDriver.Context() .termBufferSparseFile(false) .useWindowsHighResTimer(true) .threadingMode(ThreadingMode.DEDICATED) .conductorIdleStrategy(BusySpinIdleStrategy.INSTANCE) .receiverIdleStrategy(NoOpIdleStrategy.INSTANCE) .senderIdleStrategy(NoOpIdleStrategy.INSTANCE); try (MediaDriver ignored = MediaDriver.launch(ctx)) { new ShutdownSignalBarrier().await(); System.out.println("Shutdown Driver..."); } }
Example #9
Source File: AeronUtil.java From nd4j with Apache License 2.0 | 6 votes |
/** * Get a media driver context * for sending ndarrays * based on a given length * where length is the length (number of elements) * in the ndarrays hat are being sent * @param length the length to based the ipc length * @return the media driver context based on the given length */ public static MediaDriver.Context getMediaDriverContext(int length) { //length of array * sizeof(float) int ipcLength = length * 16; //padding for NDArrayMessage ipcLength += 64; //must be a power of 2 ipcLength *= 2; //ipc length must be positive power of 2 while (!BitUtil.isPowerOfTwo(ipcLength)) ipcLength += 2; // System.setProperty("aeron.term.buffer.size",String.valueOf(ipcLength)); final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true) /* .ipcTermBufferLength(ipcLength) .publicationTermBufferLength(ipcLength) .maxTermBufferLength(ipcLength)*/ .conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); return ctx; }
Example #10
Source File: AeronNDArrayResponseTest.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Before public void before() { if(isIntegrationTests()) { final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); mediaDriver = MediaDriver.launchEmbedded(ctx); System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName()); System.out.println("Launched media driver"); } }
Example #11
Source File: AeronNDArrayResponseTest.java From nd4j with Apache License 2.0 | 5 votes |
@Before public void before() { final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); mediaDriver = MediaDriver.launchEmbedded(ctx); System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName()); System.out.println("Launched media driver"); }
Example #12
Source File: AeronIpcBenchmark.java From benchmarks with Apache License 2.0 | 5 votes |
@Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) { responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY); } values = new int[burstLength]; for (int i = 0; i < burstLength; i++) { values[i] = -(burstLength - i); } ctx = new MediaDriver.Context() .termBufferSparseFile(false) .threadingMode(ThreadingMode.SHARED) .sharedIdleStrategy(new BusySpinIdleStrategy()) .dirDeleteOnStart(true); mediaDriver = MediaDriver.launch(ctx); aeron = Aeron.connect(new Aeron.Context().preTouchMappedMemory(true)); publication = aeron.addPublication(CommonContext.IPC_CHANNEL, STREAM_ID); subscription = aeron.addSubscription(CommonContext.IPC_CHANNEL, STREAM_ID); consumerThread = new Thread(new Subscriber(subscription, running, responseQueues)); consumerThread.setName("consumer"); consumerThread.start(); }
Example #13
Source File: AeronExclusiveIpcBenchmark.java From benchmarks with Apache License 2.0 | 5 votes |
@Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) { responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY); } values = new int[burstLength]; for (int i = 0; i < burstLength; i++) { values[i] = -(burstLength - i); } ctx = new MediaDriver.Context() .termBufferSparseFile(false) .threadingMode(ThreadingMode.SHARED) .sharedIdleStrategy(new BusySpinIdleStrategy()) .dirDeleteOnStart(true); mediaDriver = MediaDriver.launch(ctx); aeron = Aeron.connect(new Aeron.Context().preTouchMappedMemory(true)); publication = aeron.addExclusivePublication(CommonContext.IPC_CHANNEL, STREAM_ID); subscription = aeron.addSubscription(CommonContext.IPC_CHANNEL, STREAM_ID); consumerThread = new Thread(new Subscriber(subscription, running, responseQueues)); consumerThread.setName("consumer"); consumerThread.start(); }
Example #14
Source File: ConfigurationTest.java From benchmarks with Apache License 2.0 | 5 votes |
@Test void fromSystemPropertiesOverrideAll(final @TempDir Path tempDir) { setProperty(WARM_UP_ITERATIONS_PROP_NAME, "2"); setProperty(ITERATIONS_PROP_NAME, "4"); setProperty(MESSAGES_PROP_NAME, "200"); setProperty(BATCH_SIZE_PROP_NAME, "3"); setProperty(MESSAGE_LENGTH_PROP_NAME, "24"); setProperty(MESSAGE_TRANSCEIVER_PROP_NAME, InMemoryMessageTransceiver.class.getName()); setProperty(SEND_IDLE_STRATEGY_PROP_NAME, YieldingIdleStrategy.class.getName()); setProperty(RECEIVE_IDLE_STRATEGY_PROP_NAME, BusySpinIdleStrategy.class.getName()); final Path outputDirectory = tempDir.resolve("my-output-dir-prop"); setProperty(OUTPUT_DIRECTORY_PROP_NAME, outputDirectory.toAbsolutePath().toString()); setProperty(OUTPUT_FILE_NAME_PREFIX_PROP_NAME, "my-out-file"); final Configuration configuration = fromSystemProperties(); assertEquals(2, configuration.warmUpIterations()); assertEquals(4, configuration.iterations()); assertEquals(200, configuration.numberOfMessages()); assertEquals(3, configuration.batchSize()); assertEquals(24, configuration.messageLength()); assertSame(InMemoryMessageTransceiver.class, configuration.messageTransceiverClass()); assertTrue(configuration.sendIdleStrategy() instanceof YieldingIdleStrategy); assertTrue(configuration.receiveIdleStrategy() instanceof BusySpinIdleStrategy); assertEquals(outputDirectory.toAbsolutePath(), configuration.outputDirectory()); assertTrue(configuration.outputFileNamePrefix().startsWith("my-out-file")); }
Example #15
Source File: ParameterServerClientPartialTest.java From nd4j with Apache License 2.0 | 4 votes |
@BeforeClass public static void before() throws Exception { final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); mediaDriver = MediaDriver.launchEmbedded(ctx); aeron = Aeron.connect(getContext()); masterNode = new ParameterServerSubscriber(mediaDriver); masterNode.setAeron(aeron); int masterPort = 40223 + new java.util.Random().nextInt(13000); int masterStatusPort = masterPort - 2000; masterNode.run(new String[] {"-m", "true", "-p", String.valueOf(masterPort), "-h", "localhost", "-id", "11", "-md", mediaDriver.aeronDirectoryName(), "-sp", String.valueOf(masterStatusPort), "-s", "2,2", "-u", String.valueOf(1) }); assertTrue(masterNode.isMaster()); assertEquals(masterPort, masterNode.getPort()); assertEquals("localhost", masterNode.getHost()); assertEquals(11, masterNode.getStreamId()); assertEquals(12, masterNode.getResponder().getStreamId()); assertEquals(masterNode.getMasterArray(), Nd4j.create(new int[] {2, 2})); slaveNode = new ParameterServerSubscriber(mediaDriver); slaveNode.setAeron(aeron); int slavePort = masterPort + 100; int slaveStatusPort = slavePort - 2000; slaveNode.run(new String[] {"-p", String.valueOf(slavePort), "-h", "localhost", "-id", "10", "-pm", masterNode.getSubscriber().connectionUrl(), "-md", mediaDriver.aeronDirectoryName(), "-sp", String.valueOf(slaveStatusPort), "-u", String.valueOf(1) }); assertFalse(slaveNode.isMaster()); assertEquals(slavePort, slaveNode.getPort()); assertEquals("localhost", slaveNode.getHost()); assertEquals(10, slaveNode.getStreamId()); int tries = 10; while (!masterNode.subscriberLaunched() && !slaveNode.subscriberLaunched() && tries < 10) { Thread.sleep(10000); tries++; } if (!masterNode.subscriberLaunched() && !slaveNode.subscriberLaunched()) { throw new IllegalStateException("Failed to start master and slave node"); } log.info("Using media driver directory " + mediaDriver.aeronDirectoryName()); log.info("Launched media driver"); }
Example #16
Source File: Pong.java From aeron with Apache License 2.0 | 4 votes |
public static void main(final String[] args) { final MediaDriver driver = EMBEDDED_MEDIA_DRIVER ? MediaDriver.launchEmbedded() : null; final Aeron.Context ctx = new Aeron.Context(); if (EMBEDDED_MEDIA_DRIVER) { ctx.aeronDirectoryName(driver.aeronDirectoryName()); } if (INFO_FLAG) { ctx.availableImageHandler(SamplesUtil::printAvailableImage); ctx.unavailableImageHandler(SamplesUtil::printUnavailableImage); } final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); System.out.println("Subscribing Ping at " + PING_CHANNEL + " on stream id " + PING_STREAM_ID); System.out.println("Publishing Pong at " + PONG_CHANNEL + " on stream id " + PONG_STREAM_ID); System.out.println("Using exclusive publications " + EXCLUSIVE_PUBLICATIONS); final AtomicBoolean running = new AtomicBoolean(true); SigInt.register(() -> running.set(false)); try (Aeron aeron = Aeron.connect(ctx); Subscription subscription = aeron.addSubscription(PING_CHANNEL, PING_STREAM_ID); Publication publication = EXCLUSIVE_PUBLICATIONS ? aeron.addExclusivePublication(PONG_CHANNEL, PONG_STREAM_ID) : aeron.addPublication(PONG_CHANNEL, PONG_STREAM_ID)) { final BufferClaim bufferClaim = new BufferClaim(); final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> pingHandler(bufferClaim, publication, buffer, offset, length, header); while (running.get()) { idleStrategy.idle(subscription.poll(fragmentHandler, FRAME_COUNT_LIMIT)); } System.out.println("Shutting down..."); } CloseHelper.quietClose(driver); }
Example #17
Source File: ParameterServerClientPartialTest.java From deeplearning4j with Apache License 2.0 | 4 votes |
@BeforeClass public static void beforeClass() throws Exception { final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true) .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy()) .receiverIdleStrategy(new BusySpinIdleStrategy()) .senderIdleStrategy(new BusySpinIdleStrategy()); mediaDriver = MediaDriver.launchEmbedded(ctx); aeron = Aeron.connect(getContext()); masterNode = new ParameterServerSubscriber(mediaDriver); masterNode.setAeron(aeron); int masterPort = 40223 + new java.util.Random().nextInt(13000); int masterStatusPort = masterPort - 2000; masterNode.run(new String[] {"-m", "true", "-p", String.valueOf(masterPort), "-h", "localhost", "-id", "11", "-md", mediaDriver.aeronDirectoryName(), "-sp", String.valueOf(masterStatusPort), "-s", "2,2", "-u", String.valueOf(1) }); assertTrue(masterNode.isMaster()); assertEquals(masterPort, masterNode.getPort()); assertEquals("localhost", masterNode.getHost()); assertEquals(11, masterNode.getStreamId()); assertEquals(12, masterNode.getResponder().getStreamId()); assertEquals(masterNode.getMasterArray(), Nd4j.create(new int[] {2, 2})); slaveNode = new ParameterServerSubscriber(mediaDriver); slaveNode.setAeron(aeron); int slavePort = masterPort + 100; int slaveStatusPort = slavePort - 2000; slaveNode.run(new String[] {"-p", String.valueOf(slavePort), "-h", "localhost", "-id", "10", "-pm", masterNode.getSubscriber().connectionUrl(), "-md", mediaDriver.aeronDirectoryName(), "-sp", String.valueOf(slaveStatusPort), "-u", String.valueOf(1) }); assertFalse(slaveNode.isMaster()); assertEquals(slavePort, slaveNode.getPort()); assertEquals("localhost", slaveNode.getHost()); assertEquals(10, slaveNode.getStreamId()); int tries = 10; while (!masterNode.subscriberLaunched() && !slaveNode.subscriberLaunched() && tries < 10) { Thread.sleep(10000); tries++; } if (!masterNode.subscriberLaunched() && !slaveNode.subscriberLaunched()) { throw new IllegalStateException("Failed to start master and slave node"); } log.info("Using media driver directory " + mediaDriver.aeronDirectoryName()); log.info("Launched media driver"); }
Example #18
Source File: BenchServer.java From rpc-bench with Apache License 2.0 | 4 votes |
private void execute() { final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); while (running.get()) { idleStrategy.idle(subscription.poll(fragmentHandler, FRAGMENT_LIMIT)); } }
Example #19
Source File: AeronUtil.java From nd4j with Apache License 2.0 | 2 votes |
/** * Return a reusable, parametrized * event loop that calls a * default idler * when no messages are received * * @param fragmentHandler to be called back for each message. * @param limit passed to {@link Subscription#poll(FragmentHandler, int)} * @param running indication for loop * @return loop function */ public static Consumer<Subscription> subscriberLoop(final FragmentHandler fragmentHandler, final int limit, final AtomicBoolean running, final AtomicBoolean launched) { final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); return subscriberLoop(fragmentHandler, limit, running, idleStrategy, launched); }
Example #20
Source File: AeronUtil.java From deeplearning4j with Apache License 2.0 | 2 votes |
/** * Return a reusable, parametrized * event loop that calls a * default idler * when no messages are received * * @param fragmentHandler to be called back for each message. * @param limit passed to {@link Subscription#poll(FragmentHandler, int)} * @param running indication for loop * @return loop function */ public static Consumer<Subscription> subscriberLoop(final FragmentHandler fragmentHandler, final int limit, final AtomicBoolean running, final AtomicBoolean launched) { final IdleStrategy idleStrategy = new BusySpinIdleStrategy(); return subscriberLoop(fragmentHandler, limit, running, idleStrategy, launched); }