diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-04-06 13:49:51 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-04-13 17:19:28 -0400 |
commit | f8339b000d80c35248a5c7a7e6a8fe2182702f6c (patch) | |
tree | 9ed7383b5a0bace93f8be2b11a52373570389593 | |
parent | adb8a476bc86dc96a583f45cb0dee21b0c8afd59 (diff) | |
download | mongo-f8339b000d80c35248a5c7a7e6a8fe2182702f6c.tar.gz |
adaptive sleep for ClientCusror::yield SERVER-975
-rw-r--r-- | db/client.cpp | 17 | ||||
-rw-r--r-- | db/client.h | 2 | ||||
-rw-r--r-- | db/clientcursor.cpp | 1 | ||||
-rw-r--r-- | util/goodies.h | 4 |
4 files changed, 24 insertions, 0 deletions
diff --git a/db/client.cpp b/db/client.cpp index dc82a2550da..a2fe5683394 100644 --- a/db/client.cpp +++ b/db/client.cpp @@ -245,4 +245,21 @@ namespace mongo { return b.obj(); } + int Client::recommendedYieldMicros(){ + int num = 0; + { + scoped_lock bl(clientsMutex); + num = clients.size(); + } + + if ( --num <= 0 ) // -- is for myself + return 0; + + if ( num > 50 ) + num = 50; + + num *= 100; + return num; + } + } diff --git a/db/client.h b/db/client.h index ab4350949b4..c484198219a 100644 --- a/db/client.h +++ b/db/client.h @@ -45,6 +45,8 @@ namespace mongo { static mongo::mutex clientsMutex; static set<Client*> clients; // always be in clientsMutex when manipulating this + static int recommendedYieldMicros(); + class GodScope { bool _prev; public: diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp index be0bd2f232e..1281fc33660 100644 --- a/db/clientcursor.cpp +++ b/db/clientcursor.cpp @@ -232,6 +232,7 @@ namespace mongo { { dbtempreleasecond unlock; + sleepmicros( Client::recommendedYieldMicros() ); } if ( ClientCursor::find( id , false ) == 0 ){ diff --git a/util/goodies.h b/util/goodies.h index a70f322dfe4..cd5423b344f 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -195,6 +195,8 @@ namespace mongo { boost::thread::sleep(xt); } inline void sleepmicros(int s) { + if ( s <= 0 ) + return; boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC); xt.sec += ( s / 1000000 ); @@ -215,6 +217,8 @@ namespace mongo { } } inline void sleepmicros(int s) { + if ( s <= 0 ) + return; struct timespec t; t.tv_sec = (int)(s / 1000000); t.tv_nsec = s % 1000000; |