mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Add metadata parsing to be inside mutex to slow down (#8952)
Adding mutex slows down the crawler to avoid large spikes in CPU, also add millisecond interval jitter in calculation of disk usage to slow down the spikes further.
This commit is contained in:
parent
b1bfd75fcf
commit
49df290270
@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -159,13 +160,19 @@ 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
|
||||||
@ -183,6 +190,9 @@ func updateUsage(basePath string, doneCh <-chan struct{}, waitForLowActiveIO fun
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
|
||||||
if typ&os.ModeDir != 0 {
|
if typ&os.ModeDir != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -192,12 +202,10 @@ func updateUsage(basePath string, doneCh <-chan struct{}, waitForLowActiveIO fun
|
|||||||
return errSkipFile
|
return errSkipFile
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.Lock()
|
|
||||||
dataUsageInfo.ObjectsCount++
|
dataUsageInfo.ObjectsCount++
|
||||||
dataUsageInfo.ObjectsTotalSize += uint64(size)
|
dataUsageInfo.ObjectsTotalSize += uint64(size)
|
||||||
dataUsageInfo.BucketsSizes[bucket] += uint64(size)
|
dataUsageInfo.BucketsSizes[bucket] += uint64(size)
|
||||||
dataUsageInfo.ObjectsSizesHistogram[objSizeToHistoInterval(uint64(size))]++
|
dataUsageInfo.ObjectsSizesHistogram[objSizeToHistoInterval(uint64(size))]++
|
||||||
mutex.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user