public POCTestReporter(POCTestResults r, MongoClient mc, POCTestOptions t) { mongoClient = mc; testResults = r; testOpts = t; logger = LogManager.GetLogger("POCTestReporter"); }
public void RunLoad(POCTestOptions testOpts, POCTestResults testResults) { PrepareSystem(testOpts, testResults); // Report on progress by looking at testResults var reporter = new POCTestReporter(testResults, mongoClient, testOpts); try { // Using a thread pool we keep filled // +1 for the reporter thread the timer will use ThreadPool.SetMaxThreads(testOpts.numThreads + 1, testOpts.numThreads + 1); // Allow for multiple clients to run - // Check for testOpts.threadIdStart - this should be an Int32 to start // the 'workerID' for each set of threads. int threadIdStart = testOpts.threadIdStart; //Console.Out.WriteLine("threadIdStart="+threadIdStart); reporter.run(); var workers = new List <MongoWorker>(); var tasks = new List <Task>(); for (int i = threadIdStart; i < (testOpts.numThreads + threadIdStart); i++) { var worker = new MongoWorker(mongoClient, testOpts, testResults, i); var task = new Task(new Action(() => worker.run(null))); workers.Add(worker); tasks.Add(task); task.Start(); } Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; if (isCancelled) { return; } isCancelled = true; foreach (var worker in workers) { worker.Cancel(); } reporter.Cancel(); logger.Info("Cancellation requested - waiting on threads to finish"); }; Task.WaitAll(tasks.ToArray()); //Console.Out.WriteLine("All Threads Complete: " + b); } catch (Exception e) { Console.Out.WriteLine(e.Message); } finally { // do const report reporter.constReport(); } }
public static void Main(String[] args) { var result = Parser.Default.ParseArguments <POCTestOptions>(args) .WithNotParsed(errors => { foreach (var error in errors) { switch (error.Tag) { case ErrorType.HelpRequestedError: case ErrorType.HelpVerbRequestedError: case ErrorType.VersionRequestedError: break; default: Console.Error.WriteLine(error); break; } } }) .WithParsed(testOpts => { ConfigureLogging(testOpts); try { logger = LogManager.GetLogger("POCDriver"); logger.Info("MongoDB Proof Of Concept - Load Generator"); if (testOpts.arrayupdates > 0 && (testOpts.arrays[0] < 1 || testOpts.arrays[1] < 1)) { logger.Info("You must specify an array size to update arrays"); return; } if (testOpts.printOnly) { printTestBsonDocument(testOpts); return; } var testResults = new POCTestResults(); var runner = new LoadRunner(testOpts); runner.RunLoad(testOpts, testResults); } catch (Exception e) { logger.Error(e.Message); return; } }); }
public MongoWorker(MongoClient c, POCTestOptions t, POCTestResults r, int id) { logger = LogManager.GetLogger($"MongoWorker {id}"); mongoClient = c; //Ping c.GetDatabase("admin").RunCommand <BsonDocument>(new BsonDocument("ping", 1)); testOpts = t; testResults = r; workerID = id; var db = mongoClient.GetDatabase(testOpts.namespaces[0]); maxCollections = testOpts.numcollections; String baseCollectionName = testOpts.namespaces[1]; if (maxCollections > 1) { colls = new List <IMongoCollection <BsonDocument> >(); lastCollection = 0; for (int i = 0; i < maxCollections; i++) { String str = baseCollectionName + i; colls.Add(db.GetCollection <BsonDocument>(str)); } } else { coll = db.GetCollection <BsonDocument>(baseCollectionName); } // id sequence = getHighestID(); ReviewShards(); rng = new Random(); if (testOpts.zipfsize > 0) { zipfian = true; zipf = new Zipf(0.99, testOpts.zipfsize); } if (!string.IsNullOrWhiteSpace(testOpts.workflow)) { workflow = testOpts.workflow; workflowed = true; keyStack = new List <BsonDocument>(); } }
private void PrepareSystem(POCTestOptions testOpts, POCTestResults results) { IMongoDatabase db; IMongoCollection <BsonDocument> coll; //Create indexes and suchlike db = mongoClient.GetDatabase(testOpts.namespaces[0]); coll = db.GetCollection <BsonDocument>(testOpts.namespaces[1]); if (testOpts.emptyFirst) { db.DropCollection(testOpts.namespaces[1]); } TestRecord testRecord = new TestRecord(testOpts); List <String> fields = testRecord.listFields(); for (int x = 0; x < testOpts.secondaryidx; x++) { coll.Indexes.CreateOne(new BsonDocument(fields[x], 1)); } if (testOpts.fulltext) { var options = new CreateIndexOptions(); options.Background = true; var weights = new BsonDocument(); weights.Add("lorem", 15); weights.Add("_fulltext.text", 5); options.Weights = weights; var index = new BsonDocument(); index.Add("$**", "text"); coll.Indexes.CreateOne(index, options); } results.initialCount = coll.Count(new BsonDocument()); //Now have a look and see if we are sharded //And how many shards and make sure that the collection is sharded if (!testOpts.singleserver) { ConfigureSharding(testOpts); } }