Example #1
0
        private static void DoTheRun(int iterations)
        {
            Console.WriteLine("Start");
            Task[] allTasks = new Task[13];
            for (int t = 0; t < allTasks.Length; t++)
            {
                int tt = t;
                allTasks[t] = Task.Run(() =>
                {
                    var ttt = tt;
                    for (int i = 0; i < iterations; i++)
                    {
                        try
                        {
                            //RunAllHttpStressTests();    //  for TestHelpers.SetHostAndProtocol(useHttp: true
                            RunAllNetTcpStressTests();  //  for TestHelpers.SetHostAndProtocol(useHttp: false
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debugger.Break();
                        }

                        if (i % 1000 == 0)
                        {
                            Console.WriteLine(ttt + " " + i);
                        }
                    }
                    Console.WriteLine(ttt + ": done");
                });
            }
            Task.WaitAll(allTasks);

            Console.WriteLine("Dispose all");
            StaticDisposablesHelper.DisposeAll();
        }
Example #2
0
        private void DoTheRunAsync(Func <Task> testAsync)
        {
            var cts = new CancellationTokenSource(_paramStressRunDuration);

            Console.WriteLine("Start");

            Task[] allTasks = new Task[_paramStressLevel];
            for (int t = 0; t < allTasks.Length; t++)
            {
                int tt = t;
                allTasks[t] = Task.Run(async() =>
                {
                    var ttt = tt;
                    for (long i = 0; i < _paramIterations / allTasks.Length; i++)
                    {
                        try
                        {
                            await testAsync();
                        }
                        catch (ObjectDisposedException e)
                        {
                            TestUtils.ReportFailure(e.ToString());
                        }
                        catch (Exception e)
                        {
                            TestUtils.ReportFailure(e.ToString());
                            throw;
                        }

                        if (i % 100 == 0)
                        {
                            Console.WriteLine(DateTime.Now.ToString() + " " + ttt + " " + i);
                        }

                        if (cts.Token.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                    Console.WriteLine(ttt + ": done");
                }, cts.Token);
            }
            Task.WaitAll(allTasks);

            Console.WriteLine("Dispose all");
            StaticDisposablesHelper.DisposeAll();
        }
Example #3
0
        public void RunPerf()
        {
            switch (_paramTestToRun)
            {
            case "HelloWorld":
                if (_paramUseAsync)
                {
                    RunFirstNIterationsAsync(MaxIterations, MaxTasks,
                                             testAsync: RunStartupPerfTestsAsync <IService1, HelloWorldTest <CommonPerfStartupTestParams>, CommonPerfStartupTestParams>);
                    RunMaxThroughputAsync(duration: s_measurementDuration, maxTasks: MaxTasks,
                                          testAsync: RunThroughputPerfTestsAsync <IService1, HelloWorldTest <CommonPerfThroughputTestParams>, CommonPerfThroughputTestParams>);
                }
                else
                {
                    RunFirstNIterations(MaxIterations, MaxTasks,
                                        test: RunStartupPerfTests <IService1, HelloWorldTest <CommonPerfStartupTestParams>, CommonPerfStartupTestParams>);
                    RunMaxThroughput(duration: s_measurementDuration, maxTasks: MaxTasks,
                                     test: RunThroughputPerfTests <IService1, HelloWorldTest <CommonPerfThroughputTestParams>, CommonPerfThroughputTestParams>);
                }
                break;

            case "Streaming":
                if (_paramUseAsync)
                {
                    RunFirstNIterationsAsync(MaxIterations, MaxTasks,
                                             testAsync: RunStartupPerfTestsAsync <IStreamingService, StreamingTest <IStreamingService, StreamingPerfStartupTestParams>, StreamingPerfStartupTestParams>);
                    RunMaxThroughputAsync(duration: s_measurementDuration, maxTasks: MaxTasks,
                                          testAsync: RunThroughputPerfTestsAsync <IStreamingService, StreamingTest <IStreamingService, StreamingPerfThroughputTestParams>, StreamingPerfThroughputTestParams>);
                }
                else
                {
                    RunFirstNIterations(MaxIterations, MaxTasks,
                                        test: RunStartupPerfTests <IStreamingService, StreamingTest <IStreamingService, StreamingPerfStartupTestParams>, StreamingPerfStartupTestParams>);
                    RunMaxThroughput(duration: s_measurementDuration, maxTasks: MaxTasks,
                                     test: RunThroughputPerfTests <IStreamingService, StreamingTest <IStreamingService, StreamingPerfThroughputTestParams>, StreamingPerfThroughputTestParams>);
                }
                break;

            case "Duplex":
                if (_paramUseAsync)
                {
                    RunFirstNIterationsAsync(MaxIterations, MaxTasks,
                                             testAsync: RunStartupPerfTestsAsync <IDuplexService, DuplexTest <DuplexPerfStartupTestParams>, DuplexPerfStartupTestParams>);
                    RunMaxThroughputAsync(duration: s_measurementDuration, maxTasks: MaxTasks,
                                          testAsync: RunThroughputPerfTestsAsync <IDuplexService, DuplexTest <DuplexPerfThroughputTestParams>, DuplexPerfThroughputTestParams>);
                }
                else
                {
                    RunFirstNIterations(MaxIterations, MaxTasks,
                                        test: RunStartupPerfTests <IDuplexService, DuplexTest <DuplexPerfStartupTestParams>, DuplexPerfStartupTestParams>);
                    RunMaxThroughput(duration: s_measurementDuration, maxTasks: MaxTasks,
                                     test: RunThroughputPerfTests <IDuplexService, DuplexTest <DuplexPerfThroughputTestParams>, DuplexPerfThroughputTestParams>);
                }
                break;

            case "DuplexStreaming":
                if (_paramUseAsync)
                {
                    RunFirstNIterationsAsync(MaxIterations, MaxTasks,
                                             testAsync: RunStartupPerfTestsAsync <IDuplexStreamingService, DuplexStreamingTest <IDuplexStreamingService, DuplexStreamingPerfStartupTestParams>, DuplexStreamingPerfStartupTestParams>);
                    RunMaxThroughputAsync(duration: s_measurementDuration, maxTasks: MaxTasks,
                                          testAsync: RunThroughputPerfTestsAsync <IDuplexStreamingService, DuplexStreamingTest <IDuplexStreamingService, DuplexStreamingPerfThroughputTestParams>, DuplexStreamingPerfThroughputTestParams>);
                }
                else
                {
                    RunFirstNIterations(MaxIterations, MaxTasks,
                                        test: RunStartupPerfTests <IDuplexStreamingService, DuplexStreamingTest <IDuplexStreamingService, DuplexStreamingPerfStartupTestParams>, DuplexStreamingPerfStartupTestParams>);
                    RunMaxThroughput(duration: s_measurementDuration, maxTasks: MaxTasks,
                                     test: RunThroughputPerfTests <IDuplexStreamingService, DuplexStreamingTest <IDuplexStreamingService, DuplexStreamingPerfThroughputTestParams>, DuplexStreamingPerfThroughputTestParams>);
                }
                break;

            default:
                Console.WriteLine("wrong argument: " + _paramTestToRun);
                return;
            }

            var sw = new Stopwatch();

            sw.Start();
            StaticDisposablesHelper.DisposeAll();
            Console.WriteLine("Dispose all done in " + sw.ElapsedMilliseconds);
        }