Beispiel #1
0
        private static void RunBencher(IBencher bencher)
        {
            bencher.ResetResults();
            Console.WriteLine("First one warm-up run of each bench type to initialize constructs. Results will not be collected.");
            var result = bencher.PerformSetBenchmark(discardResults: true);

            OriginalController.ReportSetResult(result);
            if (bencher.SupportsEagerLoading)
            {
                result = bencher.PerformEagerLoadBenchmark(discardResults: true);
                OriginalController.ReportEagerLoadResult(result);
                if (PerformAsyncBenchmarks && bencher.SupportsAsync)
                {
                    result = bencher.PerformAsyncEagerLoadBenchmark(discardResults: true);
                    OriginalController.ReportEagerLoadResult(result);
                }
            }
            if (PerformIndividualBenchMarks)
            {
                result = bencher.PerformIndividualBenchMark(KeysForIndividualFetches, discardResults: true);
                OriginalController.ReportIndividualResult(result);
            }
            Console.WriteLine("\nStarting bench runs...");
            if (PerformSetBenchmarks)
            {
                // set benches
                Console.WriteLine("Set fetches");
                Console.WriteLine("-------------------------");
                for (int i = 0; i < LoopAmount; i++)
                {
                    result = bencher.PerformSetBenchmark();
                    OriginalController.ReportSetResult(result);

                    // avoid having the GC collect in the middle of a run.
                    OriginalController.ForceGCCollect();
                }
            }
            if (PerformIndividualBenchMarks)
            {
                // individual benches
                Console.WriteLine("\nSingle element fetches");
                Console.WriteLine("-------------------------");
                for (int i = 0; i < LoopAmount; i++)
                {
                    result = bencher.PerformIndividualBenchMark(KeysForIndividualFetches);
                    OriginalController.ReportIndividualResult(result);

                    // avoid having the GC collect in the middle of a run.
                    OriginalController.ForceGCCollect();

                    if (ApplyAntiFloodForVMUsage)
                    {
                        // sleep is to avoid hammering the network layer on the target server. If the target server is a VM, it might stall once or twice
                        // during benching, which is not what we want at it can skew the results a lot. In a very short time, a lot of queries are executed
                        // on the target server (LoopAmount * IndividualKeysAmount), which will hurt performance on VMs with very fast frameworks in some
                        // cases in some runs (so more than 2 runs are slow).
#pragma warning disable CS0162
                        Thread.Sleep(400);
#pragma warning restore CS0162
                    }
                }
            }
            if (PerformEagerLoadBenchmarks && bencher.SupportsEagerLoading)
            {
                // eager load benches
                Console.WriteLine("\nEager Load fetches");
                Console.WriteLine("-------------------------");
                for (int i = 0; i < LoopAmount; i++)
                {
                    result = bencher.PerformEagerLoadBenchmark();
                    OriginalController.ReportEagerLoadResult(result);

                    // avoid having the GC collect in the middle of a run.
                    OriginalController.ForceGCCollect();
                }
            }
            if (PerformAsyncBenchmarks && bencher.SupportsEagerLoading && bencher.SupportsAsync)
            {
                // eager load benches
                Console.WriteLine("\nAsync eager Load fetches");
                Console.WriteLine("-------------------------");
                for (int i = 0; i < LoopAmount; i++)
                {
                    result = bencher.PerformAsyncEagerLoadBenchmark(discardResults: false);
                    OriginalController.ReportEagerLoadResult(result);

                    // avoid having the GC collect in the middle of a run.
                    OriginalController.ForceGCCollect();
                }
            }
        }
Beispiel #2
0
        private static void RunMemoryAnalysisForBencher(IBencher bencher)
        {
            Console.WriteLine("\nStarting bench runs...");
            BenchResult result;

            if (PerformSetBenchmarks)
            {
                // set benches
                Console.WriteLine("Set fetches");
                Console.WriteLine("-------------------------");
                result = bencher.PerformSetBenchmark(discardResults: true);
                OriginalController.ReportMemoryUsageSetResult(result);
                bencher.MemorySetBenchmarks = result.NumberOfBytesAllocated;
                // avoid having the GC collect in the middle of a run.
                OriginalController.ForceGCCollect();
            }
            if (PerformIndividualBenchMarks)
            {
                // individual benches
                Console.WriteLine("\nSingle element fetches");
                Console.WriteLine("-------------------------");
                result = bencher.PerformIndividualBenchMark(KeysForIndividualFetches, discardResults: true);
                OriginalController.ReportMemoryUsageIndividualResult(result);
                bencher.MemoryIndividualBenchmarks = result.NumberOfBytesAllocated;

                // avoid having the GC collect in the middle of a run.
                OriginalController.ForceGCCollect();

                if (ApplyAntiFloodForVMUsage)
                {
                    // sleep is to avoid hammering the network layer on the target server. If the target server is a VM, it might stall once or twice
                    // during benching, which is not what we want at it can skew the results a lot. In a very short time, a lot of queries are executed
                    // on the target server (LoopAmount * IndividualKeysAmount), which will hurt performance on VMs with very fast frameworks in some
                    // cases in some runs (so more than 2 runs are slow).
#pragma warning disable CS0162
                    Thread.Sleep(400);
#pragma warning restore CS0162
                }
            }
            if (PerformEagerLoadBenchmarks && bencher.SupportsEagerLoading)
            {
                // eager load benches
                Console.WriteLine("\nEager Load fetches");
                Console.WriteLine("-------------------------");
                result = bencher.PerformEagerLoadBenchmark(discardResults: true);
                OriginalController.ReportMemoryUsageEagerLoadResult(result);
                bencher.MemoryEagerLoadBenchmarks = result.NumberOfBytesAllocated;

                // avoid having the GC collect in the middle of a run.
                OriginalController.ForceGCCollect();
            }
            if (PerformAsyncBenchmarks && bencher.SupportsEagerLoading && bencher.SupportsAsync)
            {
                // eager load benches
                Console.WriteLine("\nAsync eager Load fetches");
                Console.WriteLine("-------------------------");
                result = bencher.PerformAsyncEagerLoadBenchmark(discardResults: true);
                OriginalController.ReportMemoryUsageEagerLoadResult(result);
                bencher.MemoryAsyncEagerLoadBenchmarks = result.NumberOfBytesAllocated;

                // avoid having the GC collect in the middle of a run.
                OriginalController.ForceGCCollect();
            }
        }