From 4f6b86a1c09b99aeb239d49c92ea7036f7a24e9e Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 4 Oct 2023 11:36:49 +0200 Subject: [PATCH] cmd/stdiscosrv: Slightly tweak replication settings --- cmd/stdiscosrv/replication.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/stdiscosrv/replication.go b/cmd/stdiscosrv/replication.go index f21c9cc01..8d0db3f7b 100644 --- a/cmd/stdiscosrv/replication.go +++ b/cmd/stdiscosrv/replication.go @@ -19,8 +19,11 @@ import ( "github.com/syncthing/syncthing/lib/protocol" ) -const replicationReadTimeout = time.Minute -const replicationHeartbeatInterval = time.Second * 30 +const ( + replicationReadTimeout = time.Minute + replicationWriteTimeout = 30 * time.Second + replicationHeartbeatInterval = time.Second * 30 +) type replicator interface { send(key string, addrs []DatabaseAddress, seen int64) @@ -68,6 +71,12 @@ func (s *replicationSender) Serve(ctx context.Context) error { conn.Close() }() + // The replication stream is not especially latency sensitive, but it is + // quite a lot of data in small writes. Make it more efficient. + if tcpc, ok := conn.NetConn().(*net.TCPConn); ok { + _ = tcpc.SetNoDelay(false) + } + // Get the other side device ID. remoteID, err := deviceID(conn) if err != nil { @@ -116,7 +125,7 @@ func (s *replicationSender) Serve(ctx context.Context) error { binary.BigEndian.PutUint32(buf, uint32(n)) // Send - conn.SetWriteDeadline(time.Now().Add(5 * time.Second)) + conn.SetWriteDeadline(time.Now().Add(replicationWriteTimeout)) if _, err := conn.Write(buf[:4+n]); err != nil { replicationSendsTotal.WithLabelValues("error").Inc() log.Println("Replication write:", err)