public static async Task DuplicateAsync(bool parallel) { var mongoDriver = new MongoDbDriver( ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User"); var mongoDriver2 = new MongoDbDriver( ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User2"); await mongoDriver2.Database.DropCollectionAsync("User2"); var timer = new Stopwatch(); timer.Start(); var tasks = Enumerable.Range(0, 128).Select(async i => { var uids = await LoadUids(mongoDriver.Collection, i); foreach (var uid in uids) { var user = await mongoDriver.LoadUserAsync(uid); await mongoDriver2.CreateUserAsync(uid, user); } return(uids.Count); }); var totalCount = await WaitForComplete(tasks, parallel); var elapsed = timer.Elapsed.TotalSeconds; var rowPerSec = totalCount / timer.Elapsed.TotalSeconds; Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}"); }
public static async Task SaveComplexAsync(bool parallel, bool full) { var mongoDriver2 = new MongoDbDriver( ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User2"); var timer = new Stopwatch(); timer.Start(); var tasks = Enumerable.Range(0, 128).Select(async i => { var uids = await LoadUids(mongoDriver2.Collection, i); foreach (var uid in uids) { var user = await mongoDriver2.LoadUserAsync(uid); user.SetDefaultTracker(); user.Data.Gold += 1; user.Data.Gold -= 1; foreach (var key in user.Items.Keys.ToList()) { var item = user.Items[key]; user.Items[key] = item; if (full == false) { break; } } foreach (var key in user.Teams.Keys.ToList()) { var team = user.Teams[key]; user.Teams[key] = team; if (full == false) { break; } } await mongoDriver2.SaveUserAsync(uid, user.Tracker); } return(uids.Count); }); var totalCount = await WaitForComplete(tasks, parallel); var elapsed = timer.Elapsed.TotalSeconds; var rowPerSec = totalCount / timer.Elapsed.TotalSeconds; Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}"); }
public static async Task ReadAsync(bool parallel) { var mongoDriver = new MongoDbDriver( ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User"); var timer = new Stopwatch(); timer.Start(); var tasks = Enumerable.Range(0, 128).Select(async i => { var uids = await LoadUids(mongoDriver.Collection, i); foreach (var uid in uids) await mongoDriver.LoadUserAsync(uid); return uids.Count; }); var totalCount = await WaitForComplete(tasks, parallel); var elapsed = timer.Elapsed.TotalSeconds; var rowPerSec = totalCount / timer.Elapsed.TotalSeconds; Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}"); }
public static async Task SaveComplexAsync(bool parallel, bool full) { var mongoDriver2 = new MongoDbDriver( ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User2"); var timer = new Stopwatch(); timer.Start(); var tasks = Enumerable.Range(0, 128).Select(async i => { var uids = await LoadUids(mongoDriver2.Collection, i); foreach (var uid in uids) { var user = await mongoDriver2.LoadUserAsync(uid); user.SetDefaultTracker(); user.Data.Gold += 1; user.Data.Gold -= 1; foreach (var key in user.Items.Keys.ToList()) { var item = user.Items[key]; user.Items[key] = item; if (full == false) break; } foreach (var key in user.Teams.Keys.ToList()) { var team = user.Teams[key]; user.Teams[key] = team; if (full == false) break; } await mongoDriver2.SaveUserAsync(uid, user.Tracker); } return uids.Count; }); var totalCount = await WaitForComplete(tasks, parallel); var elapsed = timer.Elapsed.TotalSeconds; var rowPerSec = totalCount / timer.Elapsed.TotalSeconds; Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}"); }