Beispiel #1
0
        public void ExecuteWrite(BenchmarkTest test)
        {
            Current = test;
            string databaseName = test.Database.Name;

            try
            {
                Logger.Info(String.Format("{0} Write() started...", databaseName));
                Current.Write();
                Logger.Info(String.Format("{0} Write() ended...", databaseName));
            }
            catch (Exception exc)
            {
                Logger.Error(String.Format("{0} Write()", databaseName), exc);
                Logger.Error(String.Format("{0} Write() failed...", databaseName));
            }
            finally
            {
                Current = null;

                if (OnTestFinish != null)
                {
                    OnTestFinish(test, TestMethod.Write);
                }
            }
        }
Beispiel #2
0
        public void ExecuteRead(BenchmarkTest test)
        {
            Current = test;
            string databaseName = test.Database.Name;

            try
            {
                Logger.Info(String.Format("{0} Read() started...", databaseName));
                Current.Read();
                Logger.Info(String.Format("Records read: {0}", test.RecordsRead.ToString("N0")));
                Logger.Info(String.Format("{0} Read() ended...", databaseName));
            }
            catch (KeysNotOrderedException exc)
            {
                Logger.Error(String.Format("{0} {1}", databaseName, exc.Message));
                Logger.Info(String.Format("{0} The database does not return the records ordered by key. The test is invalid!...", databaseName));
            }
            catch (Exception exc)
            {
                Logger.Error(String.Format("{0} Read()", databaseName), exc);
                Logger.Error(String.Format("{0} Read() failed...", databaseName));
            }
            finally
            {
                Current = null;

                if (OnTestFinish != null)
                {
                    OnTestFinish(test, TestMethod.Read);
                }
            }
        }
Beispiel #3
0
        public void ExecuteFinish(BenchmarkTest test)
        {
            Current = test;

            try
            {
                Current.Finish();
            }
            catch (Exception exc)
            {
                Logger.Error(String.Format("{0} Finish()", test.Database.Name), exc);
                Logger.Error(String.Format("{0} Finish() failed...", test.Database.Name));
            }
            finally
            {
                Current = null;
            }
        }
Beispiel #4
0
        public void ExecuteInit(BenchmarkTest test)
        {
            Current = test;
            string databaseName = test.Database.Name;

            try
            {
                Logger.Info("");
                Logger.Info(String.Format("{0} Init() started...", databaseName));

                Current.Init();

                Logger.Info(String.Format("{0} Init() ended...", databaseName));
            }
            catch (Exception exc)
            {
                Logger.Error(String.Format("{0} Init()", databaseName), exc);
                Logger.Error(String.Format("{0} Init() failed...", databaseName));
            }
            finally
            {
                Current = null;
            }
        }
        public static JsonObjectCollection ConvertToJson(BenchmarkTest benchmark, ReportType type)
        {
            JsonObjectCollection jsonBenchmark = new JsonObjectCollection("BenchmarkTest");

            // Test info parameters.
            JsonObjectCollection jsonSettings = new JsonObjectCollection("TestInfo");
            jsonSettings.Add(new JsonNumericValue("FlowCount", benchmark.FlowCount));
            jsonSettings.Add(new JsonNumericValue("RecordCount", benchmark.RecordCount));
            jsonSettings.Add(new JsonNumericValue("Randomness", benchmark.Randomness * 100));

            long elapsedTime = benchmark.EndTime.Ticks - benchmark.StartTime.Ticks;
            jsonSettings.Add(new JsonNumericValue("ElapsedTime", new TimeSpan(elapsedTime).TotalMilliseconds));

            JsonObjectCollection jsonDatabase = new JsonObjectCollection("Database");
            jsonDatabase.Add(new JsonStringValue("Name", benchmark.Database.Name));
            jsonDatabase.Add(new JsonStringValue("IndexingTechnology", benchmark.Database.IndexingTechnology.ToString()));
            jsonDatabase.Add(new JsonStringValue("Category", benchmark.Database.Name));

            jsonDatabase.Add(new JsonNumericValue("AverageWriteSpeed", benchmark.GetSpeed(TestMethod.Write)));
            jsonDatabase.Add(new JsonNumericValue("AverageReadSpeed", benchmark.GetSpeed(TestMethod.Read)));
            jsonDatabase.Add(new JsonNumericValue("AverageSecondaryReadSpeed", benchmark.GetSpeed(TestMethod.SecondaryRead)));

            jsonDatabase.Add(new JsonNumericValue("WritePeakMemoryUsage", benchmark.GetPeakWorkingSet(TestMethod.Write) / (1024.0 * 1024.0)));
            jsonDatabase.Add(new JsonNumericValue("ReadPeakMemoryUsage", benchmark.GetPeakWorkingSet(TestMethod.Read) / (1024.0 * 1024.0)));
            jsonDatabase.Add(new JsonNumericValue("SecondaryReadPeakMemoryUsage", benchmark.GetPeakWorkingSet(TestMethod.SecondaryRead) / (1024.0 * 1024.0)));

            jsonDatabase.Add(new JsonNumericValue("Size", benchmark.DatabaseSize / (1024.0 * 1024.0)));

            JsonObjectCollection jsonDatabaseSettings = new JsonObjectCollection("Settings");

            if (benchmark.Database.Settings != null)
            {
                foreach (var item in benchmark.Database.Settings)
                    jsonDatabaseSettings.Add(new JsonStringValue(item.Key, item.Value));
            }

            jsonDatabase.Add(jsonDatabaseSettings);

            // Test results.
            JsonObjectCollection jsonTestData = new JsonObjectCollection("TestResults");
            JsonObject jsonWrite = null;
            JsonObject jsonRead = null;
            JsonObject jsonSecondaryRead = null;

            if (type == ReportType.Summary)
            {
                jsonWrite = new JsonNumericValue("Write", benchmark.GetSpeed(TestMethod.Write));
                jsonRead = new JsonNumericValue("Read", benchmark.GetSpeed(TestMethod.Read));
                jsonSecondaryRead = new JsonNumericValue("SecondaryRead", benchmark.GetSpeed(TestMethod.SecondaryRead));
            }
            else // type == ReportType.Detailed
            {
                // Get statistics and convert them to JSON.
                SpeedStatistics writeStat = benchmark.SpeedStatistics[(int)TestMethod.Write];
                SpeedStatistics readStat = benchmark.SpeedStatistics[(int)TestMethod.Read];
                SpeedStatistics secondaryReadStat = benchmark.SpeedStatistics[(int)TestMethod.SecondaryRead];

                jsonWrite = ConvertStatisticToJson(writeStat, "Write");
                jsonRead = ConvertStatisticToJson(readStat, "Read");
                jsonSecondaryRead = ConvertStatisticToJson(secondaryReadStat, "SecondaryRead");
            }

            jsonTestData.Add(jsonWrite);
            jsonTestData.Add(jsonRead);
            jsonTestData.Add(jsonSecondaryRead);

            // Form the end JSON structure.
            jsonBenchmark.Add(jsonSettings);
            jsonBenchmark.Add(jsonDatabase);
            jsonBenchmark.Add(jsonTestData);

            return jsonBenchmark;
        }
        private void startButton_Click(object sender, EventArgs e)
        {
            // Parse test parameters.
            TableCount = Int32.Parse(cbFlowsCount.Text.Replace(" ", ""));
            RecordCount = Int64.Parse(cbRecordCount.Text.Replace(" ", ""));
            Randomness = trackBar1.Value / 20.0f;

            var databases = ApplicationManager.SelectedDatabases;
            if (databases.Length == 0)
                return;

            History.Clear();
            Cancellation = new CancellationTokenSource();

            foreach (var database in databases)
            {
                var session = new BenchmarkTest(database, TableCount, RecordCount, Randomness, Cancellation);
                History.Add(session);

                try
                {
                    foreach (var directory in Directory.GetDirectories(database.DataDirectory))
                        Directory.Delete(directory, true);

                    foreach (var files in Directory.GetFiles(database.DataDirectory, "*.*", SearchOption.AllDirectories))
                        File.Delete(files);
                }
                catch (Exception exc)
                {
                    Logger.Error("Application exception occured...", exc);
                }
            }

            ApplicationManager.Prepare();

            // Start the benchmark.
            MainTask = Task.Factory.StartNew(DoBenchmark, Cancellation.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
        private void Report(BenchmarkTest benchmark, TestMethod method)
        {
            try
            {
                Action<string, object, Color> updateChart = null;

                StepFrame ActiveStepFrame = ApplicationManager.GetCurrentStepFrame();
                string databaseName = benchmark.Database.Name;
                Color databaseColor = benchmark.Database.Color;

                // Speed chart.
                updateChart = ActiveStepFrame.AddAverageSpeedToBar;
                Report(databaseName, databaseColor, updateChart, benchmark.GetSpeed(method));

                // Size chart.
                updateChart = ActiveStepFrame.AddSizeToBar;
                Report(databaseName, databaseColor, updateChart, benchmark.DatabaseSize / (1024.0 * 1024.0));

                // Time chart.
                updateChart = ActiveStepFrame.AddTimeToBar;
                Report(databaseName, databaseColor, updateChart, new DateTime(benchmark.GetTime(method).Ticks));

                // CPU chart.
                //updateChart = ActiveStepFrame.AddCpuUsageToBar;
                //Report(databaseName, databaseColor, updateChart, benchmark.GetAverageProcessorTime(method));

                // Memory chart.
                updateChart = ActiveStepFrame.AddMemoryUsageToBar;
                Report(databaseName, databaseColor, updateChart, benchmark.GetPeakWorkingSet(method) / (1024.0 * 1024.0));

                // I/O chart.
                //updateChart = ActiveStepFrame.AddIoUsageToBar;
                //Report(databaseName, databaseColor, updateChart, benchmark.GetAverageIOData(method) / (1024.0 * 1024.0));
            }
            catch (Exception exc)
            {
                Logger.Error("Report results failed...", exc);
            }
        }
        private void DoBenchmark()
        {
            BenchmarkSuite testSuite = new BenchmarkSuite();
            testSuite.OnTestFinish += Report;

            try
            {
                foreach (var benchmark in History)
                {
                    if (Cancellation.IsCancellationRequested)
                        break;

                    Current = benchmark;
                    testSuite.ExecuteInit(benchmark);

                    // Write.
                    ApplicationManager.SetCurrentMethod(TestMethod.Write);
                    CurrentStatus = TestMethod.Write.ToString();

                    testSuite.ExecuteWrite(benchmark);

                    // Read.
                    ApplicationManager.SetCurrentMethod(TestMethod.Read);
                    CurrentStatus = TestMethod.Read.ToString();

                    testSuite.ExecuteRead(benchmark);

                    // Secondary Read.
                    ApplicationManager.SetCurrentMethod(TestMethod.SecondaryRead);
                    CurrentStatus = TestMethod.SecondaryRead.ToString();

                    testSuite.ExecuteSecondaryRead(benchmark);

                    // Finish.
                    CurrentStatus = TestMethod.None.ToString();
                    testSuite.ExecuteFinish(benchmark);
                }
            }
            finally
            {
                Current = null;

                if (Cancellation.IsCancellationRequested)
                    History.Clear();
                else
                {
                    if (!(bool)Properties.Settings.Default["HideReportForm"])
                        StartOnlineReport();
                }
            }
        }
        public static void ExportSettings(StreamWriter writer, BenchmarkTest session)
        {
            int tableCount = session.FlowCount;
            long recordCount = session.RecordCount;
            string sequential = session.KeysType.ToString();
            string randomness = string.Format("{0}%", session.Randomness * 100);

            writer.WriteLine("Settings:");
            writer.WriteLine("Table count;Record count;Keys type;Randomness");
            writer.Write(tableCount + ";");
            writer.Write(recordCount + ";");
            writer.Write(sequential + ";");
            writer.WriteLine(randomness + ";");
        }