Created
September 26, 2016 19:02
-
-
Save jasonmimick/1e745900e46bd4a1b38fc1efcb82746b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connectionString = "mongodb://localhost:12831/test"; | |
var dbName = "test"; | |
var baseCollectionName = "Foo"; | |
var numCollections = 2;//3; | |
var sleepTimeMs = 1000*60; | |
var shouldStop = function() { | |
return ls().indexOf("./stop-textTerms")!=-1 | |
} | |
// Called on own thread, pass data in through TestData | |
// object | |
var textTermsWorker = function() { | |
var numNaps = 0; | |
var coll = TestData.targetCollection; | |
print("textTermsWorker: " + coll ); | |
var snoozeTimeMs = TestData.sleepTimeMs; | |
var conn = new Mongo(TestData.connectionString); | |
printjson(conn); | |
var db = conn.getDB(TestData.dbName); | |
printjson(db); | |
var shouldStop = TestData.shouldStop; | |
while ( !shouldStop() ) { | |
print("calling { \"textTermBuild2\" : " + coll + "}" ); | |
var result = db.runCommand( { "textTermBuild2" : coll } ); | |
printjson(result); | |
print("snoozing..." + coll ); | |
sleep(snoozeTimeMs); | |
numNaps++; | |
} | |
print(coll + " got stop."); | |
} | |
var subshells = []; | |
for(var i=0;i<numCollections;i++) { | |
var TestData = {}; | |
TestData.threadnum = i; | |
TestData.targetCollection = baseCollectionName + "_" + i; | |
TestData.connectionString = connectionString; | |
TestData.shouldStop = shouldStop; | |
TestData.sleepTimeMs = sleepTimeMs; | |
TestData.dbName = dbName; | |
var thread = startParallelShell(textTermsWorker, undefined, false); | |
subshells.push( thread ); | |
} | |
// wait for threads to complete | |
for (var i=0;i<numCollections;i++) { | |
subshells[i](); | |
} | |
print("got stop"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment