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