Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#979 from gmarek/scalability
Browse files Browse the repository at this point in the history
simplify sleep logic a bit
  • Loading branch information
mwielgus committed Feb 16, 2016
2 parents 56603af + 1017936 commit d26d138
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions metrics/sources/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
)

const (
DefaultMetricsScrapeTimeout = 20 * time.Second
MaxDelayInMs = 4 * 1000
MaxDelayIntroductionClusterSizeThreshold = 500
DefaultMetricsScrapeTimeout = 20 * time.Second
MaxDelayMs = 4 * 1000
DelayPerSourceMs = 8
)

var (
Expand Down Expand Up @@ -83,17 +83,17 @@ func (this *sourceManager) ScrapeMetrics(start, end time.Time) *DataBatch {
startTime := time.Now()
timeoutTime := startTime.Add(this.metricsScrapeTimeout)

delayInMs := (MaxDelayInMs * len(sources)) / MaxDelayIntroductionClusterSizeThreshold
if delayInMs > MaxDelayInMs {
delayInMs = MaxDelayInMs
delayMs := DelayPerSourceMs * len(sources)
if delayMs > MaxDelayMs {
delayMs = MaxDelayMs
}

for _, source := range sources {

go func(source MetricsSource, channel chan *DataBatch, start, end, timeoutTime time.Time, delayInMs int) {

// Prevents network congestion.
time.Sleep(time.Duration(rand.Intn(delayInMs)) * time.Millisecond)
time.Sleep(time.Duration(rand.Intn(delayMs)) * time.Millisecond)

glog.V(2).Infof("Querying source: %s", source)
metrics := scrape(source, start, end)
Expand All @@ -112,7 +112,7 @@ func (this *sourceManager) ScrapeMetrics(start, end time.Time) *DataBatch {
glog.Warningf("Failed to send the response back %s", source)
return
}
}(source, responseChannel, start, end, timeoutTime, delayInMs)
}(source, responseChannel, start, end, timeoutTime, delayMs)
}
response := DataBatch{
Timestamp: end,
Expand Down

0 comments on commit d26d138

Please sign in to comment.