You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/03/09 06:20:15 UTC

svn commit: r920685 - in /incubator/thrift/trunk/lib/cpp/src: server/TNonblockingServer.cpp transport/TSocket.cpp transport/TSocket.h

Author: dreiss
Date: Tue Mar  9 05:20:14 2010
New Revision: 920685

URL: http://svn.apache.org/viewvc?rev=920685&view=rev
Log:
cpp: Add setLowRTO to TSocket

low tcp RTO might mitigate TCP incast problems. Adding the setLowRTO
function to TSocket allows us to experiment with a solution.

Modified:
    incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
    incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp
    incubator/thrift/trunk/lib/cpp/src/transport/TSocket.h

Modified: incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp?rev=920685&r1=920684&r2=920685&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp Tue Mar  9 05:20:14 2010
@@ -19,6 +19,7 @@
 
 #include "TNonblockingServer.h"
 #include <concurrency/Exception.h>
+#include <transport/TSocket.h>
 
 #include <iostream>
 #include <sys/socket.h>
@@ -39,6 +40,8 @@ using namespace apache::thrift::protocol
 using namespace apache::thrift::transport;
 using namespace apache::thrift::concurrency;
 using namespace std;
+using apache::thrift::transport::TSocket;
+using apache::thrift::transport::TTransportException;
 
 class TConnection::Task: public Runnable {
  public:
@@ -706,6 +709,12 @@ void TNonblockingServer::listenSocket(in
   setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
   #endif
 
+  #ifdef TCP_LOW_MIN_RTO
+  if (TSocket::getUseLowMinRto()) {
+    setsockopt(s, IPPROTO_TCP, TCP_LOW_MIN_RTO, &one, sizeof(one));
+  }
+  #endif
+
   if (listen(s, LISTEN_BACKLOG) == -1) {
     close(s);
     throw TException("TNonblockingServer::serve() listen");
@@ -761,7 +770,7 @@ void TNonblockingServer::registerEvents(
               EV_READ | EV_PERSIST,
               TConnection::taskHandler,
               this);
-    
+
     // Attach to the base
     event_base_set(eventBase_, &notificationEvent_);
 

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp?rev=920685&r1=920684&r2=920685&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp Tue Mar  9 05:20:14 2010
@@ -153,6 +153,15 @@ void TSocket::openConnection(struct addr
   // No delay
   setNoDelay(noDelay_);
 
+  // Uses a low min RTO if asked to.
+#ifdef TCP_LOW_MIN_RTO
+  if (getUseLowMinRto()) {
+    int one = 1;
+    setsockopt(socket_, IPPROTO_TCP, TCP_LOW_MIN_RTO, &one, sizeof(one));
+  }
+#endif
+
+
   // Set the socket to be non blocking for connect if a timeout exists
   int flags = fcntl(socket_, F_GETFL, 0);
   if (connTimeout_ > 0) {
@@ -589,4 +598,12 @@ int TSocket::getPeerPort() {
   return peerPort_;
 }
 
+bool TSocket::useLowMinRto_ = false;
+void TSocket::setUseLowMinRto(bool useLowMinRto) {
+  useLowMinRto_ = useLowMinRto;
+}
+bool TSocket::getUseLowMinRto() {
+  return useLowMinRto_;
+}
+
 }}} // apache::thrift::transport

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TSocket.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TSocket.h?rev=920685&r1=920684&r2=920685&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TSocket.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TSocket.h Tue Mar  9 05:20:14 2010
@@ -22,6 +22,7 @@
 
 #include <string>
 #include <sys/time.h>
+#include <netdb.h>
 
 #include "TTransport.h"
 #include "TServerSocket.h"
@@ -182,6 +183,15 @@ class TSocket : public TTransport {
    **/
   int getPeerPort();
 
+  /**
+   * Sets whether to use a low minimum TCP retransmission timeout.
+   */
+  static void setUseLowMinRto(bool useLowMinRto);
+
+  /**
+   * Gets whether to use a low minimum TCP retransmission timeout.
+   */
+  static bool getUseLowMinRto();
 
  protected:
   /**
@@ -234,6 +244,9 @@ class TSocket : public TTransport {
 
   /** Recv timeout timeval */
   struct timeval recvTimeval_;
+
+  /** Whether to use low minimum TCP retransmission timeout */
+  static bool useLowMinRto_;
 };
 
 }}} // apache::thrift::transport