Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Writes the data contained in the list of RedisTestObj objects in the TestParameters.RandomObjects property.
        ///     Use the TestParameters.GenerateRandomObjects method to populate the RandomObjects property.
        /// </summary>
        public static void PerformanceTestRedisWrite()
        {
            bool success = false;

            Logger.LogSubHeading("Testing Redis data writing performance");

            //-----a----- Get the object properties for our test object
            TestObj rto     = new TestObj();
            string  objName = null;

            PropertyInfo[] objPI = null;
            rw.GetObjectProperties(rto, out objName, out objPI);

            //-----b---- Clear out any existing data ..
            if (TestParameters.DoWrite == true)
            {
                Logger.Log("Clearing any existing data...");
                success = rw.ClearData(TestObj.ObjectName);
            }

            // Write the data to the db and index the required fields
            Logger.Log("Writing data");
            DateTime writeStart = DateTime.Now;

            if (TestParameters.DoWrite == true)
            {
//                PropertyInfo[] pi = rto.GetType().GetProperties();

                //  With a clustered database, we are better off indexing the data first as with most of the indexes, they will need to be clustered on one specific db
                // And index a few of the fields...
                // This means that the actual objects are then concentrated on the remaining cluster nodes...
                Logger.LogSubHeading("Extracting TestInt ...");
                List <KeyValuePair <uint, double> > data = TestObj.BuildNumericList("TestInt", objPI, TestParameters.RandomObjects);
                Logger.Log("Indexing TestInt ...");
                success = success & rw.IndexNumericProperty(TestObj.ObjectName, "TestInt", rto.TestInt.GetType().Name, data);

                GC.Collect();

                Logger.LogSubHeading("Extracting TestLong ...");
                data = TestObj.BuildNumericList("TestLong", objPI, TestParameters.RandomObjects);
                Logger.Log("Indexing TestLong ...");
                success = success & rw.IndexNumericProperty(TestObj.ObjectName, "TestLong", rto.TestLong.GetType().Name, data);

                GC.Collect();

                Logger.LogSubHeading("Extracting TestDouble ...");
                data = TestObj.BuildNumericList("TestDouble", objPI, TestParameters.RandomObjects);
                Logger.Log("Indexing TestDouble ...");
                success = success & rw.IndexNumericProperty(TestObj.ObjectName, "TestDouble", rto.TestDouble.GetType().Name, data);

                GC.Collect();

                // 19-Aug-2016 - there is little merit in extracting bools into indexes in Redis as it's 50:50 - better to just scan the objects!
                //                Logger.Log("Extracting TestBool ...");
                //                data = RedisTestObj.BuildNumericList("TestBool", objPI, TestParameters.RandomObjects);
                //                Logger.Log("Indexing TestBool ...");
                //                success = success & rw.IndexBool(RedisTestObj.ObjectName, "TestBool", data);

                Logger.LogSubHeading("Extracting TestDT ...");
                data = TestObj.BuildNumericList("TestDT", objPI, TestParameters.RandomObjects);
                Logger.Log("Indexing TestDT ...");
                success = success & rw.IndexDateTime(TestObj.ObjectName, "TestDT", data);

                data = null;
                GC.Collect();

                Logger.LogSubHeading("Extracting TestStr ...");
                List <KeyValuePair <uint, string> > data2 = TestObj.BuildStringList("TestStr", objPI, TestParameters.RandomObjects);
                Logger.Log("Indexing TestStr ...");
                success = success & rw.IndexString(TestObj.ObjectName, "TestStr", data2);

                data2 = null;
                GC.Collect();

                // So lets write this to the database
                Logger.LogSubHeading("Indexing completed - now starting to writing the data...");
                success = rw.WriteDataAsHash(TestParameters.RandomObjects);
                Logger.Log("Writing data completed");
            }

            Logger.Log("Finished writing and indexing");
            TestParameters.WriteRedis = DateTime.Now.Subtract(writeStart);

            // 15-Aug-2016 - And lastly - lets make sure we can get all the indexes!!!
            List <DatabaseIndexInfo> riis = rw.IndexFindAll(rto);

            foreach (DatabaseIndexInfo rii in riis)
            {
                Logger.Log("Found index for property " + rii.IndexName + " of type " + rii.IndexType
                           + " and search type " + rii.SearchType.ToString()
                           + " with min of " + rii.MinMax.Key
                           + " and max of " + rii.MinMax.Value);
            }

            string ohFuck = "";
        }