Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, kostja@tarantool.org
Subject: [PATCH v3 5/6] [RAW] swim: send one UDP packet per EV_WRITE event
Date: Sat, 29 Dec 2018 13:14:14 +0300	[thread overview]
Message-ID: <606bb0e206b7f6a4a45a92e9d200e35d58e815f1.1546077015.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1546077015.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1546077015.git.v.shpilevoy@tarantool.org>

Since the first commit of #3234, where anti-entropy component was
introduced, a single SWIM message could be split into multiple
UDP packets. But so far these packets were being sent in mere
'for' loop on a single EV_WRITE event. It is not proper way of
using event loop, but the simplest, because does not require any
externally stored positions in packet lists.

The previous commit introduced such global list of UDP packets to
send, and now it is much simpler to send each packet on separate
EV_WRITE event. This commit does it.

Part of #3234
---
 src/lib/swim/swim_io.c | 19 +++++++++++--------
 src/lib/swim/swim_io.h |  1 +
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/lib/swim/swim_io.c b/src/lib/swim/swim_io.c
index 00a16a2bb..dadf14db2 100644
--- a/src/lib/swim/swim_io.c
+++ b/src/lib/swim/swim_io.c
@@ -60,6 +60,7 @@ swim_task_schedule(struct swim_task *task, swim_transport_send_f send,
 	assert(! swim_task_is_active(task));
 	task->send = send;
 	task->dst = *dst;
+	task->pos = swim_msg_first_packet(&task->msg);
 	rlist_add_tail_entry(&task->scheduler->queue_output, task,
 			     in_queue_output);
 	ev_io_start(loop(), &task->scheduler->output);
@@ -133,19 +134,21 @@ swim_scheduler_on_output(struct ev_loop *loop, struct ev_io *io, int events)
 		return;
 	}
 	struct swim_task *task =
-		rlist_shift_entry(&scheduler->queue_output, struct swim_task,
+		rlist_first_entry(&scheduler->queue_output, struct swim_task,
 				  in_queue_output);
 	say_verbose("SWIM: send to %s",
 		    sio_strfaddr((struct sockaddr *) &task->dst,
 				 sizeof(task->dst)));
-	for (struct swim_packet *packet = swim_msg_first_packet(&task->msg);
-	     packet != NULL; packet = swim_packet_next(packet)) {
-		if (task->send(io->fd, packet->body, packet->pos - packet->body,
-			       (struct sockaddr *) &task->dst,
-			       sizeof(task->dst)) == -1)
-			diag_log();
+	struct swim_packet *packet = task->pos;
+	if (task->send(io->fd, packet->body, packet->pos - packet->body,
+		       (struct sockaddr *) &task->dst,
+		       sizeof(task->dst)) == -1)
+		diag_log();
+	task->pos = swim_packet_next(packet);
+	if (task->pos == NULL) {
+		task->complete(task);
+		rlist_del_entry(task, in_queue_output);
 	}
-	task->complete(task);
 }
 
 static void
diff --git a/src/lib/swim/swim_io.h b/src/lib/swim/swim_io.h
index f08bd1ef3..605542c4e 100644
--- a/src/lib/swim/swim_io.h
+++ b/src/lib/swim/swim_io.h
@@ -256,6 +256,7 @@ struct swim_task {
 	swim_task_f complete;
 	/** Message to send. */
 	struct swim_msg msg;
+	struct swim_packet *pos;
 	/** Destination address. */
 	struct sockaddr_in dst;
 	/** Place in a queue of tasks. */
-- 
2.17.2 (Apple Git-113)

  parent reply	other threads:[~2018-12-29 10:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-29 10:14 [PATCH v3 0/6] SWIM draft Vladislav Shpilevoy
2018-12-29 10:14 ` [PATCH v3 1/6] [RAW] swim: introduce SWIM's anti-entropy component Vladislav Shpilevoy
2019-01-09  9:12   ` [tarantool-patches] " Konstantin Osipov
2019-01-15 14:42     ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-09 11:45   ` [tarantool-patches] " Konstantin Osipov
2019-01-15 14:42     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-29 10:14 ` [PATCH v3 2/6] [RAW] swim: introduce failure detection component Vladislav Shpilevoy
2019-01-09 13:48   ` [tarantool-patches] " Konstantin Osipov
2019-01-15 14:42     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-29 10:14 ` [PATCH v3 3/6] [RAW] swim: introduce a dissemination component Vladislav Shpilevoy
2018-12-29 10:14 ` [PATCH v3 4/6] [RAW] swim: keep encoded round message cached Vladislav Shpilevoy
2018-12-29 10:14 ` Vladislav Shpilevoy [this message]
2019-01-09 13:53   ` [tarantool-patches] [PATCH v3 5/6] [RAW] swim: send one UDP packet per EV_WRITE event Konstantin Osipov
2019-01-15 14:42     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-29 10:14 ` [PATCH v3 6/6] [RAW] swim: introduce payload Vladislav Shpilevoy
2019-01-09 13:58   ` [tarantool-patches] " Konstantin Osipov
2019-01-15 14:42     ` [tarantool-patches] " Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=606bb0e206b7f6a4a45a92e9d200e35d58e815f1.1546077015.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v3 5/6] [RAW] swim: send one UDP packet per EV_WRITE event' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox