From 739096a9c0673124d474d5e3422a2b8271c5db94 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 25 Feb 2022 19:50:18 +0800 Subject: [PATCH 1/2] statistics performance --- internal/msg_transfer/logic/history_msg_handler.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/msg_transfer/logic/history_msg_handler.go b/internal/msg_transfer/logic/history_msg_handler.go index b78695c11..f0ba102cd 100644 --- a/internal/msg_transfer/logic/history_msg_handler.go +++ b/internal/msg_transfer/logic/history_msg_handler.go @@ -8,6 +8,7 @@ import ( "Open_IM/pkg/grpc-etcdv3/getcdv3" pbMsg "Open_IM/pkg/proto/chat" pbPush "Open_IM/pkg/proto/push" + "Open_IM/pkg/statistics" "Open_IM/pkg/utils" "context" "github.com/Shopify/sarama" @@ -20,9 +21,14 @@ type fcb func(msg []byte, msgKey string) type HistoryConsumerHandler struct { msgHandle map[string]fcb historyConsumerGroup *kfk.MConsumerGroup + singleMsgCount uint64 + groupMsgCount uint64 } func (mc *HistoryConsumerHandler) Init() { + statistics.NewStatistics(&mc.singleMsgCount, config.Config.ModuleName.MsgTransferName, "singleMsgCount insert to mongo ", 10) + statistics.NewStatistics(&mc.singleMsgCount, config.Config.ModuleName.MsgTransferName, "groupMsgCount insert to mongo ", 10) + mc.msgHandle = make(map[string]fcb) mc.msgHandle[config.Config.Kafka.Ws2mschat.Topic] = mc.handleChatWs2Mongo mc.historyConsumerGroup = kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{KafkaVersion: sarama.V0_10_2_0, @@ -55,6 +61,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String()) return } + mc.singleMsgCount++ log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time) } if !isSenderSync && msgKey == msgFromMQ.MsgData.SendID { @@ -70,6 +77,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) log.NewError(operationID, "group data insert to mongo err", msgFromMQ.String(), msgFromMQ.MsgData.RecvID, err.Error()) return } + mc.groupMsgCount++ } go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID) default: From e1f58f07fe9146d58584e753c23e2f34e0bb7e26 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 25 Feb 2022 19:55:58 +0800 Subject: [PATCH 2/2] 2.0.1 --- cmd/Open-IM-SDK-Core | 2 +- pkg/statistics/statistics.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/Open-IM-SDK-Core b/cmd/Open-IM-SDK-Core index 992f76df0..1c6c7af53 160000 --- a/cmd/Open-IM-SDK-Core +++ b/cmd/Open-IM-SDK-Core @@ -1 +1 @@ -Subproject commit 992f76df0ee500a0377523b0780d3a85f2275755 +Subproject commit 1c6c7af5393b3e9eefbaf16b673519ca863a6c2c diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index eb018fbf0..bda8ded85 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -21,7 +21,7 @@ func (s *Statistics) output() { select { case <-t.C: } - log.Debug(s.ModuleName, s.PrintArgs, *s.Count-sum) + log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum) } }