Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Random tests - returns a set of IDs
        /// </summary>
        public static List <uint> RedisPerformanceComparisonCustom()
        {
            bool success = false;

            // Pause to enable GC
            GC.Collect();
            Thread.Sleep(3000);

            Logger.LogSubHeading("Starting Redis performance comparison of CUSTOM code ...");

            HashSet <uint> objIDs = new HashSet <uint>();
            int            i      = 0;


            string objectName             = TestObj.ObjectName; // "RedisTestObj";
            List <DatabaseIndexInfo> riis = rw.IndexFindAll(new TestObj());

            //-----2----- Test RedisWrapper
            {
                Logger.Log("Now testing the RedisWrapper...");
                DateTime RVTest = DateTime.Now;
                List <Task <List <uint> > > rvTasks2 = new List <Task <List <uint> > >();
                //List<Task<List<uint>>> rvTasks3 = new List<Task<List<uint>>>();

                // Firing off the search requests ...
                Logger.Log("Firing off the search requests ...");
                int chunkSize = 10000;
                if (chunkSize < 10)
                {
                    chunkSize = 10;
                }
                else if (chunkSize > TestParameters.PatternsToSearchFor.Count)
                {
                    chunkSize = TestParameters.PatternsToSearchFor.Count;
                }
                int startIndex = 0;


                {
                    rvTasks2 = new List <Task <List <uint> > >();
                    for (i = startIndex; i < startIndex + chunkSize; i++)
                    {
                        //rvTasks2.Add(rw.SearchObjectsStart(objectName, TestParameters.PatternsToSearchFor[i], true));
                        rvTasks2.Add(rw.SearchObjects(objectName, TestParameters.PatternsToSearchFor[i], true));

                        RedisWrapper.DebugStart(rvTasks2[rvTasks2.Count - 1].Id, TestParameters.PatternsToSearchFor[i], riis);

                        Logger.Log(i, 100, TestParameters.NumSearchPatterns);
                    }
                    Logger.Log(i, 1, TestParameters.NumSearchPatterns);

                    //                    List<List<uint>> results = rw.AwaitResultsSeparately(rvTasks2);

                    ///////////////////////////////////////////////// Might need to minimise the memory here ...
                    //rvTasks3 = new List<Task<List<uint>>>();
                    //for (i = startIndex; i < startIndex + chunkSize; i++) {
                    //                        rvTasks3.Add(rw.SearchObjectsFinish(objectName, TestParameters.PatternsToSearchFor[i], results[i], true));
                    //                        // NEEED TO UPDATE THE DEBUG HERE
                    //                        Logger.Log(i, 100, TestParameters.NumSearchPatterns);
                    //                    }
                    //                    Logger.Log(i, 1, TestParameters.NumSearchPatterns);

                    //objIDs.UnionWith(rw.AwaitResults(rvTasks3));
                    objIDs.UnionWith(rw.AwaitResults(rvTasks2));
                }

                while (i < TestParameters.NumSearchPatterns)
                {
                    while (i % chunkSize != 0)
                    {
                        Thread.Sleep(10);
                    }
                    startIndex += chunkSize;
                    {
                        //Logger.Log("\nExtracting chunk starting " + startIndex + " and length " + chunkSize + " ...");
                        rvTasks2 = new List <Task <List <uint> > >();
                        for (i = startIndex; i < startIndex + chunkSize; i++)
                        {
                            //rvTasks2.Add(rw.SearchObjectsStart(objectName, TestParameters.PatternsToSearchFor[i], true));
                            rvTasks2.Add(rw.SearchObjects(objectName, TestParameters.PatternsToSearchFor[i], true));

                            RedisWrapper.DebugStart(rvTasks2[rvTasks2.Count - 1].Id, TestParameters.PatternsToSearchFor[i], riis);

                            Logger.Log(i, 100, TestParameters.NumSearchPatterns);
                        }
                        Logger.Log(i, 1, TestParameters.NumSearchPatterns);

                        //List<List<uint>> results = rw.AwaitResultsSeparately(rvTasks2);

                        ///////////////////////////////////////////////// Might need to minimise the memory here ...
                        //rvTasks3 = new List<Task<List<uint>>>();
                        //for (i = startIndex; i < startIndex + chunkSize; i++) {
                        //rvTasks3.Add(rw.SearchObjectsFinish(objectName, TestParameters.PatternsToSearchFor[i], results[i], true));
                        // NEEED TO UPDATE THE DEBUG HERE
                        //Logger.Log(i, 100, TestParameters.NumSearchPatterns);
                        //}
                        //Logger.Log(i, 1, TestParameters.NumSearchPatterns);

                        //objIDs.UnionWith(rw.AwaitResults(rvTasks3));
                        objIDs.UnionWith(rw.AwaitResults(rvTasks2));
                    }
                }

                // and now here lets sort the Debug results and have a look at the outcome........
                if (RedisWrapper.DoDebug == true)
                {
                    RedisWrapper.Debug.Sort(DatabaseDebug.Sort("Duration", true));
                    //RedisWrapper.Debug.Add(new RedisDebug(rvTasks2[rvTasks2.Count - 1].Id, DateTime.Now, TestParameters.PatternsToSearchFor[i]));

                    foreach (DatabaseDebug rb in RedisWrapper.Debug)
                    {
                        if (rb.IsFaulted == true)
                        {
                            Logger.LogWarning(rb.SearchPatternsAsText + " and took " + rb.Duration + "ms. ");
                        }
                        else
                        {
                            Logger.Log(rb.SearchPatternsAsText + " and took " + rb.Duration + "ms. ");
                        }
                    }
                }


                TimeSpan RVTested2 = DateTime.Now.Subtract(RVTest);
                Logger.Log("");
                Logger.Log("Total num objects = " + objIDs.Count.ToString("N0") + ".  And number of faults observed = XXXXXXXXXX.");
                Logger.Log("Time to process:" + RVTested2.TotalSeconds);
            }

            // Pause to enable GC
            Logger.Log("Pausing to enable garbage collection ...");
            GC.Collect();
            Thread.Sleep(3000);


            return(objIDs.ToList());
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="chunkSize"></param>
        /// <param name="startIndex"></param>
        public static void PerformanceTestRedisSearchThreadBlock(int chunkSize, int startIndex)
        {
            TestObj rto = new TestObj();

            int i = startIndex;

            if ((startIndex + chunkSize) >= TestParameters.PatternsToSearchFor.Count)
            {
                chunkSize = TestParameters.PatternsToSearchFor.Count - startIndex;
            }

            Logger.Log("Starting chunk with index " + startIndex + " and size " + chunkSize + " ...");

            //-----a----- Fire off the search queries
            List <Task <List <uint> > > tasks = new List <Task <List <uint> > >();

            //List<Task<List<uint>>> tasksS = new List<Task<List<uint>>>();
            //List<Task<List<uint>>> tasksF = new List<Task<List<uint>>>();


            for (i = startIndex; i < (startIndex + chunkSize); i++)
            {
                List <DatabaseSearchPattern> rsps = TestParameters.PatternsToSearchFor[i];
                //tasksS.Add(rw.SearchObjectsStart(RedisTestObj.ObjectName, rsps, true));
                tasks.Add(rw.SearchObjects(TestObj.ObjectName, rsps, true));

                //RedisWrapper.DebugStart(tasksS[tasksS.Count - 1].Id, rsps, RedisWrapper.IndexInfo);
                RedisWrapper.DebugStart(tasks[tasks.Count - 1].Id, rsps, RedisWrapper.IndexInfo);

                Logger.Log(i - startIndex, 100, chunkSize);
            }
            Logger.Log(i - startIndex, 100, chunkSize);

            //Thread.Sleep(1000);

            //List<List<uint>> results = rw.AwaitResultsSeparately(tasksS);

            //Logger.Log("\nAnd now finishing the searching of these objects ...");
            ///////////////////////////////////////////////// Might need to minimise the memory here ...
            //for (i = startIndex; i < startIndex + chunkSize; i++) {
            // tasksF.Add(rw.SearchObjectsFinish(RedisTestObj.ObjectName, TestParameters.PatternsToSearchFor[i], results[i], true));
            // NEEED TO UPDATE THE DEBUG HERE
            //Logger.Log(i, 100, TestParameters.NumSearchPatterns);
            //}
            //Logger.Log(i, 1, TestParameters.NumSearchPatterns);


            //-----b----- Now lets wait for our array of IDs
            // Now do the union...

            //List<uint> allIDs = rw.AwaitResults(tasksF);
            int previousCount = IDs.Count;

            lock (IDs) {
                //IDs.UnionWith(allIDs);
                IDs.UnionWith(rw.AwaitResults(tasks));
            }


            //HashSet<long> allIDs = RedisWrapper.AwaitResults(tasks).Result;
            //HashSet<long> allIDs = RedisWrapper.AwaitResults(tasks);
            //Logger.Log("Found "+allIDs.Count+" ids matching our search patterns... ");

            // Note that this will now be cumulative ..
            Logger.Log("Found " + (IDs.Count - previousCount) + " NEW ids matching our search patterns (and " + IDs.Count + " now in total)... ");


            // Do the printing of all the specific queries only if DoDebug is set to true ....
            if (RedisWrapper.DoDebug == true)
            {
                RedisWrapper.Debug.Sort(DatabaseDebug.Sort("Duration", true));

                int counter = 0;
                foreach (DatabaseDebug rb in RedisWrapper.Debug)
                {
                    if (rb.IsFaulted == true)
                    {
                        Logger.LogWarning(rb.SearchPatternsAsText + " and took " + rb.Duration + "ms. ");
                    }
                    else
                    {
                        Logger.Log("Search " + (++counter) + " " + rb.SearchPatternsAsText + " and took " + rb.Duration + "ms. ");
                    }
                }
            }


            //HashSet<long> ids = null;
            //if ( allIDs.Count > TestParameters.MaxNumObjects) {
            //    foreach( long id in allIDs) {
            //        ids.Add(id);
            //        if (ids.Count >= TestParameters.MaxNumObjects) {
            //            break;
            //        }
            //    }
            //    allIDs = null;
            //} else {
            //    ids = allIDs;
            //}



            //-----d-----
//            if (TestParameters.UseThreading == true) {
//                DNThreadManager.IncrementNumIterationsCompleted();
//            } else {
//                Logger.Log(i, 100, chunkSize);
//            }

            NumCompleted += chunkSize;


            //            if (TestParameters.UseThreading == true) {
            //                DNThreadManager.IncrementNumIterationsCompleted(chunkSize);
            //            } else {

            //            }

            Logger.Log("");
//            Logger.Log(log.ToString());
        }