Exemplo n.º 1
0
        static RecyclablePooledFactoriesAndChannelsAsync_OpenOnce()
        {
            s_test = new TestTemplate();
            // It is expected to see various exceptions when we use factories while recycling them
            (s_test as IExceptionPolicy).RelaxedExceptionPolicy = true;

            s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
                new PoolOfAsyncThings <
                    FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, OpenAsyncOnceChannelWrapper <ChannelType> > >(
                    maxSize: s_test.TestParameters.MaxPooledFactories,
                    createInstance: () => new FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, OpenAsyncOnceChannelWrapper <ChannelType> >(
                        createFactoryInstance:
                        s_test.CreateChannelFactory,
                        destroyFactoryInstanceAsync: async(chf) =>
                        await s_test.CloseFactoryAsync(chf),
                        maxPooledObjects: s_test.TestParameters.MaxPooledChannels,
                        createObject: (chf) =>
            {
                var channel = s_test.CreateChannel(chf);
                // If channel creation failed and is unexpected we'd already catch it inside s_test.CreateChannel.
                // If the failure is expected then we will get null back.
                // In this case we simply return null instead of wrapping it and let the pool handle it
                return(channel != null ? new OpenAsyncOnceChannelWrapper <ChannelType>(channel) : null);
            },
                        destroyObjectAsync: async(chWr) => await s_test.CloseChannelAsync(chWr.Channel),
                        validateObjectInstance: (oaocw) => s_test.ValidateChannel(oaocw.Channel)),
                    destroyInstanceAsync: async(fapoio) => await fapoio.DestroyAsync(),
                    instanceValidator: (fapoio) => s_test.ValidateFactory(fapoio.Factory)));
        }
Exemplo n.º 2
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();
        }
        static RecyclablePooledFactoriesAndChannels_OpenOnce()
        {
            // moving the following magic numbers to the test template interface will help each test to collect different type of stats
            s_CreateChannelStats = new CallStats(samples: 1000, errorSamples: 1000);
            s_CallChannelStats   = new CallStats(samples: 1000000, errorSamples: 10000);
            s_CloseChannelStats  = new CallStats(samples: 1000, errorSamples: 1000);
            s_CloseFactoryStats  = new CallStats(samples: 1000, errorSamples: 1000);

            s_test = new TestTemplate();
            Console.WriteLine(s_test.GetType().ToString());

            // Perhaps a helper (extension?) method to hide new PoolOfThings would make things more readable
            s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
                new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, OpenOnceChannelWrapper <ChannelType> > >(
                    maxSize: 3, // # of pooled FactoryAndPoolOfItsObjects
                    createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, OpenOnceChannelWrapper <ChannelType> >(
                        createFactoryInstance: () =>
                        s_test.CreateChannelFactory(),
                        destroyFactoryInstance: (chf) =>
                        s_CloseFactoryStats.CallActionAndRecordStats(() => s_test.CloseFactory(chf)),
                        maxPooledObjects: 3, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                        createObject: (chf) =>
                        s_CreateChannelStats.CallFuncAndRecordStats(func: () => new OpenOnceChannelWrapper <ChannelType>(s_test.CreateChannel(chf))),
                        destroyObject: (chWr) =>
                        s_CloseChannelStats.CallActionAndRecordStats(action: () => s_test.CloseChannel(chWr.Channel))
                        ),
                    destroyInstance: (_fapoic) => _fapoic.Destroy()));
        }
Exemplo n.º 4
0
 static PooledFactoriesAsync()
 {
     s_test = new TestTemplate();
     s_pooledChannelFactories = StaticDisposablesHelper.AddDisposable(
         new PoolOfAsyncThings <ChannelFactory <ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories,
             createInstance: () => s_test.CreateChannelFactory(),
             destroyInstanceAsync: async(chf) => await s_test.CloseFactoryAsync(chf)));
 }
Exemplo n.º 5
0
 static PooledFactories()
 {
     s_test = new TestTemplate();
     s_pooledChannelFactories = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <ChannelFactory <ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories,
             createInstance: () => s_test.CreateChannelFactory(),
             destroyInstance: (chf) => s_test.CloseFactory(chf),
             instanceValidator: s_test.ValidateFactory));
 }
 static PooledFactories()
 {
     s_test = new TestTemplate();
     s_pooledChannelFactories = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <ChannelFactory <ChannelType> >(
             maxSize: 10,
             createInstance: () =>
             s_test.CreateChannelFactory(),
             destroyInstance: (chf) =>
             s_CloseFactoryStats.CallActionAndRecordStats(() => s_test.CloseFactory(chf))));
 }
Exemplo n.º 7
0
        static RecyclablePooledFactoriesAsync()
        {
            s_test = new TestTemplate();
            // It is expected to see various exceptions when we use factories while recycling them
            (s_test as IExceptionPolicy).RelaxedExceptionPolicy = true;

            s_recyclablePooledChannelFactories = StaticDisposablesHelper.AddDisposable(
                new PoolOfAsyncThings <ChannelFactory <ChannelType> >(
                    maxSize: s_test.TestParameters.MaxPooledFactories,
                    createInstance: s_test.CreateChannelFactory,
                    destroyInstanceAsync: async(chf) => await s_test.CloseFactoryAsync(chf)));
        }
 static PooledFactoriesAsync()
 {
     s_test = new TestTemplate();
     // we do not expect exceptions here since we're not closing anything during usage
     (s_test as IExceptionPolicy).RelaxedExceptionPolicy = false;
     s_pooledChannelFactories = StaticDisposablesHelper.AddDisposable(
         new PoolOfAsyncThings <ChannelFactory <ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories,
             createInstance: () => s_test.CreateChannelFactory(),
             destroyInstanceAsync: async(chf) => await s_test.CloseFactoryAsync(chf),
             instanceValidator: s_test.ValidateFactory));
 }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        static RecyclablePooledFactoriesAndChannels_OpenOnce()
        {
            s_test = new TestTemplate();
            // It is expected to see various exceptions when we use factories while recycling them
            (s_test as IExceptionPolicy).RelaxedExceptionPolicy = true;

            s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
                new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, OpenOnceChannelWrapper <ChannelType> > >(
                    maxSize: s_test.TestParameters.MaxPooledFactories,
                    createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, OpenOnceChannelWrapper <ChannelType> >(
                        createFactoryInstance: () => s_test.CreateChannelFactory(),
                        destroyFactoryInstance: (chf) => s_test.CloseFactory(chf),
                        maxPooledObjects: s_test.TestParameters.MaxPooledChannels,
                        createObject: (chf) => new OpenOnceChannelWrapper <ChannelType>(s_test.CreateChannel(chf)),
                        destroyObject: (chWr) => s_test.CloseChannel(chWr.Channel)),
                    destroyInstance: (_fapoio) => _fapoio.Destroy()));
        }
Exemplo n.º 11
0
 static PooledFactoriesAndChannelsAsync()
 {
     s_test = new TestTemplate();
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfAsyncThings <FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstanceAsync: async(chf) =>
                 await s_test.CloseFactoryAsync(chf),
                 maxPooledObjects: s_test.TestParameters.MaxPooledChannels, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_test.CreateChannel(chf),
                 destroyObjectAsync: async(ch) =>
                 await s_test.CloseChannelAsync(ch)
                 ),
             destroyInstanceAsync: async(_fapoiao) => await _fapoiao.DestroyAsync()));
 }
 static PooledFactoriesAndChannels()
 {
     s_test = new TestTemplate();
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: 3, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstance: (chf) =>
                 s_CloseFactoryStats.CallActionAndRecordStats(() => s_test.CloseFactory(chf)),
                 maxPooledObjects: 3, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_CreateChannelStats.CallFuncAndRecordStats(s_test.CreateChannel, chf),
                 destroyObject: (ch) =>
                 s_CloseChannelStats.CallActionAndRecordStats(() => s_test.CloseChannel(ch))
                 ),
             destroyInstance: (_fapoic) => _fapoic.Destroy()));
 }
Exemplo n.º 13
0
 static PooledFactoriesAndChannels()
 {
     s_test = new TestTemplate();
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstance: (chf) =>
                 s_test.CloseFactory(chf),
                 maxPooledObjects: s_test.TestParameters.MaxPooledChannels, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_test.CreateChannel(chf),
                 destroyObject: (ch) =>
                 s_test.CloseChannel(ch),
                 validateObjectInstance: s_test.ValidateChannel),
             destroyInstance: (fapoio) => fapoio.Destroy(),
             instanceValidator: (fapoiao) => s_test.ValidateFactory(fapoiao.Factory)));
 }
Exemplo n.º 14
0
        static RecyclablePooledFactoriesAndChannelsAsync()
        {
            s_test = new TestTemplate();
            // It is expected to see various exceptions when we use factories while recycling them
            (s_test as IExceptionPolicy).RelaxedExceptionPolicy = true;

            s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
                new PoolOfAsyncThings <FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, ChannelType> >(
                    maxSize: s_test.TestParameters.MaxPooledFactories,
                    createInstance: () => new FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, ChannelType>(
                        createFactoryInstance: () =>
                        s_test.CreateChannelFactory(),
                        destroyFactoryInstanceAsync: async(chf) => await s_test.CloseFactoryAsync(chf),
                        maxPooledObjects: s_test.TestParameters.MaxPooledChannels,
                        createObject: (chf) => s_test.CreateChannel(chf),
                        destroyObjectAsync: (ch) => s_test.CloseChannelAsync(ch),
                        validateObjectInstance: s_test.ValidateChannel),
                    destroyInstanceAsync: (fapoio) => fapoio.DestroyAsync(),
                    instanceValidator: (fapoio) => s_test.ValidateFactory(fapoio.Factory)));
        }
 static RecyclablePooledFactoriesAndChannelsAsync_OpenOnce()
 {
     s_test = new TestTemplate();
     s_recyclablePooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfAsyncThings <
             FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, OpenAsyncOnceChannelWrapper <ChannelType> > >(
             maxSize: 3,     // # of pooled FactoryAndPoolOfItsChannels
             createInstance: () => new FactoryAndPoolOfItsAsyncObjects <ChannelFactory <ChannelType>, OpenAsyncOnceChannelWrapper <ChannelType> >(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstanceAsync: async(chf) =>
                 await s_CloseFactoryStats.CallAsyncFuncAndRecordStatsAsync(s_test.CloseFactoryAsync, chf),
                 maxPooledObjects: 3,     // # of pooled channels within each pooled FactoryAndPoolOfItsAsyncObjects
                 createObject: (chf) =>
                 s_CreateChannelStats.CallFuncAndRecordStats(func: () => new OpenAsyncOnceChannelWrapper <ChannelType>(s_test.CreateChannel(chf))),
                 destroyObjectAsync: async(chWr) =>
                 await s_CloseChannelStats.CallAsyncFuncAndRecordStatsAsync(func: () => s_test.CloseChannelAsync(chWr.Channel))
                 ),
             destroyInstanceAsync: async(_fapoic) => await _fapoic.DestroyAsync()));
 }
 static PooledFactoriesAndChannels()
 {
     s_test = new TestTemplate();
     // we do not expect exceptions here since we're not closing anything during usage
     (s_test as IExceptionPolicy).RelaxedExceptionPolicy = false;
     s_pooledFactoriesAndChannels = StaticDisposablesHelper.AddDisposable(
         new PoolOfThings <FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType> >(
             maxSize: s_test.TestParameters.MaxPooledFactories, // # of pooled FactoryAndPoolOfItsObjects
             createInstance: () => new FactoryAndPoolOfItsObjects <ChannelFactory <ChannelType>, ChannelType>(
                 createFactoryInstance:
                 s_test.CreateChannelFactory,
                 destroyFactoryInstance: (chf) =>
                 s_test.CloseFactory(chf),
                 maxPooledObjects: s_test.TestParameters.MaxPooledChannels, // # of pooled channels within each pooled FactoryAndPoolOfItsObjects
                 createObject: (chf) =>
                 s_test.CreateChannel(chf),
                 destroyObject: (ch) =>
                 s_test.CloseChannel(ch),
                 validateObjectInstance: s_test.ValidateChannel),
             destroyInstance: (fapoio) => fapoio.Destroy(),
             instanceValidator: (fapoiao) => s_test.ValidateFactory(fapoiao.Factory)));
 }
Exemplo n.º 17
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);
        }