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:10 UTC

[09/11] incubator-trafficcontrol git commit: Change TM2 to reduce CPU usage

Change TM2 to reduce CPU usage

Changes Traffic Monitor 2.0 pollers to not lock the goroutine to the
OS thread, changes pollers to sleep for 100ms when the poll
queue is empty (and amortize back to the poll interval by reducing
the set interval by the same amount), changes GOMAXPROCS from 3x to
1x the core count, with the aim of reducing CPU usage.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/93adeaf9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/93adeaf9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/93adeaf9

Branch: refs/heads/master
Commit: 93adeaf97a2fb539ee0d8ae3b4e5cdb46f9f6c67
Parents: a595c10
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Dec 8 15:44:42 2016 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Thu Jan 5 12:46:32 2017 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/common/poller/poller.go  | 14 +++++++-------
 .../experimental/traffic_monitor/traffic_monitor.go   |  5 +----
 2 files changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/93adeaf9/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 067defd..65288fc 100644
--- a/traffic_monitor/experimental/common/poller/poller.go
+++ b/traffic_monitor/experimental/common/poller/poller.go
@@ -24,7 +24,6 @@ import (
 	"math/rand"
 	"net/http"
 	"os"
-	"runtime"
 	"sync/atomic"
 	"time"
 
@@ -230,6 +229,8 @@ func sleepPoller(interval time.Duration, id string, url string, fetcher fetcher.
 	}
 }
 
+const InsomniacPollerEmptySleepDuration = time.Millisecond * time.Duration(100)
+
 // InsomniacPoll polls using a single thread, which never sleeps. This exists to work around a bug observed in OpenStack CentOS 6.5 kernel 2.6.32 wherin sleep gets progressively slower. This should be removed and Poll() changed to call SleepPoll() when the bug is tracked down and fixed for production.
 func (p HttpPoller) InsomniacPoll() {
 	// iterationCount := uint64(0)
@@ -253,7 +254,7 @@ func (p HttpPoller) InsomniacPoll() {
 		polls := []HTTPPollInfo{}
 		for id, pollCfg := range newCfg.Urls {
 			polls = append(polls, HTTPPollInfo{
-				Interval: newCfg.Interval,
+				Interval: newCfg.Interval - InsomniacPollerEmptySleepDuration,
 				ID:       id,
 				URL:      pollCfg.URL,
 				Timeout:  pollCfg.Timeout,
@@ -265,7 +266,6 @@ func (p HttpPoller) InsomniacPoll() {
 }
 
 func insomniacPoller(pollerId int64, polls []HTTPPollInfo, fetcherTemplate fetcher.HttpFetcher, die <-chan struct{}) {
-	runtime.LockOSThread()
 	heap := Heap{PollerID: pollerId}
 	start := time.Now()
 	fetchers := map[string]fetcher.Fetcher{}
@@ -303,14 +303,14 @@ func insomniacPoller(pollerId int64, polls []HTTPPollInfo, fetcherTemplate fetch
 	}
 
 	for {
-		if mustDie(die) {
-			return
-		}
 		p, ok := heap.Pop()
 		if !ok {
-			ThreadSleep(0)
+			ThreadSleep(InsomniacPollerEmptySleepDuration)
 			continue
 		}
+		if mustDie(die) {
+			return
+		}
 		ThreadSleep(p.Next.Sub(time.Now()))
 		go poll(p)
 	}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/93adeaf9/traffic_monitor/experimental/traffic_monitor/traffic_monitor.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/traffic_monitor.go b/traffic_monitor/experimental/traffic_monitor/traffic_monitor.go
index f2b5444..671e10e 100644
--- a/traffic_monitor/experimental/traffic_monitor/traffic_monitor.go
+++ b/traffic_monitor/experimental/traffic_monitor/traffic_monitor.go
@@ -115,11 +115,8 @@ func getLogWriters(errLoc, warnLoc, infoLoc, debugLoc string) (io.Writer, io.Wri
 	return errW, warnW, infoW, debugW, nil
 }
 
-// NumLockedThreads is the number of threads which will be locked to a single goroutine. Ideally this would be computed, but there's no easy way to do that, and it isn't critical. This only protects against the case where a user has a single core, or manually changes GOMAXPROCS to a small number.
-const NumLockedThreads = 3
-
 func main() {
-	runtime.GOMAXPROCS(runtime.NumCPU()*3 + NumLockedThreads)
+	runtime.GOMAXPROCS(runtime.NumCPU())
 
 	staticData, err := getStaticAppData()
 	if err != nil {