-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak Badger GC and expose several Badger config options (#94)
* Add value log GC * Add various badger options and tweak our GC * Add more metrics and PR comments * PR Comments * Fix metrics * Fix latency metrics * Minot comment tweaks
- Loading branch information
1 parent
6ec9eb4
commit 4b0a27e
Showing
10 changed files
with
341 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package storemanager | ||
|
||
import ( | ||
"fmt" | ||
"github.com/golang/glog" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/salesforce/sloop/pkg/sloop/store/untyped/badgerwrap" | ||
"github.com/spf13/afero" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
const vlogExt = ".vlog" // value log data | ||
const sstExt = ".sst" // LSM data | ||
|
||
var ( | ||
metricStoreSizeOnDiskMb = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_store_sizeondiskmb"}) | ||
metricBadgerKeys = promauto.NewGaugeVec(prometheus.GaugeOpts{Name: "sloop_badger_keys"}, []string{"level"}) | ||
metricBadgerTables = promauto.NewGaugeVec(prometheus.GaugeOpts{Name: "sloop_badger_tables"}, []string{"level"}) | ||
metricBadgerLsmFileCount = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_badger_lsmfilecount"}) | ||
metricBadgerLsmSizeMb = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_badger_lsmsizemb"}) | ||
metricBadgerVLogFileCount = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_badger_vlogfilecount"}) | ||
metricBadgerVLogSizeMb = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_badger_vlogsizemb"}) | ||
) | ||
|
||
type storeStats struct { | ||
timestamp time.Time | ||
DiskSizeBytes uint64 | ||
DiskLsmBytes uint64 | ||
DiskLsmFileCount int | ||
DiskVlogBytes uint64 | ||
DiskVlogFileCount int | ||
LevelToKeyCount map[int]uint64 | ||
LevelToTableCount map[int]int | ||
} | ||
|
||
func generateStats(storeRoot string, db badgerwrap.DB, fs *afero.Afero) *storeStats { | ||
ret := &storeStats{} | ||
ret.LevelToKeyCount = make(map[int]uint64) | ||
ret.LevelToTableCount = make(map[int]int) | ||
ret.timestamp = time.Now() | ||
|
||
totalSizeBytes, extFileCount, extByteCount, err := getDirSizeRecursive(storeRoot, fs) | ||
if err != nil { | ||
// Swallowing on purpose as we still want the other stats | ||
glog.Errorf("Failed to check storage size on disk: %v", err) | ||
} | ||
ret.DiskSizeBytes = totalSizeBytes | ||
ret.DiskLsmFileCount = extFileCount[sstExt] | ||
ret.DiskLsmBytes = extByteCount[sstExt] | ||
ret.DiskVlogFileCount = extFileCount[vlogExt] | ||
ret.DiskVlogBytes = extByteCount[vlogExt] | ||
|
||
tables := db.Tables(true) | ||
for _, table := range tables { | ||
glog.V(2).Infof("BadgerDB TABLE id=%v keycount=%v level=%v left=%q right=%q", table.ID, table.KeyCount, table.Level, string(table.Left), string(table.Right)) | ||
ret.LevelToTableCount[table.Level] += 1 | ||
ret.LevelToKeyCount[table.Level] += table.KeyCount | ||
} | ||
|
||
glog.Infof("Finished updating store stats: %+v", ret) | ||
return ret | ||
} | ||
|
||
// Returns total size, count of files by extension, count of bytes by extension | ||
func getDirSizeRecursive(root string, fs *afero.Afero) (uint64, map[string]int, map[string]uint64, error) { | ||
var totalSize uint64 | ||
var extFileCount = make(map[string]int) | ||
var extByteCount = make(map[string]uint64) | ||
|
||
err := fs.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if !info.IsDir() { | ||
totalSize += uint64(info.Size()) | ||
ext := filepath.Ext(path) | ||
extFileCount[ext] += 1 | ||
extByteCount[ext] += uint64(info.Size()) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return 0, extFileCount, extByteCount, err | ||
} | ||
|
||
return totalSize, extFileCount, extByteCount, nil | ||
} | ||
|
||
func emitMetrics(stats *storeStats) { | ||
metricStoreSizeOnDiskMb.Set(float64(stats.DiskSizeBytes / 1024 / 1024)) | ||
for k, v := range stats.LevelToKeyCount { | ||
metricBadgerKeys.WithLabelValues(fmt.Sprintf("%v", k)).Set(float64(v)) | ||
} | ||
for k, v := range stats.LevelToTableCount { | ||
metricBadgerTables.WithLabelValues(fmt.Sprintf("%v", k)).Set(float64(v)) | ||
} | ||
metricBadgerLsmFileCount.Set(float64(stats.DiskLsmFileCount)) | ||
metricBadgerLsmSizeMb.Set(float64(stats.DiskLsmBytes / 1024 / 1024)) | ||
metricBadgerVLogFileCount.Set(float64(stats.DiskVlogFileCount)) | ||
metricBadgerVLogSizeMb.Set(float64(stats.DiskVlogBytes / 1024 / 1024)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package storemanager | ||
|
||
import ( | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/assert" | ||
"path" | ||
"testing" | ||
) | ||
|
||
func Test_GetDirSizeRecursive(t *testing.T) { | ||
fs := afero.Afero{Fs: afero.NewMemMapFs()} | ||
fs.MkdirAll(someDir, 0700) | ||
// 3 vlog files | ||
fs.WriteFile(path.Join(someDir, "000010.vlog"), []byte("a"), 0700) | ||
fs.WriteFile(path.Join(someDir, "000011.vlog"), []byte("aa"), 0700) | ||
fs.WriteFile(path.Join(someDir, "000012.vlog"), []byte("aaaaa"), 0700) | ||
// 4 sst files | ||
fs.WriteFile(path.Join(someDir, "000070.sst"), []byte("zzzzzz"), 0700) | ||
fs.WriteFile(path.Join(someDir, "000071.sst"), []byte("zzzzzzz"), 0700) | ||
fs.WriteFile(path.Join(someDir, "000072.sst"), []byte("zzzzzzzz"), 0700) | ||
fs.WriteFile(path.Join(someDir, "000073.sst"), []byte("zzzzzzzzz"), 0700) | ||
// Other | ||
fs.WriteFile(path.Join(someDir, "KEYREGISTRY"), []byte("u"), 0700) | ||
fs.WriteFile(path.Join(someDir, "MANIFEST"), []byte("u"), 0700) | ||
|
||
subDir := path.Join(someDir, "subDir") | ||
fs.Mkdir(subDir, 0700) | ||
fs.WriteFile(path.Join(subDir, "randomFile"), []byte("abc"), 0700) | ||
|
||
fileSize, extFileCount, extByteCount, err := getDirSizeRecursive(someDir, &fs) | ||
assert.Nil(t, err) | ||
assert.Equal(t, uint64(43), fileSize) | ||
assert.Equal(t, map[string]int(map[string]int{"": 3, ".sst": 4, ".vlog": 3}), extFileCount) | ||
assert.Equal(t, map[string]uint64(map[string]uint64{"": 5, ".sst": 30, ".vlog": 8}), extByteCount) | ||
} |
Oops, something went wrong.