cmd/stdiscosrv: Slightly tweak replication settings

This commit is contained in:
Jakob Borg 2023-10-04 11:36:49 +02:00
parent 516c057d43
commit 4f6b86a1c0

View File

@ -19,8 +19,11 @@ import (
"github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/protocol"
) )
const replicationReadTimeout = time.Minute const (
const replicationHeartbeatInterval = time.Second * 30 replicationReadTimeout = time.Minute
replicationWriteTimeout = 30 * time.Second
replicationHeartbeatInterval = time.Second * 30
)
type replicator interface { type replicator interface {
send(key string, addrs []DatabaseAddress, seen int64) send(key string, addrs []DatabaseAddress, seen int64)
@ -68,6 +71,12 @@ func (s *replicationSender) Serve(ctx context.Context) error {
conn.Close() 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. // Get the other side device ID.
remoteID, err := deviceID(conn) remoteID, err := deviceID(conn)
if err != nil { if err != nil {
@ -116,7 +125,7 @@ func (s *replicationSender) Serve(ctx context.Context) error {
binary.BigEndian.PutUint32(buf, uint32(n)) binary.BigEndian.PutUint32(buf, uint32(n))
// Send // Send
conn.SetWriteDeadline(time.Now().Add(5 * time.Second)) conn.SetWriteDeadline(time.Now().Add(replicationWriteTimeout))
if _, err := conn.Write(buf[:4+n]); err != nil { if _, err := conn.Write(buf[:4+n]); err != nil {
replicationSendsTotal.WithLabelValues("error").Inc() replicationSendsTotal.WithLabelValues("error").Inc()
log.Println("Replication write:", err) log.Println("Replication write:", err)