diff --git a/Mongo.Migration.Demo.Migrations/Cars/M00/M001_RenameDorsToDoors.cs b/Mongo.Migration.Demo.Migrations/Cars/M00/M001_RenameDorsToDoors.cs index e6a63d9..a9f553d 100644 --- a/Mongo.Migration.Demo.Migrations/Cars/M00/M001_RenameDorsToDoors.cs +++ b/Mongo.Migration.Demo.Migrations/Cars/M00/M001_RenameDorsToDoors.cs @@ -4,7 +4,7 @@ using Mongo.Migration.Migrations.Attributes; using MongoDB.Bson; -namespace Mongo.Migration.Demo.Migrations.Cars.M00 +namespace Mongo.Migration.Demo.MongoMigrations.Cars.M00 { [MigrationMaker] public class M001_RenameDorsToDoors : Migration diff --git a/Mongo.Migration.Demo.Migrations/Cars/M01/M011_RemoveUnnecessaryField.cs b/Mongo.Migration.Demo.Migrations/Cars/M01/M011_RemoveUnnecessaryField.cs index 38abc5b..c031f7b 100644 --- a/Mongo.Migration.Demo.Migrations/Cars/M01/M011_RemoveUnnecessaryField.cs +++ b/Mongo.Migration.Demo.Migrations/Cars/M01/M011_RemoveUnnecessaryField.cs @@ -4,7 +4,7 @@ using Mongo.Migration.Migrations.Attributes; using MongoDB.Bson; -namespace Mongo.Migration.Demo.Migrations.Cars.M01 +namespace Mongo.Migration.Demo.MongoMigrations.Cars.M01 { [MigrationMaker] public class M011_RemoveUnnecessaryField : Migration diff --git a/Mongo.Migration.Demo.Performance.Console/Program.cs b/Mongo.Migration.Demo.Performance.Console/Program.cs index 8b4e66d..4d3afb1 100644 --- a/Mongo.Migration.Demo.Performance.Console/Program.cs +++ b/Mongo.Migration.Demo.Performance.Console/Program.cs @@ -19,6 +19,16 @@ static Program() _client = new MongoClient(runner.ConnectionString); } + #region private + + private const int DOCUMENT_COUNT = 10000; + + private const string DATABASE_NAME = "PerformanceTestCar"; + + private const string COLLECTION_NAME = "Test"; + + private const int TOLERANCE_MS = 200; + private static void InsertMany(int number, bool withVersion) { var documents = new List(); @@ -37,7 +47,7 @@ private static void InsertMany(int number, bool withVersion) documents.Add(document); } - _client.GetDatabase("PerformanceTestCar").GetCollection("Tests").InsertManyAsync(documents) + _client.GetDatabase(DATABASE_NAME).GetCollection(COLLECTION_NAME).InsertManyAsync(documents) .Wait(); } @@ -45,41 +55,46 @@ private static void MigrateAll(bool withVersion) { if (withVersion) { - var versionedCollectin = _client.GetDatabase("PerformanceTestCar") - .GetCollection("Tests"); + var versionedCollectin = _client.GetDatabase(DATABASE_NAME) + .GetCollection(COLLECTION_NAME); var versionedResult = versionedCollectin.FindAsync(_ => true).Result.ToListAsync().Result; return; } - var collection = _client.GetDatabase("PerformanceTestCar") - .GetCollection("Tests"); + var collection = _client.GetDatabase(DATABASE_NAME) + .GetCollection(COLLECTION_NAME); var result = collection.FindAsync(_ => true).Result.ToListAsync().Result; } private static void AddDocumentsToCache() { - InsertMany(10000, false); + InsertMany(DOCUMENT_COUNT, false); MigrateAll(false); } private static void ClearCollection() { - _client.GetDatabase("PerformanceTestCar").DropCollection("Tests"); + _client.GetDatabase(DATABASE_NAME).DropCollection(COLLECTION_NAME); } + #endregion + private static void Main(string[] args) { + // Arrange // Worm up MongoCache ClearCollection(); AddDocumentsToCache(); ClearCollection(); + // Act // Measure time of MongoDb processing without Mongo.Migration var sw = new Stopwatch(); sw.Start(); - InsertMany(10000, false); + InsertMany(DOCUMENT_COUNT, false); MigrateAll(false); sw.Stop(); + ClearCollection(); // Measure time of MongoDb processing without Mongo.Migration @@ -87,7 +102,7 @@ private static void Main(string[] args) var swWithMigration = new Stopwatch(); swWithMigration.Start(); - InsertMany(10000, true); + InsertMany(DOCUMENT_COUNT, true); MigrateAll(true); swWithMigration.Stop(); @@ -96,7 +111,9 @@ private static void Main(string[] args) var result = swWithMigration.ElapsedMilliseconds - sw.ElapsedMilliseconds; System.Console.WriteLine( - $"MongoDB: {sw.ElapsedMilliseconds}, Mongo.Migration: {swWithMigration.ElapsedMilliseconds}, Diff: {result}"); + $"MongoDB: {sw.ElapsedMilliseconds}, Mongo.Migration: {swWithMigration.ElapsedMilliseconds}, Diff: {result} (Tolerance: {TOLERANCE_MS}), Documents: {DOCUMENT_COUNT}, Migrations per Document: 2"); + + System.Console.ReadLine(); } } } \ No newline at end of file