private void logData(Object args) { timer.Change(testOpts.reportTime * 1000, Timeout.Infinite); Int64 insertsDone = testResults.GetOpsDone("inserts"); logger.Info("------------------------"); if (testOpts.sharded && !testOpts.singleserver) { var configdb = mongoClient.GetDatabase("config"); var shards = configdb.GetCollection <BsonDocument>("shards"); testOpts.numShards = (int)shards.Count(new BsonDocument()); } logger.Info(string.Format(CultureInfo.CurrentUICulture, "After {0} seconds, {1:#,##0} new records inserted - collection has {2:#,##0} in total \n", testResults.GetSecondsElapsed(), insertsDone, testResults.initialCount + insertsDone)); var results = testResults.GetOpsPerSecondLastInterval(); foreach (var o in POCTestResults.opTypes) { var begin = String.Format(CultureInfo.CurrentUICulture, "{0:#,##0} {1} per second since last report ", results[o], o); var end = ""; var opsDone = testResults.GetOpsDone(o); if (opsDone > 0) { var fastops = 100 - (testResults.GetSlowOps(o) * 100.0) / opsDone; end = String.Format(CultureInfo.CurrentUICulture, "{0:0.##} % in under {1} milliseconds", fastops, testOpts.slowThreshold); } else { end = String.Format(CultureInfo.CurrentUICulture, "{0:0.##} % in under {1} milliseconds", (float)100, testOpts.slowThreshold); } if (o == "rangequeries") { end = end + "\n"; } logger.Info($"{begin} {end}"); } }
public void run(Object arg) { // Use a bulk inserter - even if ony for one List <WriteModel <BsonDocument> > bulkWriter; try { bulkWriter = new List <WriteModel <BsonDocument> >(); int bulkops = 0; int c = 0; logger.Info("Worker thread " + workerID + " Started."); while (testResults.GetSecondsElapsed() < testOpts.duration) { if (isCancelled) { break; } c++; //Timer isn't granullar enough to sleep for each if (testOpts.opsPerSecond > 0) { double threads = testOpts.numThreads; double opsperthreadsecond = testOpts.opsPerSecond / threads; double sleeptimems = 1000 / opsperthreadsecond; if (c == 1) { //First time randomise Random r = new Random(); sleeptimems = r.Next((int)Math.Floor(sleeptimems)); } Thread.Sleep((int)Math.Floor(sleeptimems)); } if (!workflowed) { // Console.Out.WriteLine("Random op"); // Choose the type of op int allops = testOpts.insertops + testOpts.keyqueries + testOpts.updates + testOpts.rangequeries + testOpts.arrayupdates; int randop = getNextVal(allops); if (randop < testOpts.insertops) { insertNewRecord(bulkWriter); bulkops++; } else if (randop < testOpts.insertops + testOpts.keyqueries) { simpleKeyQuery(); } else if (randop < testOpts.insertops + testOpts.keyqueries + testOpts.rangequeries) { rangeQuery(); } else { // An in place single field update // fld 0 - set to random number updateSingleRecord(bulkWriter); if (!testOpts.findandmodify) { bulkops++; } } } else { // Following a preset workflow String wfop = workflow.Substring(workflowStep, workflowStep + 1); // Console.Out.WriteLine("Executing workflow op [" + workflow + // "] " + wfop); if (wfop.Equals("i")) { // Insert a new record, push it's key onto our stack TestRecord r = insertNewRecord(bulkWriter); keyStack.Add((BsonDocument)r.internalDoc.GetValue("_id")); bulkops++; // Console.Out.WriteLine("Insert"); } else if (wfop.Equals("u")) { if (keyStack.Count > 0) { updateSingleRecord(bulkWriter, keyStack[keyStack.Count - 1]); // Console.Out.WriteLine("Update"); if (!testOpts.findandmodify) { bulkops++; } } } else if (wfop.Equals("p")) { // Pop the top thing off the stack if (keyStack.Count > 0) { keyStack.RemoveAt(keyStack.Count - 1); } } else if (wfop.Equals("k")) { // Find a new record an put it on the stack BsonDocument r = simpleKeyQuery(); if (r != null) { keyStack.Add((BsonDocument)r.GetValue("_id")); } } // If we have reached the end of the wfops then reset workflowStep++; if (workflowStep >= workflow.Length) { workflowStep = 0; keyStack = new List <BsonDocument>(); } } if (c % testOpts.batchSize == 0) { if (bulkops > 0) { flushBulkOps(bulkWriter); bulkWriter.Clear(); bulkops = 0; // Check and see if we need to rejig sharding if (numShards != testOpts.numShards) { ReviewShards(); } } } } } catch (Exception e) { logger.Error("Error: " + e.Message); if (testOpts.debug) { logger.Debug(e.StackTrace); } } }