summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-11-09 00:14:52 -0500
committerEliot Horowitz <eliot@10gen.com>2010-11-09 00:15:14 -0500
commit0c7e7101a6fabe05ab72a09e686e7ae0b736df3b (patch)
treef488a525f66557af9102639cb905f8d234585806 /db
parentdd56085dbee13e12c91e994f6196fc58aef06304 (diff)
downloadmongo-0c7e7101a6fabe05ab72a09e686e7ae0b736df3b.tar.gz
track network in/out SERVER-2081
Diffstat (limited to 'db')
-rw-r--r--db/db.cpp3
-rw-r--r--db/dbcommands.cpp7
-rw-r--r--db/stats/counters.cpp22
-rw-r--r--db/stats/counters.h10
4 files changed, 32 insertions, 10 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 0326e3e0244..304775b2c99 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -217,6 +217,7 @@ namespace mongo {
Message m;
while ( 1 ) {
+ inPort->clearCounters();
if ( !dbMsgPort->recv(m) ) {
if( !cmdLine.quiet )
@@ -275,6 +276,8 @@ sendmore:
}
}
+ networkCounter.hit( inPort->getBytesIn() , inPort->getBytesOut() );
+
m.reset();
}
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index 8697b270556..304a846db92 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -397,6 +397,13 @@ namespace mongo {
ClientCursor::appendStats( bb );
bb.done();
}
+
+ {
+ BSONObjBuilder bb( result.subobjStart( "network" ) );
+ networkCounter.append( bb );
+ bb.done();
+ }
+
timeBuilder.appendNumber( "after counters" , Listener::getElapsedTimeMillis() - start );
diff --git a/db/stats/counters.cpp b/db/stats/counters.cpp
index 69861a8ec76..fad0f364c5e 100644
--- a/db/stats/counters.cpp
+++ b/db/stats/counters.cpp
@@ -144,25 +144,33 @@ namespace mongo {
void NetworkCounter::hit( long long bytesIn , long long bytesOut ) {
const long long MAX = 1ULL << 60;
- mongo::mutex::scoped_lock lk( _mutex );
- if ( _bytesIn > MAX || _bytesOut > MAX ){
+
+ // don't care about the race as its just a counter
+ bool overflow = _bytesIn > MAX || _bytesOut > MAX;
+
+ if ( overflow ){
+ _lock.lock();
_overflows++;
_bytesIn = bytesIn;
_bytesOut = bytesOut;
+ _requests = 1;
+ _lock.unlock();
}
else {
+ _lock.lock();
_bytesIn += bytesIn;
_bytesOut += bytesOut;
-
+ _requests++;
+ _lock.unlock();
}
}
- BSONObj NetworkCounter::getObj() {
- BSONObjBuilder b( 64 );
- mongo::mutex::scoped_lock lk( _mutex );
+ void NetworkCounter::append( BSONObjBuilder& b ) {
+ _lock.lock();
b.appendNumber( "bytesIn" , _bytesIn );
b.appendNumber( "bytesOut" , _bytesOut );
- return b.obj();
+ b.appendNumber( "numRequests" , _requests );
+ _lock.unlock();
}
diff --git a/db/stats/counters.h b/db/stats/counters.h
index 730602c5a01..1af7ba94b98 100644
--- a/db/stats/counters.h
+++ b/db/stats/counters.h
@@ -21,6 +21,7 @@
#include "../jsobj.h"
#include "../../util/message.h"
#include "../../util/processinfo.h"
+#include "../../util/concurrency/spin_lock.h"
namespace mongo {
@@ -133,14 +134,17 @@ namespace mongo {
class NetworkCounter {
public:
- NetworkCounter() : _bytesIn(0), _bytesOut(0), _overflows(0) , _mutex( "NetworkCounter" ){}
+ NetworkCounter() : _bytesIn(0), _bytesOut(0), _requests(0), _overflows(0){}
void hit( long long bytesIn , long long bytesOut );
- BSONObj getObj();
+ void append( BSONObjBuilder& b );
private:
long long _bytesIn;
long long _bytesOut;
+ long long _requests;
+
long long _overflows;
- mongo::mutex _mutex;
+
+ SpinLock _lock;
};
extern NetworkCounter networkCounter;