|
Hi
I got follow information when cpp client fetch data from cold mongodb:
> db.currentOp()
|
{
|
"inprog" : [
|
{
|
"opid" : 10,
|
"active" : true,
|
"secs_running" : 115,
|
"op" : "getmore",
|
"ns" : "test.test",
|
"query" : {
|
|
},
|
"client" : "127.0.0.1:17066",
|
"desc" : "conn1",
|
"connectionId" : 1,
|
"waitingForLock" : false,
|
"numYields" : 7381,
|
"lockStats" : {
|
"timeLockedMicros" : {
|
"r" : NumberLong(1009869),
|
"w" : NumberLong(0)
|
},
|
"timeAcquiringMicros" : {
|
"r" : NumberLong(115256560),
|
"w" : NumberLong(0)
|
}
|
}
|
}
|
]
|
}
|
> db.stats()
|
{
|
"db" : "test",
|
"collections" : 3,
|
"objects" : 1000004,
|
"avgObjSize" : 143.99963200147198,
|
"dataSize" : 144000208,
|
"storageSize" : 185917440,
|
"numExtents" : 13,
|
"indexes" : 1,
|
"indexSize" : 27921040,
|
"fileSize" : 520093696,
|
"nsSizeMB" : 16,
|
"dataFileVersion" : {
|
"major" : 4,
|
"minor" : 5
|
},
|
"ok" : 1
|
}
|
something from web console
top:
{ "host" : "20110924-1019",
|
"version" : "2.4.1",
|
"process" : "E:\\mongodb-win32-i386-2.4.1\\bin\\mongod",
|
"pid" : 2304,
|
"uptime" : 156,
|
"uptimeMillis" : 156187,
|
"uptimeEstimate" : 100,
|
"localTime" : { "$date" : "Fri Apr 05 17:07:36 2013" },
|
"asserts" : { "regular" : 0,
|
"warning" : 0,
|
"msg" : 0,
|
"user" : 0,
|
"rollovers" : 0 },
|
"backgroundFlushing" : { "flushes" : 2,
|
"total_ms" : 374,
|
"average_ms" : 187,
|
"last_ms" : 78,
|
"last_finished" : { "$date" : "Fri Apr 05 17:07:00 2013" } },
|
"connections" : { "current" : 1,
|
"available" : 19999,
|
"totalCreated" : 164 },
|
"cursors" : { "totalOpen" : 1,
|
"clientCursors_size" : 1,
|
"timedOut" : 0,
|
"pinned" : 1 },
|
"extra_info" : { "note" : "fields vary by platform",
|
"page_faults" : 18797,
|
"usagePageFileMB" : 41,
|
"totalPageFileMB" : 3934,
|
"availPageFileMB" : 2627,
|
"ramMB" : 2042 },
|
"globalLock" : { "totalTime" : 156187000,
|
"lockTime" : 36845,
|
"currentQueue" : { "total" : 0,
|
"readers" : 0,
|
"writers" : 0 },
|
"activeClients" : { "total" : 0,
|
"readers" : 0,
|
"writers" : 0 } },
|
"indexCounters" : { "note" : "not supported on this platform" },
|
"locks" : { "." : { "timeLockedMicros" : { "R" : 102,
|
"W" : 36845 },
|
"timeAcquiringMicros" : { "R" : 59,
|
"W" : 29 } },
|
"admin" : { "timeLockedMicros" : {},
|
"timeAcquiringMicros" : {} },
|
"local" : { "timeLockedMicros" : { "r" : 2528,
|
"w" : 0 },
|
"timeAcquiringMicros" : { "r" : 559,
|
"w" : 0 } },
|
"test" : { "timeLockedMicros" : { "r" : 1401275,
|
"w" : 0 },
|
"timeAcquiringMicros" : { "r" : 120246410,
|
"w" : 0 } } },
|
"network" : { "bytesIn" : 98,
|
"bytesOut" : 4196572,
|
"numRequests" : 2 },
|
"opcounters" : { "insert" : 1,
|
"query" : 5,
|
"update" : 0,
|
"delete" : 0,
|
"getmore" : 2,
|
"command" : 1 },
|
"opcountersRepl" : { "insert" : 0,
|
"query" : 0,
|
"update" : 0,
|
"delete" : 0,
|
"getmore" : 0,
|
"command" : 0 },
|
"recordStats" : { "accessesNotInMemory" : 12,
|
"pageFaultExceptionsThrown" : 0,
|
"local" : { "accessesNotInMemory" : 3,
|
"pageFaultExceptionsThrown" : 0 },
|
"test" : { "accessesNotInMemory" : 6,
|
"pageFaultExceptionsThrown" : 0 } },
|
"writeBacksQueued" : false,
|
"mem" : { "bits" : 32,
|
"resident" : 65,
|
"virtual" : 376,
|
"supported" : true,
|
"mapped" : 288 },
|
"metrics" : { "document" : { "deleted" : 0,
|
"inserted" : 1,
|
"returned" : 190750,
|
"updated" : 0 },
|
"getLastError" : { "wtime" : { "num" : 0,
|
"totalMillis" : 0 },
|
"wtimeouts" : 0 },
|
"operation" : { "fastmod" : 0,
|
"idhack" : 0,
|
"scanAndOrder" : 0 },
|
"queryExecutor" : { "scanned" : 104 },
|
"record" : { "moves" : 0 },
|
"repl" : { "apply" : { "batches" : { "num" : 0,
|
"totalMillis" : 0 },
|
"ops" : 0 },
|
"buffer" : { "count" : 0,
|
"maxSizeBytes" : 268435456,
|
"sizeBytes" : 0 },
|
"network" : { "bytes" : 0,
|
"getmores" : { "num" : 0,
|
"totalMillis" : 0 },
|
"ops" : 0,
|
"readersCreated" : 0 },
|
"oplog" : { "insert" : { "num" : 0,
|
"totalMillis" : 0 },
|
"insertBytes" : 0 },
|
"preload" : { "docs" : { "num" : 0,
|
"totalMillis" : 0 },
|
"indexes" : { "num" : 0,
|
"totalMillis" : 0 } } },
|
"ttl" : { "deletedDocuments" : 0,
|
"passes" : 2 } },
|
"ok" : 1 }
|
serverStatus:
{ "host" : "20110924-1019",
|
"version" : "2.4.1",
|
"process" : "E:\\mongodb-win32-i386-2.4.1\\bin\\mongod",
|
"pid" : 2304,
|
"uptime" : 179,
|
"uptimeMillis" : 178609,
|
"uptimeEstimate" : 114,
|
"localTime" : { "$date" : "Fri Apr 05 17:07:59 2013" },
|
"asserts" : { "regular" : 0,
|
"warning" : 0,
|
"msg" : 0,
|
"user" : 0,
|
"rollovers" : 0 },
|
"backgroundFlushing" : { "flushes" : 2,
|
"total_ms" : 374,
|
"average_ms" : 187,
|
"last_ms" : 78,
|
"last_finished" : { "$date" : "Fri Apr 05 17:07:00 2013" } },
|
"connections" : { "current" : 1,
|
"available" : 19999,
|
"totalCreated" : 165 },
|
"cursors" : { "totalOpen" : 1,
|
"clientCursors_size" : 1,
|
"timedOut" : 0,
|
"pinned" : 1 },
|
"extra_info" : { "note" : "fields vary by platform",
|
"page_faults" : 20435,
|
"usagePageFileMB" : 41,
|
"totalPageFileMB" : 3934,
|
"availPageFileMB" : 2627,
|
"ramMB" : 2042 },
|
"globalLock" : { "totalTime" : 178609000,
|
"lockTime" : 36845,
|
"currentQueue" : { "total" : 0,
|
"readers" : 0,
|
"writers" : 0 },
|
"activeClients" : { "total" : 0,
|
"readers" : 0,
|
"writers" : 0 } },
|
"indexCounters" : { "note" : "not supported on this platform" },
|
"locks" : { "." : { "timeLockedMicros" : { "R" : 102,
|
"W" : 36845 },
|
"timeAcquiringMicros" : { "R" : 59,
|
"W" : 29 } },
|
"admin" : { "timeLockedMicros" : {},
|
"timeAcquiringMicros" : {} },
|
"local" : { "timeLockedMicros" : { "r" : 2546,
|
"w" : 0 },
|
"timeAcquiringMicros" : { "r" : 564,
|
"w" : 0 } },
|
"test" : { "timeLockedMicros" : { "r" : 1692983,
|
"w" : 0 },
|
"timeAcquiringMicros" : { "r" : 142650412,
|
"w" : 0 } } },
|
"network" : { "bytesIn" : 98,
|
"bytesOut" : 4196572,
|
"numRequests" : 2 },
|
"opcounters" : { "insert" : 1,
|
"query" : 5,
|
"update" : 0,
|
"delete" : 0,
|
"getmore" : 2,
|
"command" : 1 },
|
"opcountersRepl" : { "insert" : 0,
|
"query" : 0,
|
"update" : 0,
|
"delete" : 0,
|
"getmore" : 0,
|
"command" : 0 },
|
"recordStats" : { "accessesNotInMemory" : 12,
|
"pageFaultExceptionsThrown" : 0,
|
"local" : { "accessesNotInMemory" : 3,
|
"pageFaultExceptionsThrown" : 0 },
|
"test" : { "accessesNotInMemory" : 6,
|
"pageFaultExceptionsThrown" : 0 } },
|
"writeBacksQueued" : false,
|
"mem" : { "bits" : 32,
|
"resident" : 72,
|
"virtual" : 376,
|
"supported" : true,
|
"mapped" : 288 },
|
"metrics" : { "document" : { "deleted" : 0,
|
"inserted" : 1,
|
"returned" : 190750,
|
"updated" : 0 },
|
"getLastError" : { "wtime" : { "num" : 0,
|
"totalMillis" : 0 },
|
"wtimeouts" : 0 },
|
"operation" : { "fastmod" : 0,
|
"idhack" : 0,
|
"scanAndOrder" : 0 },
|
"queryExecutor" : { "scanned" : 104 },
|
"record" : { "moves" : 0 },
|
"repl" : { "apply" : { "batches" : { "num" : 0,
|
"totalMillis" : 0 },
|
"ops" : 0 },
|
"buffer" : { "count" : 0,
|
"maxSizeBytes" : 268435456,
|
"sizeBytes" : 0 },
|
"network" : { "bytes" : 0,
|
"getmores" : { "num" : 0,
|
"totalMillis" : 0 },
|
"ops" : 0,
|
"readersCreated" : 0 },
|
"oplog" : { "insert" : { "num" : 0,
|
"totalMillis" : 0 },
|
"insertBytes" : 0 },
|
"preload" : { "docs" : { "num" : 0,
|
"totalMillis" : 0 },
|
"indexes" : { "num" : 0,
|
"totalMillis" : 0 } } },
|
"ttl" : { "deletedDocuments" : 0,
|
"passes" : 2 } },
|
"ok" : 1 }
|
I think the cold/warm situation should be same to client, so I didn't reboot computer or clear fs cache. I just restart mongodb.
The result of test I just runned tell java 82 sec, cpp 610 sec.
-------------------------------------------
The test code:
java:
DBCollection c = new Mongo().getDB("test").getCollection("test");
|
/*init
|
BasicDBObject obj = new BasicDBObject("data", new byte[100]);
|
for (int i = 0; i < 1000000; i++) {
|
obj.append("_id", i).append("_v", i);
|
c.insert(obj);
|
if (i % 10000 == 0) System.out.println(i);
|
}
|
*/
|
DBCursor cursor = c.find(null, new BasicDBObject("_v", 1));
|
int i = 0;
|
long t = System.currentTimeMillis();
|
while (cursor.hasNext()) {
|
DBObject doc = cursor.next();
|
if (i++ % 10000 == 0) System.out.println(i);
|
}
|
System.out.println(System.currentTimeMillis() - t);
|
cpp:
const char *nsname = "test.test";
|
|
int t = GetTickCount();
|
|
DBClientConnection c;
|
c.connect("localhost");
|
|
BSONObjBuilder b;
|
b.append("_v", 1);
|
BSONObj keys = b.obj();
|
Query q;
|
auto_ptr<DBClientCursor> cursor = c.query(nsname, q, 0, 0, &keys);
|
int i = 0;
|
vector<long long> v;
|
while(cursor->more())
|
{
|
BSONObj doc = cursor->next();
|
long long id = doc.firstElement()._numberLong();
|
v.push_back(id);
|
if(i++%10000==0) printf("%d\n", i);
|
}
|
printf("t:%d\n", GetTickCount() - t);
|
|
system("pause");
|
|