Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 4/4] swim: do not rebuild packet meta multiple times
Date: Wed, 17 Apr 2019 22:56:37 +0300	[thread overview]
Message-ID: <11325bc37ed084aac81f9bcdb8b8a041f43e08e4.1555530516.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1555530516.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1555530516.git.v.shpilevoy@tarantool.org>

Before the patch there were 2 cases when an unchanged packet was
rebuilt partially on each send:

  - cached round message's meta section was rebuilt on each
    EV_WRITE event in swim_scheduler_on_output() function;

  - broadcast message's meta section was rebuilt too even though
    its content does not depend on a broadcast interface.

The third case appears with indirect pings patch which aggravates
meta building business by routing and packet forwarding. When a
packet needs to be forwarded farther, its meta is built in a
special manner preserving the route before EV_WRITE appears, and
on_output should not touch that meta.

This patch adds a check preventing unnecessary meta rebuilds.
Besides, the check and the meta building code are moved into a
dedicated function out of swim_scheduler_on_output() - it allows
to completely split logic of packing a message and sending it.
Separated logic helps a lot when indirect pings are introduced.

Part of #3234
---
 src/lib/swim/swim_io.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/lib/swim/swim_io.c b/src/lib/swim/swim_io.c
index 03d79ae3e..7d6addf02 100644
--- a/src/lib/swim/swim_io.c
+++ b/src/lib/swim/swim_io.c
@@ -57,6 +57,31 @@ swim_packet_create(struct swim_packet *packet)
 	swim_packet_alloc_meta(packet, sizeof(struct swim_meta_header_bin));
 }
 
+/** Fill metadata prefix of a packet. */
+static inline void
+swim_packet_build_meta(struct swim_packet *packet,
+		       const struct sockaddr_in *src)
+{
+	char *meta = packet->meta;
+	char *end = packet->body;
+	/*
+	 * Meta has already been built. It happens when the same
+	 * task is resent multiple times.
+	 */
+	if (meta == end)
+		return;
+	struct swim_meta_header_bin header;
+	swim_meta_header_bin_create(&header, src);
+	assert(meta + sizeof(header) == end);
+	memcpy(meta, &header, sizeof(header));
+	/*
+	 * Once meta is built, it is consumed by the body. Used
+	 * not to rebuild the meta again if the task will be
+	 * scheduled again without changes in data.
+	 */
+	packet->body = packet->meta;
+}
+
 void
 swim_task_create(struct swim_task *task, swim_task_f complete,
 		 swim_task_f cancel, const char *desc)
@@ -298,9 +323,7 @@ swim_scheduler_on_output(struct ev_loop *loop, struct ev_io *io, int events)
 	say_verbose("SWIM %d: send %s to %s", swim_scheduler_fd(scheduler),
 		    task->desc, sio_strfaddr((struct sockaddr *) &task->dst,
 					     sizeof(task->dst)));
-	struct swim_meta_header_bin header;
-	swim_meta_header_bin_create(&header, &scheduler->transport.addr);
-	memcpy(task->packet.meta, &header, sizeof(header));
+	swim_packet_build_meta(&task->packet, &scheduler->transport.addr);
 	int rc = swim_transport_send(&scheduler->transport, task->packet.buf,
 				     task->packet.pos - task->packet.buf,
 				     (const struct sockaddr *) &task->dst,
-- 
2.17.2 (Apple Git-113)

  parent reply	other threads:[~2019-04-17 19:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-17 19:56 [tarantool-patches] [PATCH 0/4] swim suspicion preparation Vladislav Shpilevoy
2019-04-17 19:56 ` [tarantool-patches] [PATCH 1/4] swim: move sockaddr_in checkers to swim_proto.h Vladislav Shpilevoy
2019-04-18 11:35   ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-18 15:16     ` Konstantin Osipov
2019-04-18 15:24       ` Vladislav Shpilevoy
2019-04-18 16:02         ` Konstantin Osipov
2019-04-18 18:34           ` Vladislav Shpilevoy
2019-04-18 15:15   ` Konstantin Osipov
2019-04-17 19:56 ` [tarantool-patches] [PATCH 2/4] swim: extract binary ip/port into a separate struct Vladislav Shpilevoy
2019-04-18 15:17   ` [tarantool-patches] " Konstantin Osipov
2019-04-18 18:34     ` Vladislav Shpilevoy
2019-04-17 19:56 ` [tarantool-patches] [PATCH 3/4] swim: fix a bug with invalidation of round msg in fly Vladislav Shpilevoy
2019-04-18 15:19   ` [tarantool-patches] " Konstantin Osipov
2019-04-18 18:34     ` Vladislav Shpilevoy
2019-04-17 19:56 ` Vladislav Shpilevoy [this message]
2019-04-18 17:23   ` [tarantool-patches] Re: [PATCH 4/4] swim: do not rebuild packet meta multiple times Konstantin Osipov
2019-04-18 18:34     ` 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=11325bc37ed084aac81f9bcdb8b8a041f43e08e4.1555530516.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 4/4] swim: do not rebuild packet meta multiple times' \
    /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