diff options
-rw-r--r-- | SConstruct | 17 | ||||
-rw-r--r-- | db/dbwebserver.cpp | 12 | ||||
-rw-r--r-- | db/stats/snapshots.cpp | 53 | ||||
-rw-r--r-- | db/stats/snapshots.h | 21 | ||||
-rw-r--r-- | db/stats/top.cpp | 9 | ||||
-rw-r--r-- | db/stats/top.h | 6 | ||||
-rw-r--r-- | dbtests/jsobjtests.cpp | 2 | ||||
-rw-r--r-- | rpm/init.d-mongod | 2 | ||||
-rw-r--r-- | tools/sniffer.cpp | 5 |
9 files changed, 73 insertions, 54 deletions
diff --git a/SConstruct b/SConstruct index 7cd0170b12e..8a17e697e85 100644 --- a/SConstruct +++ b/SConstruct @@ -1290,7 +1290,7 @@ if not onlyServer and not noshell: mongodForTests = None mongodForTestsPort = "27017" -def startMongodForTests( env, target, source ): +def startMongodWithArgs(*args): global mongodForTests global mongodForTestsPort global mongod @@ -1302,13 +1302,20 @@ def startMongodForTests( env, target, source ): dirName = "/data/db/sconsTests/" ensureDir( dirName ) from subprocess import Popen - mongodForTests = Popen( [ mongod[0].abspath, "--port", mongodForTestsPort, "--dbpath", dirName ] ) + mongodForTests = Popen([mongod[0].abspath, "--port", mongodForTestsPort, + "--dbpath", dirName] + list(args)) if not utils.didMongodStart( 32000 ): print( "Failed to start mongod" ) mongodForTests = None Exit( 1 ) - + +def startMongodForTests( env, target, source ): + return startMongodWithArgs() + +def startMongodSmallOplog(env, target, source): + return startMongodWithArgs("--master", "--oplogSize", "10") + def stopMongodForTests(): global mongodForTests if not mongodForTests: @@ -1333,6 +1340,10 @@ testEnv.Alias( "startMongod", [add_exe("mongod")], [startMongodForTests] ); testEnv.AlwaysBuild( "startMongod" ); testEnv.SideEffect( "dummySmokeSideEffect", "startMongod" ) +testEnv.Alias( "startMongodSmallOplog", [add_exe("mongod")], [startMongodSmallOplog] ); +testEnv.AlwaysBuild( "startMongodSmallOplog" ); +testEnv.SideEffect( "dummySmokeSideEffect", "startMongodSmallOplog" ) + def addMongodReqTargets( env, target, source ): mongodReqTargets = [ "smokeClient", "smokeJs", "smokeQuota" ] for target in mongodReqTargets: diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index c48c779dd4e..ea488a88bbd 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -98,7 +98,15 @@ namespace mongo { ss << "\n<b>DBTOP (occurences|percent of elapsed)</b>\n"; ss << "<table border=1>"; ss << "<tr align='left'>"; - ss << "<th>NS</th> <th>total</th> <th>Reads</th><th>Writes</th> <th>Queries</th><th>GetMores</th><th>Inserts</th><th>Updates</th><th>Removes</th> "; + ss << "<th>NS</th>" + "<th colspan=2>total</th>" + "<th colspan=2>Reads</th>" + "<th colspan=2>Writes</th>" + "<th colspan=2>Queries</th>" + "<th colspan=2>GetMores</th>" + "<th colspan=2>Inserts</th>" + "<th colspan=2>Updates</th>" + "<th colspan=2>Removes</th>"; ss << "</tr>"; display( ss , (double) delta->elapsed() , "GLOBAL" , delta->globalUsageDiff() ); @@ -119,7 +127,7 @@ namespace mongo { void display( stringstream& ss , double elapsed , const Top::UsageData& usage ){ ss << "<td>"; ss << usage.count; - ss << "|"; + ss << "</td><td>"; double per = 100 * ((double)usage.time)/elapsed; ss << setprecision(2) << fixed << per << "%"; ss << "</td>"; diff --git a/db/stats/snapshots.cpp b/db/stats/snapshots.cpp index 7fc6bbdc0da..71ddd72cbd7 100644 --- a/db/stats/snapshots.cpp +++ b/db/stats/snapshots.cpp @@ -25,50 +25,49 @@ handles snapshotting performance metrics and other such things */ namespace mongo { - - SnapshotData::SnapshotData() - : _created ( curTimeMicros64() ) , - _globalUsage( Top::global.getGlobalData() ) - { + void SnapshotData::takeSnapshot(){ + _created = curTimeMicros64(); + _globalUsage = Top::global.getGlobalData(); _totalWriteLockedTime = dbMutex.info().getTimeLocked(); - _usage = Top::global.cloneMap(); + Top::global.cloneMap(_usage); } - SnapshotDelta::SnapshotDelta( SnapshotData * older , SnapshotData * newer ) + SnapshotDelta::SnapshotDelta( const SnapshotData& older , const SnapshotData& newer ) : _older( older ) , _newer( newer ) { - assert( _newer->_created > _older->_created ); - _elapsed = _newer->_created - _older->_created; + assert( _newer._created > _older._created ); + _elapsed = _newer._created - _older._created; } Top::CollectionData SnapshotDelta::globalUsageDiff(){ - return Top::CollectionData( _older->_globalUsage , _newer->_globalUsage ); + return Top::CollectionData( _older._globalUsage , _newer._globalUsage ); } Top::UsageMap SnapshotDelta::collectionUsageDiff(){ Top::UsageMap u; - for ( Top::UsageMap::iterator i=_newer->_usage.begin(); i != _newer->_usage.end(); i++ ){ - u[i->first] = Top::CollectionData( _older->_usage[i->first] , i->second ); + for ( Top::UsageMap::const_iterator i=_newer._usage.begin(); i != _newer._usage.end(); i++ ){ + Top::UsageMap::const_iterator j = _older._usage.find(i->first); + if (j != _older._usage.end()) + u[i->first] = Top::CollectionData( j->second , i->second ); } return u; } - Snapshots::Snapshots(){ - _n = 100; - _snapshots = new SnapshotData*[_n]; - for ( int i=0; i<_n; i++ ) - _snapshots[i] = 0; - _loc = 0; - _stored = 0; - } + Snapshots::Snapshots(int n) + : _n(n) + , _snapshots(new SnapshotData[n]) + , _loc(0) + , _stored(0) + {} - void Snapshots::add( SnapshotData * s ){ + const SnapshotData* Snapshots::takeSnapshot(){ scoped_lock lk(_lock); _loc = ( _loc + 1 ) % _n; - _snapshots[_loc] = s; + _snapshots[_loc].takeSnapshot(); if ( _stored < _n ) _stored++; + return &_snapshots[_loc]; } auto_ptr<SnapshotDelta> Snapshots::computeDelta( int numBack ){ @@ -79,7 +78,7 @@ namespace mongo { return p; } - SnapshotData* Snapshots::getPrev( int numBack ){ + const SnapshotData& Snapshots::getPrev( int numBack ){ int x = _loc - numBack; if ( x < 0 ) x += _n; @@ -109,19 +108,17 @@ namespace mongo { long long numLoops = 0; - SnapshotData * prev = 0; + const SnapshotData* prev = 0; while ( ! inShutdown() ){ try { - SnapshotData * s = new SnapshotData(); - - statsSnapshots.add( s ); + const SnapshotData* s = statsSnapshots.takeSnapshot(); if ( prev ){ unsigned long long elapsed = s->_created - prev->_created; if ( cmdLine.cpu ){ - SnapshotDelta d( prev , s ); + SnapshotDelta d( *prev , *s ); log() << "cpu: elapsed:" << (elapsed/1000) <<" writelock: " << (int)(100*d.percentWriteLocked()) << "%" << endl; } diff --git a/db/stats/snapshots.h b/db/stats/snapshots.h index 9fde41ac1ee..542318aaee6 100644 --- a/db/stats/snapshots.h +++ b/db/stats/snapshots.h @@ -34,7 +34,7 @@ namespace mongo { * i.e. all counters at a given time */ class SnapshotData { - SnapshotData(); + void takeSnapshot(); unsigned long long _created; Top::CollectionData _globalUsage; @@ -43,6 +43,7 @@ namespace mongo { friend class SnapshotThread; friend class SnapshotDelta; + friend class Snapshots; }; /** @@ -50,10 +51,10 @@ namespace mongo { */ class SnapshotDelta { public: - SnapshotDelta( SnapshotData * older , SnapshotData * newer ); + SnapshotDelta( const SnapshotData& older , const SnapshotData& newer ); unsigned long long start() const { - return _older->_created; + return _older._created; } unsigned long long elapsed() const { @@ -61,7 +62,7 @@ namespace mongo { } unsigned long long timeInWriteLock() const { - return _newer->_totalWriteLockedTime - _older->_totalWriteLockedTime; + return _newer._totalWriteLockedTime - _older._totalWriteLockedTime; } double percentWriteLocked() const { double e = (double) elapsed(); @@ -73,21 +74,21 @@ namespace mongo { Top::UsageMap collectionUsageDiff(); private: - SnapshotData * _older; - SnapshotData * _newer; + const SnapshotData& _older; + const SnapshotData& _newer; unsigned long long _elapsed; }; class Snapshots { public: - Snapshots(); + Snapshots(int n=100); - void add( SnapshotData * s ); + const SnapshotData* takeSnapshot(); int numDeltas() const { return _stored-1; } - SnapshotData* getPrev( int numBack = 0 ); + const SnapshotData& getPrev( int numBack = 0 ); auto_ptr<SnapshotDelta> computeDelta( int numBack = 0 ); @@ -95,7 +96,7 @@ namespace mongo { private: mongo::mutex _lock; int _n; - SnapshotData** _snapshots; + boost::scoped_array<SnapshotData> _snapshots; int _loc; int _stored; }; diff --git a/db/stats/top.cpp b/db/stats/top.cpp index 93d29ed3baf..7f42d79b957 100644 --- a/db/stats/top.cpp +++ b/db/stats/top.cpp @@ -23,14 +23,14 @@ namespace mongo { - Top::UsageData::UsageData( UsageData& older , UsageData& newer ) + Top::UsageData::UsageData( const UsageData& older , const UsageData& newer ) : time(newer.time-older.time) , count(newer.count-older.count) { } - Top::CollectionData::CollectionData( CollectionData& older , CollectionData& newer ) + Top::CollectionData::CollectionData( const CollectionData& older , const CollectionData& newer ) : total( older.total , newer.total ) , readLock( older.readLock , newer.readLock ) , writeLock( older.writeLock , newer.writeLock ) , @@ -94,10 +94,9 @@ namespace mongo { } - Top::UsageMap Top::cloneMap(){ + void Top::cloneMap(Top::UsageMap& out){ scoped_lock lk(_lock); - UsageMap x = _usage; - return x; + out = _usage; } void Top::append( BSONObjBuilder& b ){ diff --git a/db/stats/top.h b/db/stats/top.h index eaf8a12cad5..9860733f5f8 100644 --- a/db/stats/top.h +++ b/db/stats/top.h @@ -32,7 +32,7 @@ namespace mongo { class UsageData { public: UsageData() : time(0) , count(0){} - UsageData( UsageData& older , UsageData& newer ); + UsageData( const UsageData& older , const UsageData& newer ); long long time; long long count; @@ -48,7 +48,7 @@ namespace mongo { * constructs a diff */ CollectionData(){} - CollectionData( CollectionData& older , CollectionData& newer ); + CollectionData( const CollectionData& older , const CollectionData& newer ); UsageData total; @@ -68,7 +68,7 @@ namespace mongo { public: void record( const string& ns , int op , int lockType , long long micros , bool command ); void append( BSONObjBuilder& b ); - UsageMap cloneMap(); + void cloneMap(UsageMap& out); CollectionData getGlobalData(){ return _global; } public: // static stuff diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index 2f13b73fb76..e470e605ebf 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -861,7 +861,9 @@ namespace JsobjTests { public: void run() { Date_t before = jsTime(); + sleepmillis(1); time_t now = time(NULL); + sleepmillis(1); Date_t after = jsTime(); BSONObjBuilder b; diff --git a/rpm/init.d-mongod b/rpm/init.d-mongod index 2c634f6aa0c..12068c802b3 100644 --- a/rpm/init.d-mongod +++ b/rpm/init.d-mongod @@ -37,7 +37,7 @@ stop() echo -n $"Stopping mongod: " killproc -p /var/lib/mongo/mongod.lock -t30 -TERM /usr/bin/mongod RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod &7 success + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod && success } restart () { diff --git a/tools/sniffer.cpp b/tools/sniffer.cpp index 6813012ede7..14d32bdb8b1 100644 --- a/tools/sniffer.cpp +++ b/tools/sniffer.cpp @@ -381,11 +381,12 @@ void processDiagLog( const char * file ){ void usage() { cout << - "Usage: mongosniff [--help] [--forward host:port] [--source (NET <interface> | FILE <filename>)] [<port0> <port1> ... ]\n" + "Usage: mongosniff [--help] [--forward host:port] [--source (NET <interface> | (FILE | DIAGLOG) <filename>)] [<port0> <port1> ... ]\n" "--forward Forward all parsed request messages to mongod instance at \n" " specified host:port\n" "--source Source of traffic to sniff, either a network interface or a\n" - " file containing perviously captured packets, in pcap format.\n" + " file containing previously captured packets in pcap format,\n" + " or a file containing output from mongod's --diaglog option.\n" " If no source is specified, mongosniff will attempt to sniff\n" " from one of the machine's network interfaces.\n" "<port0>... These parameters are used to filter sniffing. By default, \n" |