예제 #1
0
        public Channel(ChannelOptions options, ushort channelNumber, ConnectionIO connectionIo, CancellationToken cancellationToken)
        {
            _options = options;

            _schedulerToDeliverMessages = (options != null ? options.Scheduler : null) ?? TaskScheduler.Default;

            _cancellationToken = cancellationToken;
            _io = new ChannelIO(this, channelNumber, connectionIo)
            {
                ErrorCallbacks = _errorsCallbacks
            };

            _consumerSubscriptions = new ConcurrentDictionary <string, BasicConsumerSubscriptionInfo>(StringComparer.Ordinal);

            _propertiesPool = new ObjectPoolArray <BasicProperties>(() => new BasicProperties(isFrozen: false, reusable: true), 100, preInitialize: false);
        }
예제 #2
0
        public ConnectionIO(Connection connection) : base(channelNum: 0)
        {
            _conn         = connection;
            _socketHolder = new SocketHolder();

            _commandOutboxEvent = new AutoResetEvent(false);
            _waitingServerReply = new ManualResetEventSlim(true);
            // _commandOutboxEvent = new AutoResetSuperSlimLock(false);
            _commandOutbox = new ConcurrentQueue <CommandToSend>();

            _cmdToSendObjPool = new ObjectPoolArray <CommandToSend>(() => new CommandToSend(i => _cmdToSendObjPool.PutObject(i)), 200, true);

            _amqpWriter  = new AmqpPrimitivesWriter();
            _amqpReader  = new AmqpPrimitivesReader();
            _frameReader = new FrameReader();
        }
예제 #3
0
        public void ComparePoolsPerformance()
        {
            int capacity  = Environment.ProcessorCount * 2;
            var arrayPool = new ObjectPoolArray <DummyPoolable>(capacity);
            var bagPool   = new ObjectPoolBag <DummyPoolable>(capacity);
            var queuePool = new ObjectPoolQueue <DummyPoolable>(capacity);

            //var mpmcQueuePool = new ObjectPoolMPMCQueue<DummyPoolable>(capacity);
            for (int round = 0; round < 10; round++)
            {
                TestPool(arrayPool);
                TestPool(bagPool);
                TestPool(queuePool);
                //TestPool(mpmcQueuePool);
                Console.WriteLine("----------");
            }
        }
예제 #4
0
        public void ConsistencyCheck(int howManyThreads, int poolSize)
        {
            var iterations = 100000;

            _pool = new ObjectPoolArray <FakeRecycleableObj>(
                () => new FakeRecycleableObj(i => _pool.PutObject(i)),
                poolSize, preInitialize: true, ignoreDispose: false);

            var countDown = new CountdownEvent(howManyThreads);
            var hasError  = false;

            for (int i = 0; i < howManyThreads; i++)
            {
                ThreadFactory.BackgroundThread(() =>
                {
                    try
                    {
                        for (int j = 0; j < iterations; j++)
                        {
                            var obj = _pool.GetObject();
                            if (i % 20 == 0)
                            {
                                Thread.Sleep(_rnd.Next(1, 3));                // some entropy
                            }
                            obj.Use("something");                             // Use will recycle itself
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                        hasError = true;
                    }
                    finally
                    {
                        countDown.Signal();
                    }
                }, "Test_" + i);
            }

            countDown.Wait();

            _pool.DumpDiagnostics();

            Assert.False(hasError, "Not expecting to have error(s)");
        }
예제 #5
0
 internal void GenericRecycler <T>(T item, ObjectPoolArray <T> pool) where T : class
 {
     pool.PutObject(item);
 }
예제 #6
0
 public Program()
 {
     _objectPool      = new ObjectPool <FakeItem>(() => new FakeItem(), 100, true);
     _objectPoolArray = new ObjectPoolArray <FakeItem>(() => new FakeItem(), 100, true);
 }