mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
timing and tests
This commit is contained in:
parent
f694624575
commit
76e80e83e7
24
db/mr.cpp
24
db/mr.cpp
@ -35,7 +35,7 @@ namespace mongo {
|
||||
string tempCollectionName( string coll ){
|
||||
static int inc = 1;
|
||||
stringstream ss;
|
||||
ss << database->name << ".mr." << coll << "." << time(0) << inc++;
|
||||
ss << database->name << ".mr." << coll << "." << time(0) << "." << inc++;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -86,7 +86,8 @@ namespace mongo {
|
||||
}
|
||||
|
||||
bool run(const char *dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
|
||||
|
||||
Timer t;
|
||||
|
||||
string ns = database->name + '.' + cmdObj.firstElement().valuestr();
|
||||
log(1) << "mr ns: " << ns << endl;
|
||||
|
||||
@ -104,15 +105,9 @@ namespace mongo {
|
||||
try {
|
||||
s->execSetup( (string)"tempcoll = db[\"" + resultCollShort + "\"];" , "tempcoll1" );
|
||||
|
||||
s->execSetup( "$num = 0;"
|
||||
"emit = function( k , v ){"
|
||||
" $num = $num + 1;"
|
||||
" if ( $num % 100 > 0 ){"
|
||||
" tempcoll.insert( { key : k , value : v } );"
|
||||
" }"
|
||||
" else { "
|
||||
" throw 12;"
|
||||
" }"
|
||||
s->execSetup( "emit = function( k , v ){"
|
||||
" $lastKey = k;"
|
||||
" tempcoll.insert( { key : k , value : v } );"
|
||||
"}" , "emit1" );
|
||||
|
||||
ScriptingFunction mapFunction = s->createFunction( cmdObj["map"].ascode().c_str() );
|
||||
@ -130,8 +125,14 @@ namespace mongo {
|
||||
throw UserException( (string)"map invoke failed: " + s->getError() );
|
||||
|
||||
num++;
|
||||
if ( num % 100 == 0 ){
|
||||
//assert( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result.append( "timeMillis.emit" , t.millis() );
|
||||
|
||||
// final reduce
|
||||
|
||||
BSONObj prev;
|
||||
@ -164,6 +165,7 @@ namespace mongo {
|
||||
|
||||
result.append( "result" , resultCollShort );
|
||||
result.append( "numObjects" , num );
|
||||
result.append( "timeMillis" , t.millis() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -39,4 +39,17 @@ assert.eq( 3 , z.c , "F" );
|
||||
x.drop();
|
||||
|
||||
|
||||
for ( i=5; i<1000; i++ ){
|
||||
t.save( { x : i , tags : [ "b" , "d" ] } );
|
||||
}
|
||||
|
||||
res = db.runCommand( { mapreduce : "mr1" , map : m , reduce : r } );
|
||||
printjson( res );
|
||||
assert.eq( 999 , res.numObjects , "Z1" );
|
||||
x = db[res.result];
|
||||
|
||||
assert.eq( 4 , x.find().count() , "Z2" );
|
||||
assert.eq( "a,b,c,d" , x.distinct( "key" ) , "Z3" );
|
||||
|
||||
x.find().forEach( printjson );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user