Ejemplo n.º 1
0
 public PingPongActor(WaitForStarts waitForStartsActor, IDestination destination, long repeat, TaskCompletionSource <bool> latch)
 {
     this.waitForStartsActor = waitForStartsActor;
     this.destination        = destination;
     this.repeat             = repeat;
     this.latch = latch;
 }
Ejemplo n.º 2
0
 public PingPongActor(WaitForStarts waitForStartsActor, IDestination destination, long repeat, TaskCompletionSource<bool> latch)
 {
     this.waitForStartsActor = waitForStartsActor;
     this.destination = destination;
     this.repeat = repeat;
     this.latch = latch;
 }
Ejemplo n.º 3
0
 public Destination(WaitForStarts waitForStartsActor)
 {
     this.waitForStartsActor = waitForStartsActor;
 }
Ejemplo n.º 4
0
        private static async Task<Tuple<bool, long, int>> Benchmark(int factor, int numberOfClients, long numberOfRepeats, PrintStats printStats, long bestThroughput, int redCount,
            Func<int, WaitForStarts, Tuple<IActorServerProxy, Destination>> createDestination,
            Func<int, Destination, IDestination> createDestClient,
            Func<int, WaitForStarts, IDestination, long, TaskCompletionSource<bool>, PingPongActor> createPingPong)
        {
            var totalMessagesReceived = GetTotalMessagesReceived(numberOfRepeats);
            //times 2 since the client and the destination both send messages
            long repeatsPerClient = numberOfRepeats / numberOfClients;
            var totalWatch = Stopwatch.StartNew();

            var countdown = new CountdownEvent(numberOfClients * 2);
            var waitForStartsActor = new WaitForStarts(countdown);
            var clients = new List<PingPongActor>();
            var dests = new List<Tuple<IActorServerProxy, Destination>>();
            var tasks = new List<Task>();
            for (int i = 0; i < numberOfClients; i++)
            {
                var destination = createDestination(i, waitForStartsActor);
                dests.Add(destination);

                var ts = new TaskCompletionSource<bool>();
                tasks.Add(ts.Task);
                var client = createPingPong(i, waitForStartsActor, createDestClient(i, destination.Item2), repeatsPerClient, ts);
                clients.Add(client);

                client.Start();
                destination.Item2.Start();
            }
            if (!countdown.Wait(TimeSpan.FromSeconds(10)))
            {
                Console.WriteLine("The system did not start in 10 seconds. Aborting.");
                return Tuple.Create(false, bestThroughput, redCount);
            }
            var setupTime = totalWatch.Elapsed;
            var sw = Stopwatch.StartNew();
            clients.ForEach(c => c.Ping());

            await Task.WhenAll(tasks.ToArray());
            sw.Stop();

            totalWatch.Stop();

            dests.ForEach(d => { if (d.Item1 != null) d.Item1.Stop(); });
            dests.ForEach(d => { d.Item2.Stop(); });
            clients.ForEach(c => c.Stop());

            var elapsedMilliseconds = sw.ElapsedMilliseconds;
            long throughput = elapsedMilliseconds == 0 ? -1 : totalMessagesReceived / elapsedMilliseconds * 1000;
            var foregroundColor = Console.ForegroundColor;
            if (throughput >= bestThroughput)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                bestThroughput = throughput;
                redCount = 0;
            }
            else
            {
                redCount++;
                Console.ForegroundColor = ConsoleColor.Red;
            }
            if (printStats.HasFlag(PrintStats.StartTimeOnly))
            {
                Console.Write("{0,5}", setupTime.TotalMilliseconds.ToString("F2", CultureInfo.InvariantCulture));
            }
            else
            {
                if (printStats.HasFlag(PrintStats.LineStart))
                    Console.Write("{0,10}, ", factor);
                if (printStats.HasFlag(PrintStats.Stats))
                    Console.Write("{0,8}, {1,10}, {2,10}", throughput, setupTime.TotalMilliseconds.ToString("F2", CultureInfo.InvariantCulture), totalWatch.Elapsed.TotalMilliseconds.ToString("F2", CultureInfo.InvariantCulture));
            }
            Console.ForegroundColor = foregroundColor;

            return Tuple.Create(redCount <= 3, bestThroughput, redCount);
        }
Ejemplo n.º 5
0
 public Destination(WaitForStarts waitForStartsActor)
 {
     this.waitForStartsActor = waitForStartsActor;
 }
Ejemplo n.º 6
0
        private static async Task <Tuple <bool, long, int> > Benchmark(int factor, int numberOfClients, long numberOfRepeats, PrintStats printStats, long bestThroughput, int redCount,
                                                                       Func <int, WaitForStarts, Tuple <IActorServerProxy, Destination> > createDestination,
                                                                       Func <int, Destination, IDestination> createDestClient,
                                                                       Func <int, WaitForStarts, IDestination, long, TaskCompletionSource <bool>, PingPongActor> createPingPong)
        {
            var totalMessagesReceived = GetTotalMessagesReceived(numberOfRepeats);
            //times 2 since the client and the destination both send messages
            long repeatsPerClient = numberOfRepeats / numberOfClients;
            var  totalWatch       = Stopwatch.StartNew();

            var countdown          = new CountdownEvent(numberOfClients * 2);
            var waitForStartsActor = new WaitForStarts(countdown);
            var clients            = new List <PingPongActor>();
            var dests = new List <Tuple <IActorServerProxy, Destination> >();
            var tasks = new List <Task>();

            for (int i = 0; i < numberOfClients; i++)
            {
                var destination = createDestination(i, waitForStartsActor);
                dests.Add(destination);

                var ts = new TaskCompletionSource <bool>();
                tasks.Add(ts.Task);
                var client = createPingPong(i, waitForStartsActor, createDestClient(i, destination.Item2), repeatsPerClient, ts);
                clients.Add(client);

                client.Start();
                destination.Item2.Start();
            }
            if (!countdown.Wait(TimeSpan.FromSeconds(10)))
            {
                Console.WriteLine("The system did not start in 10 seconds. Aborting.");
                return(Tuple.Create(false, bestThroughput, redCount));
            }
            var setupTime = totalWatch.Elapsed;
            var sw        = Stopwatch.StartNew();

            clients.ForEach(c => c.Ping());

            await Task.WhenAll(tasks.ToArray());

            sw.Stop();

            totalWatch.Stop();

            dests.ForEach(d => { if (d.Item1 != null)
                                 {
                                     d.Item1.Stop();
                                 }
                          });
            dests.ForEach(d => { d.Item2.Stop(); });
            clients.ForEach(c => c.Stop());

            var  elapsedMilliseconds = sw.ElapsedMilliseconds;
            long throughput          = elapsedMilliseconds == 0 ? -1 : totalMessagesReceived / elapsedMilliseconds * 1000;
            var  foregroundColor     = Console.ForegroundColor;

            if (throughput >= bestThroughput)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                bestThroughput          = throughput;
                redCount = 0;
            }
            else
            {
                redCount++;
                Console.ForegroundColor = ConsoleColor.Red;
            }
            if (printStats.HasFlag(PrintStats.StartTimeOnly))
            {
                Console.Write("{0,5}", setupTime.TotalMilliseconds.ToString("F2", CultureInfo.InvariantCulture));
            }
            else
            {
                if (printStats.HasFlag(PrintStats.LineStart))
                {
                    Console.Write("{0,10}, ", factor);
                }
                if (printStats.HasFlag(PrintStats.Stats))
                {
                    Console.Write("{0,8}, {1,10}, {2,10}", throughput, setupTime.TotalMilliseconds.ToString("F2", CultureInfo.InvariantCulture), totalWatch.Elapsed.TotalMilliseconds.ToString("F2", CultureInfo.InvariantCulture));
                }
            }
            Console.ForegroundColor = foregroundColor;

            return(Tuple.Create(redCount <= 3, bestThroughput, redCount));
        }