1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-09 09:35:03 +09:00

Fast ttl for connections and marshal append

This commit is contained in:
mcrakhman 2024-07-15 23:29:25 +02:00
parent 4c42f499d1
commit a5d2bbe830
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
4 changed files with 13 additions and 10 deletions

2
go.mod
View file

@ -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

4
go.sum
View file

@ -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=

View file

@ -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()
}

View file

@ -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