mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +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 ){
|
string tempCollectionName( string coll ){
|
||||||
static int inc = 1;
|
static int inc = 1;
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << database->name << ".mr." << coll << "." << time(0) << inc++;
|
ss << database->name << ".mr." << coll << "." << time(0) << "." << inc++;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,8 @@ namespace mongo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool run(const char *dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
|
bool run(const char *dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){
|
||||||
|
Timer t;
|
||||||
|
|
||||||
string ns = database->name + '.' + cmdObj.firstElement().valuestr();
|
string ns = database->name + '.' + cmdObj.firstElement().valuestr();
|
||||||
log(1) << "mr ns: " << ns << endl;
|
log(1) << "mr ns: " << ns << endl;
|
||||||
|
|
||||||
@ -104,15 +105,9 @@ namespace mongo {
|
|||||||
try {
|
try {
|
||||||
s->execSetup( (string)"tempcoll = db[\"" + resultCollShort + "\"];" , "tempcoll1" );
|
s->execSetup( (string)"tempcoll = db[\"" + resultCollShort + "\"];" , "tempcoll1" );
|
||||||
|
|
||||||
s->execSetup( "$num = 0;"
|
s->execSetup( "emit = function( k , v ){"
|
||||||
"emit = function( k , v ){"
|
" $lastKey = k;"
|
||||||
" $num = $num + 1;"
|
" tempcoll.insert( { key : k , value : v } );"
|
||||||
" if ( $num % 100 > 0 ){"
|
|
||||||
" tempcoll.insert( { key : k , value : v } );"
|
|
||||||
" }"
|
|
||||||
" else { "
|
|
||||||
" throw 12;"
|
|
||||||
" }"
|
|
||||||
"}" , "emit1" );
|
"}" , "emit1" );
|
||||||
|
|
||||||
ScriptingFunction mapFunction = s->createFunction( cmdObj["map"].ascode().c_str() );
|
ScriptingFunction mapFunction = s->createFunction( cmdObj["map"].ascode().c_str() );
|
||||||
@ -130,8 +125,14 @@ namespace mongo {
|
|||||||
throw UserException( (string)"map invoke failed: " + s->getError() );
|
throw UserException( (string)"map invoke failed: " + s->getError() );
|
||||||
|
|
||||||
num++;
|
num++;
|
||||||
|
if ( num % 100 == 0 ){
|
||||||
|
//assert( 0 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result.append( "timeMillis.emit" , t.millis() );
|
||||||
|
|
||||||
// final reduce
|
// final reduce
|
||||||
|
|
||||||
BSONObj prev;
|
BSONObj prev;
|
||||||
@ -164,6 +165,7 @@ namespace mongo {
|
|||||||
|
|
||||||
result.append( "result" , resultCollShort );
|
result.append( "result" , resultCollShort );
|
||||||
result.append( "numObjects" , num );
|
result.append( "numObjects" , num );
|
||||||
|
result.append( "timeMillis" , t.millis() );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,17 @@ assert.eq( 3 , z.c , "F" );
|
|||||||
x.drop();
|
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