cmd/swarm: use resetting timer to measure fetch time (#18474)

This commit is contained in:
Anton Evangelatov 2019-01-18 13:27:27 +01:00 committed by GitHub
parent 632135ce4c
commit a0b0db6305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,30 +125,28 @@ func uploadAndSync(c *cli.Context) error {
for {
start := time.Now()
err := fetch(hash, endpoint, fhash, ruid)
fetchTime := time.Since(start)
if err != nil {
continue
}
metrics.GetOrRegisterMeter("upload-and-sync.single.fetch-time", nil).Mark(int64(fetchTime))
metrics.GetOrRegisterResettingTimer("upload-and-sync.single.fetch-time", nil).UpdateSince(start)
wg.Done()
return
}
}(endpoints[randIndex], ruid)
} else {
for _, endpoint := range endpoints {
for _, endpoint := range endpoints[1:] {
ruid := uuid.New()[:8]
wg.Add(1)
go func(endpoint string, ruid string) {
for {
start := time.Now()
err := fetch(hash, endpoint, fhash, ruid)
fetchTime := time.Since(start)
if err != nil {
continue
}
metrics.GetOrRegisterMeter("upload-and-sync.each.fetch-time", nil).Mark(int64(fetchTime))
metrics.GetOrRegisterResettingTimer("upload-and-sync.each.fetch-time", nil).UpdateSince(start)
wg.Done()
return
}