Send all iovecs at once

This commit is contained in:
Vitaliy Filippov
2020-02-29 02:27:19 +03:00
parent fd05e13bc4
commit 56765ab750
5 changed files with 62 additions and 73 deletions
+39 -48
View File
@@ -29,17 +29,15 @@ void osd_t::send_replies()
return;
}
ring_data_t* data = ((ring_data_t*)sqe->user_data);
if (!cl.write_buf)
if (!cl.write_op)
{
// pick next command
cl.write_op = cl.outbox.front();
cl.outbox.pop_front();
cl.write_state = CL_WRITE_REPLY;
if (cl.write_op->op_type == OSD_OP_OUT)
{
gettimeofday(&cl.write_op->tv_send, NULL);
cl.write_buf = &cl.write_op->req.buf;
cl.write_remaining = OSD_PACKET_SIZE;
cl.write_state = CL_WRITE_REPLY;
}
else
{
@@ -51,18 +49,12 @@ void osd_t::send_replies()
(tv_end.tv_sec - cl.write_op->tv_begin.tv_sec)*1000000 +
tv_end.tv_usec - cl.write_op->tv_begin.tv_usec
);
cl.write_buf = &cl.write_op->reply.buf;
cl.write_remaining = OSD_PACKET_SIZE;
cl.write_state = CL_WRITE_REPLY;
}
}
cl.write_iov.iov_base = cl.write_buf;
cl.write_iov.iov_len = cl.write_remaining;
cl.write_msg.msg_iov = &cl.write_iov;
cl.write_msg.msg_iovlen = 1;
cl.write_msg.msg_iov = cl.write_op->send_list.get_iovec();
cl.write_msg.msg_iovlen = cl.write_op->send_list.get_size();
data->callback = [this, peer_fd](ring_data_t *data) { handle_send(data, peer_fd); };
my_uring_prep_sendmsg(sqe, peer_fd, &cl.write_msg, 0);
cl.write_state = cl.write_state | SQE_SENT;
}
write_ready_clients.clear();
}
@@ -80,51 +72,50 @@ void osd_t::handle_send(ring_data_t *data, int peer_fd)
stop_client(peer_fd);
return;
}
cl.write_state = cl.write_state & ~SQE_SENT;
if (data->res > 0)
if (data->res >= 0)
{
cl.write_remaining -= data->res;
cl.write_buf += data->res;
if (cl.write_remaining <= 0)
osd_op_t *cur_op = cl.write_op;
while (data->res > 0 && cur_op->send_list.sent < cur_op->send_list.count)
{
cl.write_buf = NULL;
osd_op_t *cur_op = cl.write_op;
if (cur_op->send_list.sent < cur_op->send_list.count)
iovec & iov = cur_op->send_list.buf[cur_op->send_list.sent];
if (iov.iov_len <= data->res)
{
// Send data
cl.write_buf = cur_op->send_list[cur_op->send_list.sent].buf;
assert(cl.write_buf);
cl.write_remaining = cur_op->send_list[cur_op->send_list.sent].len;
data->res -= iov.iov_len;
cur_op->send_list.sent++;
cl.write_state = CL_WRITE_DATA;
}
else
{
// Done
if (cur_op->op_type == OSD_OP_IN)
{
delete cur_op;
}
else
{
// Measure subops with data
if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_STABILIZE ||
cur_op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE)
{
timeval tv_end;
gettimeofday(&tv_end, NULL);
send_stat_count++;
send_stat_sum += (
(tv_end.tv_sec - cl.write_op->tv_send.tv_sec)*1000000 +
tv_end.tv_usec - cl.write_op->tv_send.tv_usec
);
}
cl.sent_ops[cl.write_op->req.hdr.id] = cl.write_op;
}
cl.write_op = NULL;
cl.write_state = cl.outbox.size() > 0 ? CL_WRITE_READY : 0;
iov.iov_len -= data->res;
iov.iov_base += data->res;
break;
}
}
if (cur_op->send_list.sent >= cur_op->send_list.count)
{
// Done
if (cur_op->op_type == OSD_OP_IN)
{
delete cur_op;
}
else
{
// Measure subops with data
if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_STABILIZE ||
cur_op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE)
{
timeval tv_end;
gettimeofday(&tv_end, NULL);
send_stat_count++;
send_stat_sum += (
(tv_end.tv_sec - cl.write_op->tv_send.tv_sec)*1000000 +
tv_end.tv_usec - cl.write_op->tv_send.tv_usec
);
}
cl.sent_ops[cl.write_op->req.hdr.id] = cl.write_op;
}
cl.write_op = NULL;
cl.write_state = cl.outbox.size() > 0 ? CL_WRITE_READY : 0;
}
}
if (cl.write_state != 0)
{