From df84efffce4ac45ca97431872fafa45f109a2733 Mon Sep 17 00:00:00 2001 From: lxy <237809796@qq.com> Date: Sat, 25 Sep 2021 17:38:31 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=87=EE=86=BD=E6=95=BC=E9=94=9B=E6=AD=B5op?= =?UTF-8?q?ic=20&=20message=20chan=20overload=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://47.119.165.148/zhub@129 e63fbceb-bcc3-4977-ac22-735b83d8d0f4 --- zsub/zsub.go | 10 +++++++++- zsub/ztopic.go | 13 +++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/zsub/zsub.go b/zsub/zsub.go index e2e49a4..5d83647 100644 --- a/zsub/zsub.go +++ b/zsub/zsub.go @@ -2,6 +2,7 @@ package zsub import ( "bufio" + "fmt" "log" "net" "os" @@ -369,8 +370,15 @@ func (s *ZSub) Publish(topic, msg string) { if ztopic == nil { return } - ztopic.chMsg <- msg ztopic.mcount++ + + // topic chan overload check + if len(ztopic.chMsg) == cap(ztopic.chMsg) { + log.Println(fmt.Sprintf("ztopic no cap: [%s %s]", topic, msg)) + return + } + + ztopic.chMsg <- msg } /* diff --git a/zsub/ztopic.go b/zsub/ztopic.go index c53c748..9b41eb4 100644 --- a/zsub/ztopic.go +++ b/zsub/ztopic.go @@ -1,6 +1,10 @@ package zsub -import "sync" +import ( + "fmt" + "log" + "sync" +) type ZTopic struct { //ZTopic sync.Mutex @@ -19,7 +23,12 @@ func (t *ZTopic) init() { break } - for _, group := range t.groups { + for name, group := range t.groups { + // zgroup chan overload check + if len(group.chMsg) == cap(group.chMsg) { + log.Println(fmt.Sprintf("zgroup no cap: [%s.%s %s]", name, t.topic, msg)) + continue + } group.chMsg <- msg } }