From 64197d15bebcc668480523cde465953780fe10d1 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 13 Oct 2018 12:46:14 +0000 Subject: [PATCH 1/2] Rate limit report publishing So that, if many shortcut reports are produced in quick succession, they will tend to get merged together. Expand the queue size for shortcut reports, to avoid holding up the producer so much. --- probe/probe.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/probe/probe.go b/probe/probe.go index b34f21cde..1e386850d 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -1,17 +1,20 @@ package probe import ( + "context" "sync" "time" "github.com/armon/go-metrics" log "github.com/sirupsen/logrus" + "golang.org/x/time/rate" "github.com/weaveworks/scope/report" ) const ( - reportBufferSize = 16 + spiedReportBufferSize = 16 + shortcutReportBufferSize = 1024 ) // ReportPublisher publishes reports, probably to a remote collector. @@ -23,6 +26,7 @@ type ReportPublisher interface { type Probe struct { spyInterval, publishInterval time.Duration publisher ReportPublisher + rateLimiter *rate.Limiter noControls bool tickers []Ticker @@ -79,10 +83,11 @@ func New( spyInterval: spyInterval, publishInterval: publishInterval, publisher: publisher, + rateLimiter: rate.NewLimiter(rate.Every(publishInterval)*10, 1), noControls: noControls, quit: make(chan struct{}), - spiedReports: make(chan report.Report, reportBufferSize), - shortcutReports: make(chan report.Report, reportBufferSize), + spiedReports: make(chan report.Report, spiedReportBufferSize), + shortcutReports: make(chan report.Report, shortcutReportBufferSize), } return result } @@ -197,6 +202,7 @@ func (p *Probe) tag(r report.Report) report.Report { } func (p *Probe) drainAndPublish(rpt report.Report, rs chan report.Report) { + p.rateLimiter.Wait(context.Background()) ForLoop: for { select { From 195c4e030ef18ea22bdbbc257a216665a55f9a4b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 14 Oct 2018 12:04:03 +0000 Subject: [PATCH 2/2] Raise report publishing rate to 30ms default --- probe/probe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/probe/probe.go b/probe/probe.go index 1e386850d..4e9bac59e 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -83,7 +83,7 @@ func New( spyInterval: spyInterval, publishInterval: publishInterval, publisher: publisher, - rateLimiter: rate.NewLimiter(rate.Every(publishInterval)*10, 1), + rateLimiter: rate.NewLimiter(rate.Every(publishInterval/100), 1), noControls: noControls, quit: make(chan struct{}), spiedReports: make(chan report.Report, spiedReportBufferSize),