mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Time getSize and use to estimate latency (#8959)
Remove the random sleep. This is running in 4 goroutines, so mostly doing nothing. We use the getSize latency to estimate system load, meaning when there is little load on the system and we get the result fast we sleep a little. If it took a long time we have high load and release ourselves longer. We are sleeping inside the mutex so this affects all goroutines doing IO.
This commit is contained in:
parent
6d5d77f62c
commit
2165d45d3f
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -160,19 +159,12 @@ func updateUsage(basePath string, doneCh <-chan struct{}, waitForLowActiveIO fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
numWorkers := 4
|
numWorkers := 4
|
||||||
walkInterval := 1 * time.Millisecond
|
|
||||||
|
|
||||||
var mutex sync.Mutex // Mutex to update dataUsageInfo
|
var mutex sync.Mutex // Mutex to update dataUsageInfo
|
||||||
|
|
||||||
r := rand.New(rand.NewSource(UTCNow().UnixNano()))
|
|
||||||
|
|
||||||
fastWalk(basePath, numWorkers, doneCh, func(path string, typ os.FileMode) error {
|
fastWalk(basePath, numWorkers, doneCh, func(path string, typ os.FileMode) error {
|
||||||
// Wait for I/O to go down.
|
// Wait for I/O to go down.
|
||||||
waitForLowActiveIO()
|
waitForLowActiveIO()
|
||||||
|
|
||||||
// Randomize sleep intervals, to stagger the walk.
|
|
||||||
defer time.Sleep(time.Duration(r.Float64() * float64(walkInterval)))
|
|
||||||
|
|
||||||
bucket, entry := path2BucketObjectWithBasePath(basePath, path)
|
bucket, entry := path2BucketObjectWithBasePath(basePath, path)
|
||||||
if bucket == "" {
|
if bucket == "" {
|
||||||
return nil
|
return nil
|
||||||
@ -197,7 +189,13 @@ func updateUsage(basePath string, doneCh <-chan struct{}, waitForLowActiveIO fun
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t := time.Now()
|
||||||
size, err := getSize(Item{path, typ})
|
size, err := getSize(Item{path, typ})
|
||||||
|
// Use the response time of the getSize call to guess system load.
|
||||||
|
// Sleep equivalent time.
|
||||||
|
if d := time.Since(t); d > 100*time.Microsecond {
|
||||||
|
time.Sleep(d)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errSkipFile
|
return errSkipFile
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user