From 6238bb3d8be904ff0d6271f95ce5dd24e523ed85 Mon Sep 17 00:00:00 2001 From: Neil Twigg Date: Fri, 7 Feb 2025 15:48:02 +0000 Subject: [PATCH] Apply client write deadline to batches rather than total flushes By calculating the write deadline at the beginning of the flush operation, we could be hitting it early if there is a lot of data queued up. Instead this PR applies it to each `writev` batch of at most 1024 vectors, which means that the deadline applies to no more than 64MB in one go. This makes it simpler to tune the write deadline as it can be thought of as "the maximum time taken to allow writing at most 64MB" instead. Signed-off-by: Neil Twigg --- server/client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/client.go b/server/client.go index ce8ac613c47..6414c277990 100644 --- a/server/client.go +++ b/server/client.go @@ -1642,8 +1642,10 @@ func (c *client) flushOutbound() bool { } consumed := len(wnb) - // Actual write to the socket. - nc.SetWriteDeadline(start.Add(wdl)) + // Actual write to the socket. The deadline applies to each batch + // rather than the total write, such that the configured deadline + // can be tuned to a known maximum quantity (64MB). + nc.SetWriteDeadline(time.Now().Add(wdl)) wn, err = wnb.WriteTo(nc) nc.SetWriteDeadline(time.Time{})