You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2017/01/05 19:47:05 UTC
[04/11] incubator-trafficcontrol git commit: Fix TM2 memory leak from
Tick
Fix TM2 memory leak from Tick
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/35dddc92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/35dddc92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/35dddc92
Branch: refs/heads/master
Commit: 35dddc92a5ad8bf0b06f5606c7943ce3620e7115
Parents: 9ef7364
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Jan 5 09:15:21 2017 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Thu Jan 5 12:46:32 2017 -0700
----------------------------------------------------------------------
traffic_monitor/experimental/common/poller/heap.go | 1 -
traffic_monitor/experimental/common/poller/poller.go | 3 ++-
.../experimental/traffic_monitor/manager/healthresult.go | 8 ++++++--
.../experimental/traffic_monitor/manager/stathistory.go | 9 ++++++---
4 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/35dddc92/traffic_monitor/experimental/common/poller/heap.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/poller/heap.go b/traffic_monitor/experimental/common/poller/heap.go
index c78a64e..e15d61b 100644
--- a/traffic_monitor/experimental/common/poller/heap.go
+++ b/traffic_monitor/experimental/common/poller/heap.go
@@ -20,7 +20,6 @@ package poller
*/
import (
- "fmt"
"sync"
"time"
)
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/35dddc92/traffic_monitor/experimental/common/poller/poller.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/poller/poller.go b/traffic_monitor/experimental/common/poller/poller.go
index ea70eb0..067defd 100644
--- a/traffic_monitor/experimental/common/poller/poller.go
+++ b/traffic_monitor/experimental/common/poller/poller.go
@@ -20,7 +20,6 @@ package poller
*/
import (
- "fmt"
"io/ioutil"
"math/rand"
"net/http"
@@ -120,6 +119,7 @@ func NewMonitorConfig(interval time.Duration) MonitorConfigPoller {
func (p MonitorConfigPoller) Poll() {
tick := time.NewTicker(p.Interval)
+ defer tick.Stop()
for {
select {
case opsConfig := <-p.OpsConfigChannel:
@@ -224,6 +224,7 @@ func sleepPoller(interval time.Duration, id string, url string, fetcher fetcher.
go fetcher.Fetch(id, url, pollId, pollFinishedChan) // TODO persist fetcher, with its own die chan?
<-pollFinishedChan
case <-die:
+ tick.Stop()
return
}
}
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/35dddc92/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
index aac3cf6..e42fb7e 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
@@ -129,14 +129,18 @@ func healthResultManagerListen(
) {
lastHealthEndTimes := map[enum.CacheName]time.Time{}
// This reads at least 1 value from the cacheHealthChan. Then, we loop, and try to read from the channel some more. If there's nothing to read, we hit `default` and process. If there is stuff to read, we read it, then inner-loop trying to read more. If we're continuously reading and the channel is never empty, and we hit the tick time, process anyway even though the channel isn't empty, to prevent never processing (starvation).
+ var ticker *time.Ticker
for {
var results []cache.Result
results = append(results, <-cacheHealthChan)
- tick := time.Tick(cfg.HealthFlushInterval)
+ if ticker != nil {
+ ticker.Stop()
+ }
+ ticker = time.NewTicker(cfg.HealthFlushInterval)
innerLoop:
for {
select {
- case <-tick:
+ case <-ticker.C:
log.Warnf("Health Result Manager flushing queued results\n")
processHealthResult(
cacheHealthChan,
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/35dddc92/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
index 809ceae..c5569fb 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
@@ -75,20 +75,23 @@ func StartStatHistoryManager(
unpolledCaches := threadsafe.NewUnpolledCaches()
tickInterval := cfg.StatFlushInterval
go func() {
-
+ var ticker *time.Ticker
<-cachesChanged // wait for the signal that localStates have been set
unpolledCaches.SetNewCaches(getNewCaches(localStates, monitorConfig))
for {
var results []cache.Result
results = append(results, <-cacheStatChan)
- tick := time.Tick(tickInterval)
+ if ticker != nil {
+ ticker.Stop()
+ }
+ ticker = time.NewTicker(tickInterval)
innerLoop:
for {
select {
case <-cachesChanged:
unpolledCaches.SetNewCaches(getNewCaches(localStates, monitorConfig))
- case <-tick:
+ case <-ticker.C:
log.Warnf("StatHistoryManager flushing queued results\n")
processStatResults(results, statHistory, combinedStates.Get(), lastStats, toData.Get(), errorCount, dsStats, lastStatEndTimes, lastStatDurations, unpolledCaches, monitorConfig.Get())
break innerLoop