From: Haomai Wang Date: Sun, 28 Sep 2014 02:50:28 +0000 (+0800) Subject: AsyncConnection: Optimize _try_send avoid new/delete X-Git-Tag: v0.88~37^2~4^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e1eec9a0524164817bb6fd9454f26f4a294859e8;p=ceph.git AsyncConnection: Optimize _try_send avoid new/delete Signed-off-by: Haomai Wang --- diff --git a/src/msg/AsyncConnection.cc b/src/msg/AsyncConnection.cc index 509e586416d1..8f91cc9f5721 100644 --- a/src/msg/AsyncConnection.cc +++ b/src/msg/AsyncConnection.cc @@ -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::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) { diff --git a/src/msg/AsyncConnection.h b/src/msg/AsyncConnection.h index 3b352d8ceba9..2a116b5b92ee 100644 --- a/src/msg/AsyncConnection.h +++ b/src/msg/AsyncConnection.h @@ -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