From a5d2bbe830c9557905b6a89a6b21a0fafa18c18a Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 15 Jul 2024 23:29:25 +0200 Subject: [PATCH] Fast ttl for connections and marshal append --- go.mod | 2 +- go.sum | 4 ++-- net/peer/peer.go | 1 + net/pool/poolservice.go | 16 +++++++++------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index b51a0feb..ebc4468f 100644 --- a/go.mod +++ b/go.mod @@ -101,4 +101,4 @@ require ( lukechampine.com/blake3 v1.2.1 // indirect ) -replace github.com/gogo/protobuf => github.com/anyproto/protobuf v1.3.3-0.20240715193215-a93dfa8960ec +replace github.com/gogo/protobuf => github.com/anyproto/protobuf v1.3.3-0.20240715205950-2af411f17dfa diff --git a/go.sum b/go.sum index c326bcc9..75108225 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/anyproto/go-slip10 v1.0.0 h1:uAEtSuudR3jJBOfkOXf3bErxVoxbuKwdoJN55M1i github.com/anyproto/go-slip10 v1.0.0/go.mod h1:BCmIlM1KB8wX6K4/8pOvxPl9oVKfEvZ5vsmO5rkK6vg= github.com/anyproto/go-slip21 v1.0.0 h1:CI7lUqTIwmPOEGVAj4jyNLoICvueh++0U2HoAi3m2ZY= github.com/anyproto/go-slip21 v1.0.0/go.mod h1:gbIJt7HAdr5DuT4f2pFTKCBSUWYsm/fysHBNqgsuxT0= -github.com/anyproto/protobuf v1.3.3-0.20240715193215-a93dfa8960ec h1:rgT7SEusQCNhehj4r9De3fx6rIpNsXDpH4J4OFbReWQ= -github.com/anyproto/protobuf v1.3.3-0.20240715193215-a93dfa8960ec/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/anyproto/protobuf v1.3.3-0.20240715205950-2af411f17dfa h1:uQImj4hK8HwkOcxhy/88/+jQpH0n2jX2Iryz6vomhM0= +github.com/anyproto/protobuf v1.3.3-0.20240715205950-2af411f17dfa/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o= github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= diff --git a/net/peer/peer.go b/net/peer/peer.go index e85691d3..b29e8e1b 100644 --- a/net/peer/peer.go +++ b/net/peer/peer.go @@ -265,6 +265,7 @@ func (p *peer) TryClose(objectTTL time.Duration) (res bool, err error) { objectTTL = time.Duration(ttl) * time.Second } aliveCount := p.gc(objectTTL) + log.Debug("peer gc", zap.String("peerId", p.id), zap.Int("aliveCount", aliveCount)) if aliveCount == 0 && p.created.Add(time.Minute).Before(time.Now()) { return true, p.Close() } diff --git a/net/pool/poolservice.go b/net/pool/poolservice.go index 0c574eb4..7e6d4822 100644 --- a/net/pool/poolservice.go +++ b/net/pool/poolservice.go @@ -2,14 +2,16 @@ package pool import ( "context" + "time" + + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "github.com/anyproto/any-sync/app" "github.com/anyproto/any-sync/app/logger" "github.com/anyproto/any-sync/app/ocache" "github.com/anyproto/any-sync/metric" "github.com/anyproto/any-sync/net/peer" - "github.com/prometheus/client_golang/prometheus" - "go.uber.org/zap" - "time" ) const ( @@ -49,8 +51,8 @@ func (p *poolService) Init(a *app.App) (err error) { return p.dialer.Dial(ctx, id) }, ocache.WithLogger(log.Sugar()), - ocache.WithGCPeriod(time.Minute/2), - ocache.WithTTL(time.Minute), + ocache.WithGCPeriod(time.Second*5), + ocache.WithTTL(time.Second*10), ocache.WithPrometheus(p.metricReg, "netpool", "outgoing"), ) p.pool.incoming = ocache.New( @@ -58,8 +60,8 @@ func (p *poolService) Init(a *app.App) (err error) { return nil, ocache.ErrNotExists }, ocache.WithLogger(log.Sugar()), - ocache.WithGCPeriod(time.Minute/2), - ocache.WithTTL(time.Minute), + ocache.WithGCPeriod(time.Second*5), + ocache.WithTTL(time.Second*10), ocache.WithPrometheus(p.metricReg, "netpool", "incoming"), ) return nil