Skip to content
Browse files

mongostat shows # of active readers/writers SERVER-1997

  • Loading branch information...
1 parent d31fdae commit 13703038d3a0575c9dfddceb86ceec78af7d4547 @erh erh committed
Showing with 66 additions and 19 deletions.
  1. +21 −0 db/client.cpp
  2. +1 −0 db/client.h
  3. +21 −7 db/dbcommands.cpp
  4. +23 −12 tools/stat.cpp
View
21 db/client.cpp
@@ -456,4 +456,25 @@ namespace mongo {
return time;
}
+
+ int Client::getActiveClientCount( int& writers, int& readers ){
+ writers = 0;
+ readers = 0;
+
+ scoped_lock bl(clientsMutex);
+ for ( set<Client*>::iterator i=clients.begin(); i!=clients.end(); ++i ){
+ Client* c = *i;
+ if ( ! c->curop()->active() )
+ continue;
+
+ int l = c->curop()->getLockType();
+ if ( l > 0 )
+ writers++;
+ else if ( l < 0 )
+ readers++;
+
+ }
+
+ return writers + readers;
+ }
}
View
1 db/client.h
@@ -54,6 +54,7 @@ namespace mongo {
static mongo::mutex clientsMutex;
static set<Client*> clients; // always be in clientsMutex when manipulating this
static int recommendedYieldMicros( int * writers = 0 , int * readers = 0 );
+ static int getActiveClientCount( int& writers , int& readers );
/* set _god=true temporarily, safely */
class GodScope {
View
28 db/dbcommands.cpp
@@ -312,13 +312,27 @@ namespace mongo {
t.append("lockTime", tl);
t.append("ratio", (tt ? tl/tt : 0));
- BSONObjBuilder ttt( t.subobjStart( "currentQueue" ) );
- int w=0, r=0;
- Client::recommendedYieldMicros( &w , &r );
- ttt.append( "total" , w + r );
- ttt.append( "readers" , r );
- ttt.append( "writers" , w );
- ttt.done();
+ {
+ BSONObjBuilder ttt( t.subobjStart( "currentQueue" ) );
+ int w=0, r=0;
+ Client::recommendedYieldMicros( &w , &r );
+ ttt.append( "total" , w + r );
+ ttt.append( "readers" , r );
+ ttt.append( "writers" , w );
+ ttt.done();
+ }
+
+ {
+ BSONObjBuilder ttt( t.subobjStart( "activeClients" ) );
+ int w=0, r=0;
+ Client::getActiveClientCount( w , r );
+ ttt.append( "total" , w + r );
+ ttt.append( "readers" , r );
+ ttt.append( "writers" , w );
+ ttt.done();
+ }
+
+
result.append( "globalLock" , t.obj() );
}
View
35 tools/stat.cpp
@@ -64,20 +64,21 @@ namespace mongo {
virtual void printExtraHelpAfter( ostream & out ){
out << "\n";
out << " Fields\n";
- out << " inserts/s \t- # of inserts per second\n";
- out << " query/s \t- # of queries per second\n";
- out << " update/s \t- # of updates per second\n";
- out << " delete/s \t- # of deletes per second\n";
- out << " getmore/s \t- # of get mores (cursor batch) per second\n";
- out << " command/s \t- # of commands per second\n";
- out << " flushes/s \t- # of fsync flushes per second\n";
+ out << " inserts \t- # of inserts per second\n";
+ out << " query \t- # of queries per second\n";
+ out << " update \t- # of updates per second\n";
+ out << " delete \t- # of deletes per second\n";
+ out << " getmore \t- # of get mores (cursor batch) per second\n";
+ out << " command \t- # of commands per second\n";
+ out << " flushes \t- # of fsync flushes per second\n";
out << " mapped \t- amount of data mmaped (total data size) megabytes\n";
out << " visze \t- virtual size of process in megabytes\n";
out << " res \t- resident size of process in megabytes\n";
- out << " faults/s \t- # of pages faults/sec (linux only)\n";
+ out << " faults \t- # of pages faults per sec (linux only)\n";
out << " locked \t- percent of time in global write lock\n";
out << " idx miss \t- percent of btree page misses (sampled)\n";
- out << " q r|w \t- ops waiting for lock from db.currentOp() (read|write)\n";
+ out << " qr|qw \t- queue lengths for clients waiting (read|write)\n";
+ out << " ar|aw \t- active clients (read|write)\n";
out << " conn \t- number of open connections\n";
}
@@ -155,14 +156,14 @@ namespace mongo {
BSONObjIterator i( bx );
while ( i.more() ){
BSONElement e = i.next();
- _append( result , (string)(e.fieldName()) + "/s" , 6 , (int)diff( e.fieldName() , ax , bx ) );
+ _append( result , e.fieldName() , 6 , (int)diff( e.fieldName() , ax , bx ) );
}
}
if ( b["backgroundFlushing"].type() == Object ){
BSONObj ax = a["backgroundFlushing"].embeddedObject();
BSONObj bx = b["backgroundFlushing"].embeddedObject();
- _append( result , "flushes/s" , 6 , (int)diff( "flushes" , ax , bx ) );
+ _append( result , "flushes" , 6 , (int)diff( "flushes" , ax , bx ) );
}
if ( b.getFieldDotted("mem.supported").trueValue() ){
@@ -177,7 +178,7 @@ namespace mongo {
BSONObj ax = a["extra_info"].embeddedObject();
BSONObj bx = b["extra_info"].embeddedObject();
if ( ax["page_faults"].type() || ax["page_faults"].type() )
- _append( result , "faults/s" , 6 , (int)diff( "page_faults" , ax , bx ) );
+ _append( result , "faults" , 6 , (int)diff( "page_faults" , ax , bx ) );
}
_append( result , "locked %" , 8 , percent( "globalLock.totalTime" , "globalLock.lockTime" , a , b ) );
@@ -190,6 +191,16 @@ namespace mongo {
temp << r << "|" << w;
_append( result , "qr|qw" , 9 , temp.str() );
}
+
+ if ( b.getFieldDotted( "globalLock.activeClients" ).type() == Object ){
+ int r = b.getFieldDotted( "globalLock.activeClients.readers" ).numberInt();
+ int w = b.getFieldDotted( "globalLock.activeClients.writers" ).numberInt();
+ stringstream temp;
+ temp << r << "|" << w;
+ _append( result , "ar|aw" , 7 , temp.str() );
+ }
+
+
_append( result , "conn" , 5 , b.getFieldDotted( "connections.current" ).numberInt() );
if ( b["repl"].type() == Object ){

0 comments on commit 1370303

Please sign in to comment.
Something went wrong with that request. Please try again.