Author: dreiss
Date: Tue Mar  9 05:19:52 2010
New Revision: 920676

URL: http://svn.apache.org/viewvc?rev=920676&view=rev
Log:
cpp: TSocketPool: Optimize the case of a single server in the pool.

Modified:
    incubator/thrift/trunk/lib/cpp/src/transport/TSocketPool.cpp

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TSocketPool.cpp
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TSocketPool.cpp?rev=920676&r1=920675&r2=920676&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TSocketPool.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TSocketPool.cpp Tue Mar  9 
05:19:52 2010
@@ -169,17 +169,20 @@ void TSocketPool::setCurrentServer(const
 
 /* TODO: without apc we ignore a lot of functionality from the php version */
 void TSocketPool::open() {
-  if (randomize_) {
+
+  unsigned int numServers = servers_.size();
+  if (numServers == 1 && isOpen()) {
+    // only one server that is already connected to
+    return;
+  }
+
+  if (randomize_ && numServers > 1) {
     random_shuffle(servers_.begin(), servers_.end());
   }
 
-  unsigned int numServers = servers_.size();
   for (unsigned int i = 0; i < numServers; ++i) {
 
     shared_ptr<TSocketPoolServer> &server = servers_[i];
-    bool retryIntervalPassed = (server->lastFailTime_ == 0);
-    bool isLastServer = alwaysTryLast_ ? (i == (numServers - 1)) : false;
-
     // Impersonate the server socket
     setCurrentServer(server);
 
@@ -188,6 +191,9 @@ void TSocketPool::open() {
       return;
     }
 
+    bool retryIntervalPassed = (server->lastFailTime_ == 0);
+    bool isLastServer = alwaysTryLast_ ? (i == (numServers - 1)) : false;
+
     if (server->lastFailTime_ > 0) {
       // The server was marked as down, so check if enough time has elapsed to 
retry
       int elapsedTime = time(NULL) - server->lastFailTime_;


Reply via email to