summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-04-06 13:49:51 -0400
committerEliot Horowitz <eliot@10gen.com>2010-04-13 17:19:28 -0400
commitf8339b000d80c35248a5c7a7e6a8fe2182702f6c (patch)
tree9ed7383b5a0bace93f8be2b11a52373570389593
parentadb8a476bc86dc96a583f45cb0dee21b0c8afd59 (diff)
downloadmongo-f8339b000d80c35248a5c7a7e6a8fe2182702f6c.tar.gz
adaptive sleep for ClientCusror::yield SERVER-975
-rw-r--r--db/client.cpp17
-rw-r--r--db/client.h2
-rw-r--r--db/clientcursor.cpp1
-rw-r--r--util/goodies.h4
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;