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());
        }