Skip to content

Commit

Permalink
changed console to be equel to test
Browse files Browse the repository at this point in the history
  • Loading branch information
SRoddis committed Jul 9, 2017
1 parent 05c5a73 commit 650afec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Car>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Car>
Expand Down
37 changes: 27 additions & 10 deletions Mongo.Migration.Demo.Performance.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BsonDocument>();
Expand All @@ -37,57 +47,62 @@ private static void InsertMany(int number, bool withVersion)
documents.Add(document);
}

_client.GetDatabase("PerformanceTestCar").GetCollection<BsonDocument>("Tests").InsertManyAsync(documents)
_client.GetDatabase(DATABASE_NAME).GetCollection<BsonDocument>(COLLECTION_NAME).InsertManyAsync(documents)
.Wait();
}

private static void MigrateAll(bool withVersion)
{
if (withVersion)
{
var versionedCollectin = _client.GetDatabase("PerformanceTestCar")
.GetCollection<Car>("Tests");
var versionedCollectin = _client.GetDatabase(DATABASE_NAME)
.GetCollection<Car>(COLLECTION_NAME);
var versionedResult = versionedCollectin.FindAsync(_ => true).Result.ToListAsync().Result;
return;
}

var collection = _client.GetDatabase("PerformanceTestCar")
.GetCollection<CarWithoutVersion>("Tests");
var collection = _client.GetDatabase(DATABASE_NAME)
.GetCollection<CarWithoutVersion>(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
MongoMigration.Initialize();

var swWithMigration = new Stopwatch();
swWithMigration.Start();
InsertMany(10000, true);
InsertMany(DOCUMENT_COUNT, true);
MigrateAll(true);
swWithMigration.Stop();

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

0 comments on commit 650afec

Please sign in to comment.