Ejemplo n.º 1
0
        private static int RunManyClientsTest(ITestClient client, int iterations)
        {
            var rand = new Random();

            _clientsRunning = 0;
            //warm up
            var sw = new Stopwatch();

            sw.Start();
            RunMixedPackTest(client.CreateOne(), iterations, KeyName, KeyName2);
            sw.Stop();

            var time       = (int)sw.ElapsedMilliseconds;
            int spawnTimes = 0;
            int result     = 0;
            var tasks      = new List <Task>();

            for (var i = 0; i < Iterations; i++)
            {
                SpinWait.SpinUntil(() => _clientsRunning < MaxClients);

                tasks.Add(Task.Run(() =>
                {
                    spawnTimes++;
                    Console.WriteLine("Spawn new " + client.ClientName);
                    Interlocked.Increment(ref _clientsRunning);
                    var tmp = RunMixedPackTest(client.CreateOne(), iterations, KeyName + "_" + spawnTimes, KeyName2 + "_" + spawnTimes, false);
                    result += tmp;
                    Console.WriteLine("Client time ms = " + tmp);
                    Interlocked.Decrement(ref _clientsRunning);
                    Console.WriteLine("Destroy " + client.ClientName);
                }));
                Thread.Sleep(rand.Next(time));
            }
            Task.WaitAll(tasks.ToArray());
            return(result / spawnTimes);
        }
Ejemplo n.º 2
0
        private static int RunManyClientsTest(ITestClient client, int iterations)
        {
            var rand = new Random();
            _clientsRunning = 0;
            //warm up
            var sw = new Stopwatch();
            sw.Start();
            RunMixedPackTest(client.CreateOne(), iterations, KeyName, KeyName2);
            sw.Stop();

            var time = (int)sw.ElapsedMilliseconds;
            int spawnTimes = 0;
            int result = 0;
            var tasks = new List<Task>();
            for (var i = 0; i < Iterations; i++)
            {
                SpinWait.SpinUntil(() => _clientsRunning < MaxClients);

                tasks.Add(Task.Run(() =>
                    {
                        spawnTimes++;
                        Console.WriteLine("Spawn new " + client.ClientName);
                        Interlocked.Increment(ref _clientsRunning);
                        var tmp = RunMixedPackTest(client.CreateOne(), iterations, KeyName + "_" + spawnTimes, KeyName2 + "_" + spawnTimes,false);
                        result += tmp;
                        Console.WriteLine("Client time ms = "+tmp);
                        Interlocked.Decrement(ref _clientsRunning);
                        Console.WriteLine("Destroy " + client.ClientName);
                    }));
                Thread.Sleep(rand.Next(time));
            }
            Task.WaitAll(tasks.ToArray());
            return result/spawnTimes;
        }