]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
AsyncConnection: Optimize _try_send avoid new/delete
authorHaomai Wang <haomaiwang@gmail.com>
Sun, 28 Sep 2014 02:50:28 +0000 (10:50 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Wed, 8 Oct 2014 06:05:00 +0000 (14:05 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/msg/AsyncConnection.cc
src/msg/AsyncConnection.h

index 509e586416d13a1e77e6f5f69e2bfb1493660960..8f91cc9f57212567a5198dc0e5383c23423b2c8d 100644 (file)
@@ -129,6 +129,7 @@ AsyncConnection::AsyncConnection(CephContext *cct, AsyncMessenger *m, EventCente
   write_handler.reset(new C_handle_write(this));
   reset_handler.reset(new C_handle_reset(async_msgr, this));
   remote_reset_handler.reset(new C_handle_remote_reset(async_msgr, this));
+  memset(msgvec, 0, sizeof(msgvec));
 }
 
 AsyncConnection::~AsyncConnection()
@@ -201,8 +202,12 @@ int AsyncConnection::do_sendmsg(struct msghdr &msg, int len, bool more)
 // else return < 0 means error
 int AsyncConnection::_try_send(bufferlist send_bl, bool send)
 {
-  if (send_bl.length())
-    outcoming_bl.claim_append(send_bl);
+  if (send_bl.length()) {
+    if (outcoming_bl.length())
+      outcoming_bl.claim_append(send_bl);
+    else
+      outcoming_bl.swap(send_bl);
+  }
 
   if (!send)
     return 0;
@@ -230,8 +235,7 @@ int AsyncConnection::_try_send(bufferlist send_bl, bool send)
   list<bufferptr>::const_iterator pb = outcoming_bl.buffers().begin();
   while (outcoming_bl.length() > sended) {
     struct msghdr msg;
-    int size = MIN(outcoming_bl.buffers().size(), IOV_MAX);
-    struct iovec *msgvec = new iovec[size];
+    int size = MIN(outcoming_bl.buffers().size(), IOV_LEN);
     memset(&msg, 0, sizeof(msg));
     msg.msg_iovlen = 0;
     msg.msg_iov = msgvec;
@@ -249,7 +253,6 @@ int AsyncConnection::_try_send(bufferlist send_bl, bool send)
     if (r < 0)
       return r;
 
-    delete msgvec;
     // "r" is the remaining length
     sended += msglen - r;
     if (r > 0) {
index 3b352d8ceba90ddfd629a20a4788a247c83952ab..2a116b5b92eeeeb3e4c535b88240e2ce904f67ce 100644 (file)
@@ -20,7 +20,7 @@ using namespace std;
 class AsyncMessenger;
 
 class AsyncConnection : public Connection {
-  const static uint64_t send_threshold = 16 * 1024 * 1024;
+  const static uint64_t IOV_LEN = 1024;
 
   int read_bulk(int fd, char *buf, int len);
   int do_sendmsg(struct msghdr &msg, int len, bool more);
@@ -60,11 +60,6 @@ class AsyncConnection : public Connection {
     state = STATE_ACCEPTING_WAIT_CONNECT_MSG;
     return 0;
   }
-  bool _can_prepare_send() {
-    if (outcoming_bl.length() > send_threshold)
-      return false;
-    return true;
-  }
   bool is_queued() {
     return !out_q.empty() || outcoming_bl.length();
   }
@@ -210,6 +205,7 @@ class AsyncConnection : public Connection {
   EventCallbackRef reset_handler;
   EventCallbackRef remote_reset_handler;
   bool keepalive;
+  struct iovec msgvec[IOV_LEN];
 
   // Tis section are temp variables used by state transition