예제 #1
0
        public static void Main()
        {
            ComputerSpecifications.Dump();

            var running = new AtomicBoolean(true);

            using (var aeron = Aeron.Connect())
                using (var publication = aeron.AddExclusivePublication(Channel, StreamID))
                    using (var subscription = aeron.AddSubscription(Channel, StreamID))
                    {
                        var subscriber       = new Subscriber(running, subscription);
                        var subscriberThread = new Thread(subscriber.Run)
                        {
                            Name = "subscriber"
                        };
                        var publisherThread = new Thread(new Publisher(running, publication).Run)
                        {
                            Name = "publisher"
                        };
                        var rateReporterThread = new Thread(new RateReporter(running, subscriber).Run)
                        {
                            Name = "rate-reporter"
                        };

                        rateReporterThread.Start();
                        subscriberThread.Start();
                        publisherThread.Start();

                        Console.WriteLine("Press any key to stop...");
                        Console.Read();

                        running.Set(false);

                        subscriberThread.Join();
                        publisherThread.Join();
                        rateReporterThread.Join();
                    }
        }
예제 #2
0
        public static void Main()
        {
            ComputerSpecifications.Dump();


            var reporter            = new RateReporter(1000, PrintRate);
            var rateReporterHandler = SamplesUtil.RateReporterHandler(reporter);
            var context             = new Aeron.Context();

            var running = new AtomicBoolean(true);

            var reportThread    = new Thread(reporter.Run);
            var subscribeThread = new Thread(subscription => SamplesUtil.SubscriberLoop(rateReporterHandler, FragmentCountLimit, running)((Subscription)subscription));

            using (var aeron = Aeron.Connect(context))
                using (var publication = aeron.AddPublication(Channel, StreamID))
                    using (var subscription = aeron.AddSubscription(Channel, StreamID))
                        using (var byteBuffer = BufferUtil.AllocateDirectAligned(MessageLength, BitUtil.CACHE_LINE_LENGTH))
                            using (var buffer = new UnsafeBuffer(byteBuffer))
                            {
                                reportThread.Start();
                                subscribeThread.Start(subscription);

                                do
                                {
                                    Console.WriteLine("Streaming {0:G} messages of size {1:G} bytes to {2} on stream Id {3}", NumberOfMessages, MessageLength, Channel, StreamID);

                                    _printingActive = true;

                                    long backPressureCount = 0;
                                    for (long i = 0; i < NumberOfMessages; i++)
                                    {
                                        buffer.PutLong(0, i);

                                        OfferIdleStrategy.Reset();
                                        while (publication.Offer(buffer, 0, buffer.Capacity) < 0)
                                        {
                                            OfferIdleStrategy.Idle();
                                            backPressureCount++;
                                        }
                                    }

                                    Console.WriteLine("Done streaming. backPressureRatio=" + (double)backPressureCount / NumberOfMessages);

                                    if (0 < LingerTimeoutMs)
                                    {
                                        Console.WriteLine("Lingering for " + LingerTimeoutMs + " milliseconds...");
                                        Thread.Sleep((int)LingerTimeoutMs);
                                    }

                                    _printingActive = false;
                                } while (Console.ReadLine() != "x");

                                reporter.Halt();
                                running.Set(false);

                                if (!subscribeThread.Join(5000))
                                {
                                    Console.WriteLine("Warning: not all tasks completed promptly");
                                }
                            }
        }
예제 #3
0
        public void MemoryIsNonZero()
        {
            var c = new ComputerSpecifications();

            Assert.NotZero(c.MemoryMBytes);
        }
예제 #4
0
 public void CallingDumpWorks()
 {
     ComputerSpecifications.Dump();
 }
예제 #5
0
        public static void Main()
        {
            if (MessageLength < BitUtil.SIZE_OF_LONG)
            {
                throw new ArgumentException($"Message length must be at least {BitUtil.SIZE_OF_LONG:D} bytes");
            }

            ComputerSpecifications.Dump();

            var context  = new Aeron.Context();
            var reporter = new RateReporter(1000, PrintRate);

            _reporterThread = new Thread(_ => reporter.Run());
            _reporterThread.Start();

            // Connect to media driver and add publication to send messages on the configured channel and stream ID.
            // The Aeron and Publication classes implement AutoCloseable, and will automatically
            // clean up resources when this try block is finished.
            using (var aeron = Aeron.Connect(context))
                using (var publication = aeron.AddPublication(Channel, StreamID))
                    using (var byteBuffer = BufferUtil.AllocateDirectAligned(MessageLength, BitUtil.CACHE_LINE_LENGTH))
                        using (var buffer = new UnsafeBuffer(byteBuffer))
                        {
                            do
                            {
                                _printingActive = true;

                                Console.WriteLine($"Streaming {NumberOfMessages} messages of {(RandomMessageLength ? " random" : "")} size {MessageLength} bytes to {Channel} on stream Id {StreamID}");

                                long backPressureCount = 0;

                                for (long i = 0; i < NumberOfMessages; i++)
                                {
                                    var length = LengthGenerator.AsInt;

                                    buffer.PutLong(0, i);
                                    OfferIdleStrategy.Reset();
                                    while (publication.Offer(buffer, 0, length) < 0L)
                                    {
                                        // The offer failed, which is usually due to the publication
                                        // being temporarily blocked.  Retry the offer after a short
                                        // spin/yield/sleep, depending on the chosen IdleStrategy.
                                        backPressureCount++;
                                        OfferIdleStrategy.Idle();
                                    }

                                    reporter.OnMessage(1, length);
                                }

                                Console.WriteLine("Done streaming. Back pressure ratio " + (double)backPressureCount / NumberOfMessages);

                                if (0 < LingerTimeoutMs)
                                {
                                    Console.WriteLine("Lingering for " + LingerTimeoutMs + " milliseconds...");
                                    Thread.Sleep((int)LingerTimeoutMs);
                                }

                                _printingActive = false;

                                Console.WriteLine("Execute again?");
                            } while (Console.ReadLine() == "y");
                        }

            reporter.Halt();
            _reporterThread.Join();
        }