From 728283543050f1e82e2476a021aff60f1b88012a Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 11:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=8F=90=E7=A4=BA=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sm.go | 9 ++++----- sm_upate_handler.go | 4 +--- websocket.go | 5 +++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/sm.go b/sm.go index 5a6e063..a9e4e39 100644 --- a/sm.go +++ b/sm.go @@ -42,13 +42,12 @@ func NewSMQueue(shardID uint64, replicaID uint64) sm.IStateMachine { var m runtime.MemStats runtime.ReadMemStats(&m) allocMB := float64(m.Alloc) / 1024 / 1024 - totalAllocMB := float64(m.TotalAlloc) / 1024 / 1024 + // totalAllocMB := float64(m.TotalAlloc) / 1024 / 1024 sysMB := float64(m.Sys) / 1024 / 1024 - fmt.Printf("queue remain: %d, Alloc = %.2f MB, TotalAlloc = %.2f MB, Sys = %.2f MB\n", params.Value, allocMB, totalAllocMB, sysMB) - - time.Sleep(time.Second * 5) + fmt.Printf("队列 剩余: %d, Alloc = %.2f MB, Sys = %.2f MB\n", params.Value, allocMB, sysMB) + time.Sleep(time.Second * 1) } else { - time.Sleep(time.Second * 15) + time.Sleep(time.Second * 5) } }), } diff --git a/sm_upate_handler.go b/sm_upate_handler.go index 85fe0e2..ae3c18c 100644 --- a/sm_upate_handler.go +++ b/sm_upate_handler.go @@ -74,9 +74,7 @@ var FsPasser *passer.Passer[sm.Result] = func() *passer.Passer[sm.Result] { e.Result.Data = d result.Data = d if !queue.Empty() { - size := queue.Size() - - smqueue.counter.Notify(size) + smqueue.counter.Notify(queue.Size()) } // log.Println("queue remain:", queue.Size()) diff --git a/websocket.go b/websocket.go index 8fbfd04..7ae390e 100644 --- a/websocket.go +++ b/websocket.go @@ -68,7 +68,7 @@ func queueHandler(w http.ResponseWriter, r *http.Request) { } } - err = conn.SetWriteDeadline(time.Now().Add(time.Second * 8)) + err = conn.SetWriteDeadline(time.Now().Add(time.Second * 6)) if err != nil { log.Println(err) log.Println("重新回队") @@ -84,8 +84,9 @@ func queueHandler(w http.ResponseWriter, r *http.Request) { stateClient.PushItem(nil, item) return } + // 打印消息 - fmt.Printf("%s 处理完成. len\n", conn.RemoteAddr()) + fmt.Printf("%s 的数据 推送到unity. source %s\n", conn.RemoteAddr(), item.Source) } }