From 67c97c680411eadc059fbae861c2e9aa445fbcb9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 20 Jan 2023 18:04:20 +0300 Subject: [PATCH] [#2210] services/tree: Drop messages not in queue Currently, under high load clients are blocked on channel send and the number of goroutines can increase indefinitely. In this commit we drop replication messages if send/recv queue is full and rely on a background synchronization. Signed-off-by: Evgenii Stratonikov --- pkg/services/tree/replicator.go | 2 +- pkg/services/tree/service.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/services/tree/replicator.go b/pkg/services/tree/replicator.go index 4aa1d710..b07f5f21 100644 --- a/pkg/services/tree/replicator.go +++ b/pkg/services/tree/replicator.go @@ -148,7 +148,7 @@ func (s *Service) pushToQueue(cid cidSDK.ID, treeID string, op *pilorama.LogMove treeID: treeID, op: op, }: - case <-s.closeCh: + default: } } diff --git a/pkg/services/tree/service.go b/pkg/services/tree/service.go index 440165be..acec01f6 100644 --- a/pkg/services/tree/service.go +++ b/pkg/services/tree/service.go @@ -485,7 +485,8 @@ func (s *Service) Apply(_ context.Context, req *ApplyRequest) (*ApplyResponse, e return nil, fmt.Errorf("can't parse meta-information: %w", err) } - s.replicateLocalCh <- applyOp{ + select { + case s.replicateLocalCh <- applyOp{ treeID: req.GetBody().GetTreeId(), CIDDescriptor: pilorama.CIDDescriptor{CID: cid, Position: pos, Size: size}, Move: pilorama.Move{ @@ -493,6 +494,8 @@ func (s *Service) Apply(_ context.Context, req *ApplyRequest) (*ApplyResponse, e Child: op.GetChildId(), Meta: meta, }, + }: + default: } return &ApplyResponse{Body: &ApplyResponse_Body{}, Signature: &Signature{}}, nil }