Implemented hot swap of autogc

This commit is contained in:
w1n2k 2017-01-19 19:00:14 +03:00
parent e65e5842f4
commit f0fb28c68d
1 changed files with 19 additions and 10 deletions

View File

@ -230,25 +230,34 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener, http
} }
func (c *Controller) watchGC() { func (c *Controller) watchGC() {
autoGC := c.config.AutoGC var elapsed uint64
t := time.NewTicker(time.Second)
defer t.Stop()
for range t.C {
elapsed++
c.mu.RLock()
autoGC := c.config.AutoGC
c.mu.RUnlock()
func() {
if autoGC == 0 { if autoGC == 0 {
return return
} }
t := time.NewTicker(time.Second * time.Duration(autoGC))
defer t.Stop()
for range t.C {
func() {
c.mu.RLock()
if c.stopWatchingAutoGC { if c.stopWatchingAutoGC {
c.mu.RUnlock()
return return
} }
if elapsed < autoGC {
return
}
c.mu.RLock()
runtime.GC() runtime.GC()
debug.FreeOSMemory() debug.FreeOSMemory()
c.mu.RUnlock()
elapsed = 0
}() }()
} }
} }