Пример #1
0
            public Adf.IPoolInstance CreatePoolInstance()
            {
                var instance = new QueueServerClient(this.host, this.port, this.topic, this.commitTimeout);

                instance.Timeout = this.timeout;
                return(instance);
            }
Пример #2
0
        private void Pull(int SIZE, QueueServerClient client, Dictionary <ulong, int> dictionary)
        {
            Console.WriteLine();
            Console.WriteLine("pull and commit " + SIZE);
            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < SIZE; i++)
            {
                var data        = client.Pull();
                var remoteValue = Adf.BaseDataConverter.ToInt32(data.Data);
                var localValue  = 0;
                dictionary.TryGetValue(data.MessageId, out localValue);
                //diff value
                if (localValue != remoteValue)
                {
                    Console.WriteLine("receive result error, local: {0} -  remote : {1}, dup:{2}", localValue, remoteValue, data.Duplications);
                }
                //diff index
                if (i != remoteValue)
                {
                    Console.WriteLine("receive result error, index: {0} -  remote : {1}, dup:{2}", i, remoteValue, data.Duplications);
                }

                client.Commit(data.MessageId);
            }
            stopwatch.Stop();
            Console.WriteLine((SIZE / (double)(stopwatch.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s");
        }
Пример #3
0
        private void PushAsync(int SIZE, QueueServerClient client, Dictionary <ulong, int> dictionary)
        {
            Console.WriteLine();
            Console.WriteLine("async push " + SIZE);
            System.Threading.ManualResetEvent waitHandle3 = new System.Threading.ManualResetEvent(false);
            //var pushAck = new QueueServerPushAck((ulong transferId, ulong messageId, QueueServerErrorCode errorCode, string errorMessage) =>
            //var pushAck = new EventHandler<QueueServerPushAckArgs>((sender, args) =>
            var pushAck = new QueueServerClientEvent <QueueServerAckArgs>((sender, args) =>
            {
                lock (dictionary)
                    dictionary.Add(args.MessageId, (int)args.TransferId);

                if ((int)args.TransferId == SIZE - 1)
                {
                    waitHandle3.Set();
                }
            });

            client.RPushAck += pushAck;
            var stopwatch = Stopwatch.StartNew();

            for (uint i = 0; i < SIZE; i++)
            {
                var data = Adf.BaseDataConverter.ToBytes(i);
                client.RPushAsync(data, i);
            }
            waitHandle3.WaitOne();
            stopwatch.Stop();
            client.RPushAck -= pushAck;
            Console.WriteLine((SIZE / (double)(stopwatch.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s");
        }
        static QueueServerReceiveOption QueueServerReceiveEvent(QueueServerClient client, QueueServerMessageAckArgs args)
        {
            var t = System.Threading.Interlocked.Increment(ref total);

            if (t >= 1000000)
            {
                eh.Set();
            }

            return(QueueServerReceiveOption.Nothing);
        }
Пример #5
0
        private void Push(QueueServerClient client)
        {
            var msgId = 0UL;

            //
            msgId = client.RPush("1");
            Console.WriteLine("push " + msgId);
            msgId = client.RPush("2");
            Console.WriteLine("push " + msgId);
            msgId = client.RPush("3");
            Console.WriteLine("push " + msgId);
        }
Пример #6
0
        private void Push(int SIZE, QueueServerClient client, Dictionary <ulong, int> dictionary)
        {
            Console.WriteLine();
            Console.WriteLine("push " + SIZE);
            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < SIZE; i++)
            {
                var data  = Adf.BaseDataConverter.ToBytes(i);
                var msgid = client.RPush(data);
                dictionary.Add(msgid, i);
            }
            stopwatch.Stop();
            Console.WriteLine((SIZE / (double)(stopwatch.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s");
        }
Пример #7
0
        //private void ParallelPushAndPullAsync(int SIZE, QueueServerClient client, Dictionary<ulong, int> dictionary)
        //{
        //    Console.WriteLine();
        //    Console.WriteLine("parallel async push - async pull - commit " + SIZE);

        //    System.Threading.ManualResetEvent waitHandle1 = new System.Threading.ManualResetEvent(false);
        //    var stopwatch = Stopwatch.StartNew();
        //    QueueServerPushAck pushAck = (ulong transferId, ulong messageId, QueueServerErrorCode errorCode, string errorMessage) =>
        //    {
        //        lock (dictionary)
        //            dictionary.Add(messageId, (int)transferId);

        //        if ((int)transferId == SIZE - 1)
        //        {
        //            waitHandle1.Set();
        //            stopwatch.Stop();
        //        }
        //    };
        //    client.PushAck += pushAck;
        //    System.Threading.ThreadPool.QueueUserWorkItem(q =>
        //    {
        //        stopwatch.Reset();
        //        stopwatch.Start();
        //        for (uint i = 0; i < SIZE; i++)
        //        {
        //            var data = Adf.BaseDataConverter.ToBytes(i);
        //            client.PushAsync(data, i);
        //        }
        //    });

        //    this.PullAsync(SIZE, client, dictionary);


        //    waitHandle1.WaitOne();
        //    client.PushAck -= pushAck;
        //    Console.WriteLine("push async:" + (SIZE / (double)(stopwatch.ElapsedMilliseconds / 1000)) + "/s");
        //}

        private void ParallelPushAndPullCommit(int SIZE, QueueServerClient client, Dictionary <ulong, int> dictionary)
        {
            Console.WriteLine();
            Console.WriteLine("parallel push / pull-commit " + SIZE);
            System.Threading.ManualResetEvent waitHandle1 = new System.Threading.ManualResetEvent(false);
            System.Threading.ThreadPool.QueueUserWorkItem(s =>
            {
                var stopwatch1 = Stopwatch.StartNew();
                stopwatch1.Start();
                for (int i = 0; i < SIZE; i++)
                {
                    var data  = Adf.BaseDataConverter.ToBytes(i);
                    var msgid = client.RPush(data);
                    lock (dictionary)
                        dictionary.Add(msgid, i);
                }
                stopwatch1.Stop();
                Console.WriteLine("push:" + (SIZE / (double)(stopwatch1.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s");
                waitHandle1.Set();
            });

            System.Threading.ManualResetEvent waitHandle2 = new System.Threading.ManualResetEvent(false);
            System.Threading.ThreadPool.QueueUserWorkItem(s =>
            {
                var stopwatch1 = Stopwatch.StartNew();
                stopwatch1.Start();
                for (int i = 0; i < SIZE; i++)
                {
                    var data        = client.Pull();
                    var remoteValue = Adf.BaseDataConverter.ToInt32(data.Data);
                    var localValue  = 0;
                    lock (dictionary)
                        dictionary.TryGetValue(data.MessageId, out localValue);
                    //diff value
                    if (localValue != remoteValue)
                    {
                        Console.WriteLine("receive result error, local: {0} -  remote : {1}, dup: {2}", localValue, remoteValue, data.Duplications);
                    }
                    client.Commit(data.MessageId);
                }
                stopwatch1.Stop();
                Console.WriteLine("pull:" + (SIZE / (double)(stopwatch1.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s");
                waitHandle2.Set();
            });

            waitHandle1.WaitOne();
            waitHandle2.WaitOne();
        }
Пример #8
0
        private void CheckAutoRollback(QueueServerClient client)
        {
            client.Select(client.Topic, 5);

            Console.WriteLine("push one message and pull no commit,wait timeout 10s, check auto rollback");
            //client.RPush("");
            var msg = client.Pull();

            System.Threading.Thread.Sleep(10000);
            try
            {
                client.Rollback(msg.MessageId);

                //成功则表示未自动 rollback,
                Console.WriteLine("commit timeout error");
            }
            catch
            {
            }
            Console.WriteLine("completed");
        }
Пример #9
0
 private void ReceiveErrorCallback(QueueServerClient client4, QueueServerErrorEventArgs args)
 {
     Console.WriteLine("receive error:" + args.Exception.ToString());
 }