Ejemplo n.º 1
0
        private double processRate(int size, string queue)
        {
            CircularBuffer <IMessage> buffer   = new CircularBuffer <IMessage>(100);
            IMessageListener          listener = new SyncListener(buffer);
            string localQueue = "queue-" + UUID.RandomUuid();

            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", queue);
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            double   rate  = 0;
            RangeSet range = new RangeSet();

            for (int i = 0; i < size; ++i)
            {
                IMessage m = buffer.Dequeue();
                range.Add(m.Id);
                BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
                byte[]       body   = new byte[m.Body.Length - m.Body.Position];
                reader.Read(body, 0, body.Length);
                rate += BitConverter.ToDouble(body, 0);
            }
            Session.MessageAccept(range);
            return(rate);
        }
Ejemplo n.º 2
0
        private void process(int size, string queue)
        {
            CircularBuffer <IMessage> buffer   = new CircularBuffer <IMessage>(100);
            IMessageListener          listener = new SyncListener(buffer);
            string localQueue = "queue-" + UUID.RandomUuid();

            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", queue);
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            for (int i = 0; i < size; ++i)
            {
                buffer.Dequeue();
            }
        }
Ejemplo n.º 3
0
 private double processRate(int size, string queue)
 {
     CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
     IMessageListener listener = new SyncListener(buffer);
     string localQueue = "queue-" + UUID.RandomUuid();
     Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
     Session.ExchangeBind(localQueue, "amq.direct", queue);
     Session.AttachMessageListener(listener, localQueue);
     Session.MessageSubscribe(localQueue);
     double rate = 0;
     RangeSet range = new RangeSet();
     for (int i = 0; i < size; ++i)
     {
         IMessage m = buffer.Dequeue();
         range.Add(m.Id);
         BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
         byte[] body = new byte[m.Body.Length - m.Body.Position];
         reader.Read(body, 0, body.Length);
         rate += BitConverter.ToDouble(body,0);
     }
     Session.MessageAccept(range);
     return rate;
 }
Ejemplo n.º 4
0
 private void process(int size, string queue)
 {
     CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
     IMessageListener listener = new SyncListener(buffer);
     string localQueue = "queue-" + UUID.RandomUuid();
     Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
     Session.ExchangeBind(localQueue, "amq.direct", queue);
     Session.AttachMessageListener(listener, localQueue);
     Session.MessageSubscribe(localQueue);
     for (int i = 0; i < size; ++i)
     {
         buffer.Dequeue();
     }
 }
Ejemplo n.º 5
0
        public override void Start()
        {
            byte[] data = new byte[Options.Size];
            // randomly populate data 
            Random r = new Random(34);
            r.NextBytes(data);
            IMessage message = new Message();
            message.AppendData(data);

            message.DeliveryProperties.SetRoutingKey(_key);

            if (Options.Durable)
                message.DeliveryProperties.SetDeliveryMode(MessageDeliveryMode.PERSISTENT);

            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }

            CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
            // Create a listener and subscribe it to the queue named "pub_start"          
            IMessageListener listener = new SyncListener(buffer);
            string localQueue = "localQueue-" + UUID.RandomUuid().ToString();
            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", "pub_start");
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }
            buffer.Dequeue();

            for (int j = 0; j < Options.Iterations; ++j)
            {
                DateTime start = DateTime.Now;                
                for (long i = 0; i < Options.Count; ++i)
                {
                    Session.MessageTransfer(_exchange, message);

                    if (Options.SyncPub)
                    {
                        Session.Sync();
                    }
                    if (Options.Tx > 0 && (i + 1)%Options.Tx == 0)
                    {
                        Session.TxSelect();
                        Session.Sync();
                    }
                    if (Options.IntervalPub > 0)
                    {
                        Thread.Sleep((int) Options.IntervalSub*1000);
                    }
                }
                Session.Sync();
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("pub_done");
                message.ClearData();
                double time = end.Subtract(start).TotalMilliseconds;
                byte[] rate = BitConverter.GetBytes( Options.Count / time );
                message.AppendData(rate);
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }
Ejemplo n.º 6
0
        public override void Start()
        {
            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }
            CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
            // Create a listener and subscribe it to the queue named "message_queue"
            IMessageListener listener = new SyncListener(buffer);

            string dest = "dest" + UUID.RandomUuid();
            Session.AttachMessageListener(listener, dest);
            Session.MessageSubscribe(_queue, dest,
                                     Options.Tx > 0 || Options.SubAck > 0
                                         ? MessageAcceptMode.EXPLICIT
                                         : MessageAcceptMode.NONE,
                                     MessageAcquireMode.PRE_ACQUIRED, null, 0, null);
            // issue credits     
            Session.MessageSetFlowMode(dest, MessageFlowMode.WINDOW);
            Session.MessageFlow(dest, MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);

            // Notify controller we are ready.
            IMessage message = new Message();
            message.DeliveryProperties.SetRoutingKey("sub_ready");

            message.AppendData(Encoding.UTF8.GetBytes("ready"));
            Session.MessageTransfer("amq.direct", message);

            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }


            for (int j = 0; j < Options.Iterations; ++j)
            {
               
                //need to allocate some more credit
                Session.MessageFlow(dest, MessageCreditUnit.MESSAGE, (long)Options.SubQuota);
                
                RangeSet range = new RangeSet();
                IMessage msg;
                DateTime start = DateTime.Now;
                for (long i = 0; i < Options.SubQuota; ++i)
                {                   
                    msg = buffer.Dequeue();
                    if (Options.Tx > 0 && ((i + 1)%Options.Tx == 0))
                    {
                        Session.TxCommit();
                        Session.Sync();
                    }
                    if (Options.IntervalSub > 0)
                    {
                        Thread.Sleep((int) Options.IntervalSub*1000);
                    }
                    range.Add(msg.Id);
                }
                if (Options.Tx > 0 || Options.SubAck > 0)
                    Session.MessageAccept(range);
                range.Clear();
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("sub_done");
                message.ClearData();
                message.AppendData(BitConverter.GetBytes(Options.SubQuota / end.Subtract(start).TotalMilliseconds ));
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }
Ejemplo n.º 7
0
        public override void Start()
        {
            byte[] data = new byte[Options.Size];
            // randomly populate data
            Random r = new Random(34);

            r.NextBytes(data);
            IMessage message = new Message();

            message.AppendData(data);

            message.DeliveryProperties.SetRoutingKey(_key);

            if (Options.Durable)
            {
                message.DeliveryProperties.SetDeliveryMode(MessageDeliveryMode.PERSISTENT);
            }

            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }

            CircularBuffer <IMessage> buffer = new CircularBuffer <IMessage>(100);
            // Create a listener and subscribe it to the queue named "pub_start"
            IMessageListener listener   = new SyncListener(buffer);
            string           localQueue = "localQueue-" + UUID.RandomUuid().ToString();

            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", "pub_start");
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }
            buffer.Dequeue();

            for (int j = 0; j < Options.Iterations; ++j)
            {
                DateTime start = DateTime.Now;
                for (long i = 0; i < Options.Count; ++i)
                {
                    Session.MessageTransfer(_exchange, message);

                    if (Options.SyncPub)
                    {
                        Session.Sync();
                    }
                    if (Options.Tx > 0 && (i + 1) % Options.Tx == 0)
                    {
                        Session.TxSelect();
                        Session.Sync();
                    }
                    if (Options.IntervalPub > 0)
                    {
                        Thread.Sleep((int)Options.IntervalSub * 1000);
                    }
                }
                Session.Sync();
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("pub_done");
                message.ClearData();
                double time = end.Subtract(start).TotalMilliseconds;
                byte[] rate = BitConverter.GetBytes(Options.Count / time);
                message.AppendData(rate);
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }
Ejemplo n.º 8
0
        public override void Start()
        {
            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }
            CircularBuffer <IMessage> buffer = new CircularBuffer <IMessage>(100);
            // Create a listener and subscribe it to the queue named "message_queue"
            IMessageListener listener = new SyncListener(buffer);

            string dest = "dest" + UUID.RandomUuid();

            Session.AttachMessageListener(listener, dest);
            Session.MessageSubscribe(_queue, dest,
                                     Options.Tx > 0 || Options.SubAck > 0
                                         ? MessageAcceptMode.EXPLICIT
                                         : MessageAcceptMode.NONE,
                                     MessageAcquireMode.PRE_ACQUIRED, null, 0, null);
            // issue credits
            Session.MessageSetFlowMode(dest, MessageFlowMode.WINDOW);
            Session.MessageFlow(dest, MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);

            // Notify controller we are ready.
            IMessage message = new Message();

            message.DeliveryProperties.SetRoutingKey("sub_ready");

            message.AppendData(Encoding.UTF8.GetBytes("ready"));
            Session.MessageTransfer("amq.direct", message);

            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }


            for (int j = 0; j < Options.Iterations; ++j)
            {
                //need to allocate some more credit
                Session.MessageFlow(dest, MessageCreditUnit.MESSAGE, (long)Options.SubQuota);

                RangeSet range = new RangeSet();
                IMessage msg;
                DateTime start = DateTime.Now;
                for (long i = 0; i < Options.SubQuota; ++i)
                {
                    msg = buffer.Dequeue();
                    if (Options.Tx > 0 && ((i + 1) % Options.Tx == 0))
                    {
                        Session.TxCommit();
                        Session.Sync();
                    }
                    if (Options.IntervalSub > 0)
                    {
                        Thread.Sleep((int)Options.IntervalSub * 1000);
                    }
                    range.Add(msg.Id);
                }
                if (Options.Tx > 0 || Options.SubAck > 0)
                {
                    Session.MessageAccept(range);
                }
                range.Clear();
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("sub_done");
                message.ClearData();
                message.AppendData(BitConverter.GetBytes(Options.SubQuota / end.Subtract(start).TotalMilliseconds));
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }