Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cpu waste loop #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/rmt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas
tcp_context *tc = trnode->tc;
thread_data *wdata = trnode->write_data;
listNode *lnode_node, *lnode_msg, *lnode_mbuf;
listNode *lnode_mbuf_markidx, *lnode_mbuf_readidx;
list send_msgl; /* send msg list */
struct iovec *ciov, iov[RMT_IOV_MAX];
struct msg *msg;
Expand All @@ -1327,6 +1328,9 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas

ASSERT(fd == tc->sd);

lnode_mbuf_markidx = NULL;
lnode_mbuf_readidx = NULL;

again:

send_again = 1;
Expand All @@ -1340,8 +1344,10 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas
log_debug(LOG_DEBUG, "send_data_to_target node[%s] msgs %lld",
trnode->addr, listLength(trnode->send_data));

lnode_msg = listFirst(trnode->send_data);

if (lnode_mbuf_readidx == NULL) {
lnode_mbuf_readidx = listFirst(msg->data);
}
lnode_mbuf = lnode_mbuf_readidx;
while (lnode_msg != NULL && !stop) {

msg = listNodeValue(lnode_msg);
Expand All @@ -1355,6 +1361,10 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas
if (array_n(&sendv) >= RMT_IOV_MAX ||
nsend >= limit) {
stop = 1;

/* save mbuf readmark idx */
lnode_mbuf_readidx = lnode_mbuf;

break;
}

Expand All @@ -1375,6 +1385,10 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas

lnode_mbuf = listNextNode(lnode_mbuf);
}
if (stop == 0) {
/* reset read watermark */
lnode_mbuf_readidx = NULL;
}

lnode_msg = listNextNode(lnode_msg);
}
Expand Down Expand Up @@ -1422,7 +1436,11 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas
}

/* adjust mbufs of the sent message */
lnode_mbuf = listFirst(msg->data);
if (lnode_mbuf_markidx == NULL) {
lnode_mbuf_markidx = listFirst(msg->data);
}
lnode_mbuf = lnode_mbuf_markidx;

while(lnode_mbuf != NULL){

mbuf = listNodeValue(lnode_mbuf);
Expand All @@ -1438,6 +1456,10 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas
mbuf->pos += nsent;
ASSERT(mbuf->pos < mbuf->last);
nsent = 0;

/* save mark watermark */
lnode_mbuf_markidx = lnode_mbuf;

break;
}

Expand All @@ -1463,6 +1485,8 @@ static void send_data_to_target(aeEventLoop *el, int fd, void *privdata, int mas
msg->sent = 1;
listAddNodeTail(trnode->sent_data,msg);
}
/* reset markidx watermark */
lnode_mbuf_markidx = NULL;
}
}

Expand Down