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; }
public static TestResultSet Run(string databaseName, int readCount, int? bulkSize = null, int? generateCount = null) { var result = new TestResultSet(); Console.WriteLine("Initializing store..."); var client = new MongoClient("mongodb://127.0.0.1/?safe=true"); var db = client.GetServer().GetDatabase(databaseName); Console.WriteLine("Initialized."); var collection = db.GetCollection<Person>("Person"); collection.EnsureIndex("CategoryId"); var totalTime = Stopwatch.StartNew(); var time = new Stopwatch(); time.Restart(); var generatedIds = new List<string>(); if (generateCount != null && bulkSize != null) { var totalRecords = 0; var generatingTotalTime = 0L; foreach (var chunkSize in ChunkUtils.GetChunks(generateCount.Value, bulkSize.Value)) { time.Restart(); for (var i = 0; i < chunkSize; i++) { var item = PersonGenerator.Create(); collection.Save(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); } result.Write.Count = generateCount; result.Write.TotalMs = generatingTotalTime; Console.WriteLine("Writing total time: {0} ms, avg item: {1} ms", generatingTotalTime, generatingTotalTime / generateCount); Console.Write("Waiting for rebuilding indexes..."); Thread.Sleep(TestSettings.WaitForRebuildIndexesMs); } List<string> ids; if (generatedIds.Count == 0) { ids = Profiler.Measure("Reads ids", () => collection .FindAll() .AsQueryable() .Take(readCount) .Select(i => i.Id) .ToList()); } else { ids = generatedIds; } Console.WriteLine("Reading count: {0}, ids.count: {1}", readCount, ids.Count); ids = ids.TakeRandom().ToList(); result.Read1 = ReadItemsById(collection, readCount, ids); TestSettings.PauseBetweenReads(); result.Read2 = ReadItemsById(db.GetCollection<Person>("Person"), readCount, ids); TestSettings.PauseBetweenReads(); result.Read3 = ReadItemsById(db.GetCollection<Person>("Person"), readCount, ids); for (var index = 0; index < TestSettings.NumberOfCategoriesTested; index++) { var category = "Category" + index; time.Restart(); var list = collection.FindAll().AsQueryable().Where(i => i.CategoryId == category).ToList();//.Find(Query.EQ("CategoryId", category)).ToList(); time.Stop(); Console.WriteLine("Category: {0}, Total time: {1}, readed#: {2}, avg time: {3}", category, time.ElapsedMilliseconds, list.Count, list.Count == 0 ? (object) null : time.ElapsedMilliseconds / list.Count); result.Categories.Add(new TestResult{ Count = list.Count, TotalMs = time.ElapsedMilliseconds}); } client.GetServer().DropDatabase(databaseName); return result; }
public static TestResultSet RunReadTest(string databaseName, int readCount) { var result = new TestResultSet(); var ids = new List<string>(); using (var documentStore = CreateDocumentStore(databaseName, false)) { result.CountItemsMs = ReadDocumentIds(documentStore, ids, readCount); } using (var documentStore = CreateDocumentStore(databaseName, false)) { result.Read1 = ReadItemsById(documentStore, ids); } return result; }