From 17af07cce0537609693642e604e8edea0487b84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 25 Dec 2023 09:24:20 +0800 Subject: [PATCH] =?UTF-8?q?edge-node=20gc=E5=91=BD=E4=BB=A4=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=80=97=E6=97=B6=E5=92=8Cgc=20pause=E6=97=B6?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/edge-node/main.go | 11 +++++++++-- internal/nodes/node.go | 12 +++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cmd/edge-node/main.go b/cmd/edge-node/main.go index a2e525b..a3b4f25 100644 --- a/cmd/edge-node/main.go +++ b/cmd/edge-node/main.go @@ -228,11 +228,18 @@ func main() { }) app.On("gc", func() { var sock = gosock.NewTmpSock(teaconst.ProcessName) - _, err := sock.Send(&gosock.Command{Code: "gc"}) + reply, err := sock.Send(&gosock.Command{Code: "gc"}) if err != nil { fmt.Println("[ERROR]" + err.Error()) } else { - fmt.Println("ok") + if reply == nil { + fmt.Println("ok") + } else { + var paramMap = maps.NewMap(reply.Params) + var pauseMS = paramMap.GetFloat64("pauseMS") + var costMS = paramMap.GetFloat64("costMS") + fmt.Printf("ok, cost: %.4fms, pause: %.4fms", costMS, pauseMS) + } } }) app.On("ip.drop", func() { diff --git a/internal/nodes/node.go b/internal/nodes/node.go index 0955657..734c200 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -777,9 +777,19 @@ func (this *Node) listenSock() error { _ = cmd.ReplyOk() } case "gc": + var before = time.Now() runtime.GC() debug.FreeOSMemory() - _ = cmd.ReplyOk() + + var costSeconds = time.Since(before).Seconds() + var gcStats = &debug.GCStats{} + debug.ReadGCStats(gcStats) + _ = cmd.Reply(&gosock.Command{ + Params: map[string]any{ + "pauseMS": gcStats.PauseTotal.Seconds() * 1000, + "costMS": costSeconds * 1000, + }, + }) case "reload": err := this.syncConfig(0) if err != nil {