Skip to content

Commit

Permalink
free memory
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyuyan committed Sep 12, 2017
1 parent 9627799 commit 6b50060
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/eclipse/paho.mqtt.golang/packets"
"github.com/shirou/gopsutil/mem"

"golang.org/x/net/websocket"

Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 6b50060

Please sign in to comment.