Exemple #1
0
 public TestResultSet()
 {
     Write = new TestResult();
     Read1 = new TestResult();
     Read2 = new TestResult();
     Read3 = new TestResult();
     Categories = new List<TestResult>();
 }
Exemple #2
0
 private static TestResult ReadItemsById(MongoCollection<Person> collection, int readCount, List<string> ids)
 {
     var time = Stopwatch.StartNew();
     foreach (var id in ids)
     {
         var person = collection.FindOneById(id);
         if (person == null)
             throw new ArgumentException("Id doesn't exist.");
         //Console.WriteLine(person.LastName);
     }
     time.Stop();
     var result = new TestResult { Count = readCount, TotalMs = time.ElapsedMilliseconds };
     Console.WriteLine("Reading total time: {0} ms avg: {1} ms for #records: {2}", result.TotalMs,
                       result.ItemAvgMs, ids.Count);
     return result;
 }
Exemple #3
0
 private static TestResult ReadItemsById(DocumentStore documentStore, List<string> generatedIds)
 {
     var ids = generatedIds.TakeRandom().ToList();
     var time = Stopwatch.StartNew();
     foreach (var id in ids)
     {
         var jsonDocument = documentStore.DatabaseCommands.Get(id);
         // we need to convert it to entity to do the same level of work as mongo test
         var p = jsonDocument.DataAsJson.Deserialize<Person>(documentStore.Conventions);
         if (p.Id != null)
             throw new ArgumentException();
     }
     time.Stop();
     var result = new TestResult { Count = ids.Count, TotalMs = time.ElapsedMilliseconds };
     Console.WriteLine("Reading total time: {0} ms, avg item: {1} ms, #records: {2}",
                       result.TotalMs, result.ItemAvgMs, ids.Count);
     return result;
 }
Exemple #4
0
        public static TestResultSet Run(string databaseName, int readCount, int bulkSize, int generateCount)
        {
            var result = new TestResultSet();
            var generatedIds = new List<string>();
            var time = new Stopwatch();

            using (var documentStore = CreateDocumentStore(databaseName))
            {
                result.Write = GenerateItems(documentStore, bulkSize, generateCount, generatedIds);
            }

            using (var documentStore = CreateDocumentStore(databaseName))
            {
                result.CountItemsMs = ReadDocumentIds(documentStore, new List<string>());
            }

            using (var documentStore = CreateDocumentStore(databaseName))
            {
                result.Read1 = ReadItemsById(documentStore, generatedIds);
            }

            TestSettings.PauseBetweenReads();
            using (var documentStore = CreateDocumentStore(databaseName))
            {
                result.Read2 = ReadItemsById(documentStore, generatedIds);
            }

            TestSettings.PauseBetweenReads();
            using (var documentStore = CreateDocumentStore(databaseName))
            {
                result.Read3 = ReadItemsById(documentStore, generatedIds);
            }

            using (var documentStore = CreateDocumentStore(databaseName))
            {
                using (var session = documentStore.OpenSession())
                {
                    session.Advanced.MaxNumberOfRequestsPerSession = 5000;
                    for (var index = 0; index < TestSettings.NumberOfCategoriesTested; index++)
                    {
                        var category = "Category" + index;
                        time.Restart();
                        var list = session.Query<Person>().Where(i => i.CategoryId == category).Take(5000).ToList();
                        time.Stop();
                        var categoryResult = new TestResult {Count = list.Count, TotalMs = time.ElapsedMilliseconds};
                        result.Categories.Add(categoryResult);
                        Console.WriteLine("Category: {0}, Total time: {1}, readed#: {2}, avg time: {3}", category,
                                          categoryResult.TotalMs, categoryResult.Count, categoryResult.ItemAvgMs);
                    }
                }
            }

            using (var documentStore = CreateDocumentStore(databaseName))
            {
                using (var session = documentStore.OpenSession())
                {
                    time.Restart();
                    var itemCount = session.Query<Person>().Count();
                    time.Stop();
                    result.CountItemsMs = time.ElapsedMilliseconds;
                    Console.WriteLine("Count: {0}, Time: {1} ms", itemCount, time.ElapsedMilliseconds);
                    //CategoryCounts(session);
                }
            }

            using (var documentStore = CreateDocumentStore(databaseName))
            {
                Console.WriteLine("Deleting database...");
                documentStore.DatabaseCommands.ForSystemDatabase().Delete("Raven/Databases/" + databaseName, null);
                var dbDir = Path.Combine(ConfigurationManager.AppSettings["RavenDbPath"], databaseName);
                documentStore.Dispose();
                for (var i = 0; i < 1; i++)
                {
                    try
                    {
                        Directory.Delete(dbDir);
                        Console.WriteLine("Database deleted");
                        break;
                    }
                    catch (Exception)
                    {
                    }
                    Console.WriteLine("Could not delete database");
                    Thread.Sleep(5000);
                }
            }
            return result;
        }
Exemple #5
0
        private static TestResult GenerateItems(IDocumentStore documentStore, int bulkSize, int generateCount, List<string> generatedIds)
        {
            var time = new Stopwatch();
            var writeResult = new TestResult();
            var totalRecords = 0;
            var generatingTotalTime = 0L;

            foreach (var chunkSize in ChunkUtils.GetChunks(generateCount, bulkSize))
            {
                //var items = Enumerable.Range(0, chunkSize).Select(PersonGenerator.Create).ToList();

                time.Restart();
                using (var bulkInsert = documentStore.BulkInsert())
                {
                    for (var i = 0; i < chunkSize; i++)
                    {
                        var item = PersonGenerator.Create();
                        bulkInsert.Store(item);
                        generatedIds.Add(item.Id);
                    }
                }
                time.Stop();
                generatingTotalTime += time.ElapsedMilliseconds;

                totalRecords += chunkSize;
                Console.WriteLine("Written {0} total: {1} records in: {2} ms", chunkSize, totalRecords,
                                  time.ElapsedMilliseconds);
            }
            writeResult.Count = generateCount;
            writeResult.TotalMs = generatingTotalTime;
            Console.WriteLine("Writing total time: {0} ms, avg item: {1} ms", generatingTotalTime, writeResult.ItemAvgMs);

            Console.WriteLine("Waiting for rebuilding indexes...");
            Thread.Sleep(TestSettings.WaitForRebuildIndexesMs);
            return writeResult;
        }