mirror of
https://github.com/fhmq/hmq.git
synced 2026-04-24 10:38:34 +00:00
free memory
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
|
||||
@@ -84,12 +85,14 @@ func (b *Broker) Start() {
|
||||
}
|
||||
|
||||
func StateMonitor() {
|
||||
// v, _ := mem.VirtualMemory()
|
||||
timeSticker := time.NewTicker(time.Second * 30)
|
||||
v, _ := mem.VirtualMemory()
|
||||
timeSticker := time.NewTicker(time.Second * 5)
|
||||
for {
|
||||
select {
|
||||
case <-timeSticker.C:
|
||||
debug.FreeOSMemory()
|
||||
if v.UsedPercent > 0.8 {
|
||||
debug.FreeOSMemory()
|
||||
}
|
||||
// fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user