Example #1
0
        public IEnumerable <string> Simulate(Load workLoad, int threadCount)
        {
            currentTime = new Stopwatch();
            currentTime.Start();
            workLoad.Connect(Enqueue);
            totalMessages = workLoad.TotalMessages;
            dequeueStrategy.Start(threadCount);

            Task.Run(() =>
            {
                while (workLoad.TotalSentMessages < workLoad.TotalMessages)
                {
                    var before = currentTime.ElapsedMilliseconds;
                    workLoad.TimePassed(before);
                    var after = currentTime.ElapsedMilliseconds;
                    var delay = (int)(after - before);
                    if (delay < 50)
                    {
                        Thread.Sleep(50 - delay);
                    }
                }
                signalEndEvent.Wait();
                taskStarted.Dispose();
                taskEnded.Dispose();
                results.CompleteAdding();
            });
            return(results.GetConsumingEnumerable());
        }
 public IEnumerable<string> Simulate(Load workLoad, int threadCount)
 {
     currentTime = new Stopwatch();
     currentTime.Start();
     workLoad.Connect(Enqueue);
     totalMessages = workLoad.TotalMessages;
     dequeueStrategy.Start(threadCount);
     
     Task.Run(() =>
     {
         while (workLoad.TotalSentMessages < workLoad.TotalMessages)
         {
             var before = currentTime.ElapsedMilliseconds;
             workLoad.TimePassed(before);
             var after = currentTime.ElapsedMilliseconds;
             var delay = (int) (after - before);
             if (delay < 50)
             {
                 Thread.Sleep(50 - delay);
             }
         }
         signalEndEvent.Wait();
         taskStarted.Dispose();
         taskEnded.Dispose();
         results.CompleteAdding();
     });
     return results.GetConsumingEnumerable();
 }
Example #3
0
 public IEnumerable <string> Simulate(Load workload, int maximumConcurrency)
 {
     this.maximumConcurrency = maximumConcurrency;
     workload.Connect(queue.Add);
     StartThread(0);
     while (threads.Count > 0)
     {
         workload.TimePassed(currentTime);
         const int longRunningThreshold = 100;
         foreach (var runningThread in threads)
         {
             runningThread.Tick(currentTime);
             var blockedTime = currentTime - runningThread.BlockedAt;
             if (!runningThread.Dead && !runningThread.Replaced && runningThread.ProcessingMessage && blockedTime > longRunningThreshold) //blocked for more than five seconds
             {
                 runningThread.MarkAsReplaced();
                 RampUp();
             }
         }
         foreach (var action in currentQueue)
         {
             action();
         }
         currentQueue.Clear();
         if (threads.Count > 0)
         {
             var newTime = threads.Min(x => x.DueAt);
             if (threads.Any(x => x.LongRunning && !x.Replaced && newTime - currentTime > longRunningThreshold))
             {
                 currentTime = currentTime + longRunningThreshold;
             }
             else
             {
                 currentTime = newTime;
             }
         }
         //if (!workload.HasMoreMessages && processedMessages == workload.TotalMessages)
         //{
         //    break;
         //}
     }
     return(result.Select(x => string.Format("{0,12:n} [{1,2}] {2}", x.Item1, x.Item2, x.Item3)));
 }
 public IEnumerable<string> Simulate(Load workload, int maximumConcurrency)
 {
     this.maximumConcurrency = maximumConcurrency;
     workload.Connect(queue.Add);
     StartThread(0);
     while (threads.Count > 0)
     {
         workload.TimePassed(currentTime);
         const int longRunningThreshold = 100;
         foreach (var runningThread in threads)
         {
             runningThread.Tick(currentTime);
             var blockedTime = currentTime - runningThread.BlockedAt;
             if (!runningThread.Dead && !runningThread.Replaced && runningThread.ProcessingMessage && blockedTime > longRunningThreshold) //blocked for more than five seconds
             {
                 runningThread.MarkAsReplaced();
                 RampUp();
             }
         }
         foreach (var action in currentQueue)
         {
             action();
         }
         currentQueue.Clear();
         if (threads.Count > 0)
         {
             var newTime = threads.Min(x => x.DueAt);
             if (threads.Any(x => x.LongRunning && !x.Replaced  && newTime - currentTime > longRunningThreshold))
             {
                 currentTime = currentTime + longRunningThreshold;
             }
             else
             {
                 currentTime = newTime;
             }
         }
         //if (!workload.HasMoreMessages && processedMessages == workload.TotalMessages)
         //{
         //    break;
         //}
     }
     return result.Select(x => string.Format("{0,12:n} [{1,2}] {2}", x.Item1, x.Item2, x.Item3));
 }