Exemplo n.º 1
0
        private void Perf_test_single_thread_put_peek_and_take(ITransactionalQueue <XDoc> queue)
        {
            long totalEnqueue = 0;
            long totalDequeue = 0;
            var  n            = 20000;
            var  m            = 4;

            for (var k = 0; k < m; k++)
            {
                var items = new List <XDoc>();
                for (var i = 0; i < n; i++)
                {
                    items.Add(new XDoc("test")
                              .Attr("id", i)
                              .Elem("foo", "bar")
                              .Start("baz")
                              .Attr("meta", "true")
                              .Value("dsfdsssssssssssssssssssssssssssssfdfsfsfsfsfsfsfd")
                              .End()
                              .Start("id", StringUtil.CreateAlphaNumericKey(16)));
                }
                var stopwatch = Stopwatch.StartNew();
                foreach (var itm in items)
                {
                    queue.Enqueue(itm);
                }
                Assert.AreEqual(n, queue.Count);
                stopwatch.Stop();
                totalEnqueue += stopwatch.ElapsedMilliseconds;
                var j = 0;
                stopwatch = Stopwatch.StartNew();
                var v = queue.Dequeue();
                while (v != null)
                {
                    Assert.IsTrue(queue.CommitDequeue(v.Id));
                    j++;
                    v = queue.Dequeue();
                }
                stopwatch.Stop();
                totalDequeue += stopwatch.ElapsedMilliseconds;
                Assert.AreEqual(n, j);
                Assert.AreEqual(0, queue.Count);
            }
            Console.WriteLine("Enqueue: {0:0,000}/s", n * m * 1000 / totalEnqueue);
            Console.WriteLine("Dequeue: {0:0,000}/s", n * m * 1000 / totalDequeue);
        }
Exemplo n.º 2
0
        private int Dequeue(ITransactionalQueue <XDoc> queue, ManualResetEvent trigger)
        {
            trigger.WaitOne();
            var j = 0;
            ITransactionalQueueEntry <XDoc> value = queue.Dequeue();

            while (value != null)
            {
                bool success = queue.CommitDequeue(value.Id);
                if (!success)
                {
                    throw new InvalidOperationException();
                }
                j++;
                value = queue.Dequeue();
            }
            return(j);
        }
Exemplo n.º 3
0
 private void Poll(TaskTimer timer)
 {
     if (!_poll)
     {
         timer.Change(TimeSpan.FromSeconds(1), TaskEnv.Current);
         return;
     }
     _poll = false;
     while (true)
     {
         // pull item from queue to store in out accumulation queue and hold on to it
         var item = _persistentQueue.Dequeue(TimeSpan.MaxValue);
         if (item == null)
         {
             // didn't find an item, drop out of loop and set timer to check again later
             timer.Change(TimeSpan.FromSeconds(1), TaskEnv.Current);
             return;
         }
         var doc    = item.Value;
         var wikiid = doc["@wikiid"].AsText;
         var id     = new XUri("http://" + wikiid + "/" + doc["path"].AsText);
         lock (_data) {
             UpdateRecord data;
             XUri         channel = doc["channel"].AsUri;
             string       action  = channel.Segments[2];
             if (!_data.TryGetValue(id, out data))
             {
                 _log.DebugFormat("queueing '{0}' for '{1}'", action, id);
                 _queue.Enqueue(new Tuplet <DateTime, XUri>(DateTime.UtcNow.Add(_delay), id));
                 data = new UpdateRecord(id, doc, wikiid);
             }
             else
             {
                 _log.DebugFormat("appending existing queue record '{0}' for '{1}'", action, id);
                 data = data.With(doc);
             }
             if (action != "create" && action != "move")
             {
                 data.ActionStack.PushDelete();
             }
             if (action != "delete")
             {
                 data.ActionStack.PushAdd();
             }
             data.QueueIds.Add(item.Id);
             _data[id] = data;
         }
     }
 }
Exemplo n.º 4
0
        private void Perf_test_single_thread_put_peek_and_take(ITransactionalQueue<XDoc> queue)
        {
            long totalEnqueue = 0;
            long totalDequeue = 0;
            var n = 20000;
            var m = 4;

            for(var k = 0; k < m; k++) {
                var items = new List<XDoc>();
                for(var i = 0; i < n; i++) {
                    items.Add(new XDoc("test")
                                  .Attr("id", i)
                                  .Elem("foo", "bar")
                                  .Start("baz")
                                  .Attr("meta", "true")
                                  .Value("dsfdsssssssssssssssssssssssssssssfdfsfsfsfsfsfsfd")
                                  .End()
                                  .Start("id", StringUtil.CreateAlphaNumericKey(16)));
                }
                var stopwatch = Stopwatch.StartNew();
                foreach(var itm in items) {
                    queue.Enqueue(itm);
                }
                Assert.AreEqual(n, queue.Count);
                stopwatch.Stop();
                totalEnqueue += stopwatch.ElapsedMilliseconds;
                var j = 0;
                stopwatch = Stopwatch.StartNew();
                var v = queue.Dequeue();
                while(v != null) {
                    Assert.IsTrue(queue.CommitDequeue(v.Id));
                    j++;
                    v = queue.Dequeue();
                }
                stopwatch.Stop();
                totalDequeue += stopwatch.ElapsedMilliseconds;
                Assert.AreEqual(n, j);
                Assert.AreEqual(0, queue.Count);
            }
            Console.WriteLine("Enqueue: {0:0,000}/s", n * m * 1000 / totalEnqueue);
            Console.WriteLine("Dequeue: {0:0,000}/s", n * m * 1000 / totalDequeue);
        }
Exemplo n.º 5
0
 private int Dequeue(ITransactionalQueue<XDoc> queue, ManualResetEvent trigger)
 {
     trigger.WaitOne();
     var j = 0;
     ITransactionalQueueEntry<XDoc> value = queue.Dequeue();
     while(value != null) {
         bool success = queue.CommitDequeue(value.Id);
         if(!success) {
             throw new InvalidOperationException();
         }
         j++;
         value = queue.Dequeue();
     }
     return j;
 }