Read me for memory consumption (#119)

* Added guidance for memory consuption

* Added metric for dropPrefix latency so that we can measure for how much time it locks the DB

* fixed the comment
This commit is contained in:
sana-jawad 2020-05-11 16:13:05 -07:00 коммит произвёл GitHub
Родитель 245ccdd3c4
Коммит 6874a7cc5f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -97,6 +97,42 @@ To download a backup of the database, navigate to http://localhost:8080/data/bac
To restore from a backup, start `sloop` with the `-restore-database-file` flag set to the backup file downloaded in the previous step. When restoring, you may also wish to set the `-disable-kube-watch=true` flag to stop new writes from occurring and/or the `-context` flag to restore the database into a different context.
## Memory Consumption
Sloop's memory usage can be managed by tweaking several options:
- `badger-use-lsm-only-options` If this flag is set to true, values would be collocated with the LSM tree, with value log largely acting as a write-ahead log only. Recommended value for memory constrained environments: false
- `badger-keep-l0-in-memory` When this flag is set to true, Level 0 tables are kept in memory. This leads to better performance in writes as well as compactions. Recommended value for memory constrained environments: false
- `badger-sync-writes` When SyncWrites is true all writes are synced to disk. Setting this to false would achieve better performance, but may cause data loss in case of crash. Recommended value for memory constrained environments: false
- `badger-vlog-fileIO-mapping` TableLoadingMode indicates which file loading mode should be used for the LSM tree data files. Setting to true would not load the value in memory map. Recommended value for memory constrained environments: true
Apart from these flags some other values can be tweaked to fit in the memory constraints. Following are some examples of setups.
- Memory consumption max limit: 1GB
```
// 0.5<<20 (524288 bytes = 0.5 Mb)
"badger-max-table-size=524288",
"badger-number-of-compactors=1",
"badger-number-of-level-zero-tables=1",
"badger-number-of-zero-tables-stall=2",
```
- Memory consumption max limit: 2GB
```
// 16<<20 (16777216 bytes = 16 Mb)
"badger-max-table-size=16777216",
"badger-number-of-compactors=1",
"badger-number-of-level-zero-tables=1",
"badger-number-of-zero-tables-stall=2",
```
- Memory consumption max limit: 5GB
```
// 32<<20 (33554432 bytes = 32 Mb)
"badger-max-table-size=33554432",
"badger-number-of-compactors=1",
"badger-number-of-level-zero-tables=2",
"badger-number-of-zero-tables-stall=3",
```
Apart from the above settings, max-disk-mb and max-look-back can be tweaked according to input data and memory constraints.
## Contributing
Refer to [CONTRIBUTING.md](CONTRIBUTING.md)<br>

Просмотреть файл

@ -26,6 +26,7 @@ var (
metricGcSuccessCount = promauto.NewCounter(prometheus.CounterOpts{Name: "sloop_gc_success_count"})
metricGcFailedCount = promauto.NewCounter(prometheus.CounterOpts{Name: "sloop_gc_failed_count"})
metricGcLatency = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_gc_latency_sec"})
metricDropPrefixLatency = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_drop_prefix_sec"})
metricGcRunning = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_gc_running"})
metricGcCleanUpPerformed = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_gc_cleanup_performed"})
metricGcDeletedNumberOfKeys = promauto.NewGauge(prometheus.GaugeOpts{Name: "sloop_gc_deleted_num_of_keys"})
@ -310,11 +311,14 @@ func deletePartition(minPartition string, tables typed.Tables, deletionBatchSize
err, numOfDeletedKeysForPrefix, numOfKeysToDeleteForPrefix = common.DeleteKeysWithPrefix(prefix, tables.Db(), deletionBatchSize, numberOfKeysToRemove)
metricGcDeletedNumberOfKeysByTable.WithLabelValues(fmt.Sprintf("%v", tableName)).Set(float64(numOfDeletedKeysForPrefix))
} else {
beforeDropPrefix := time.Now()
err = tables.Db().DropPrefix([]byte(prefix))
// !badger!move keys for the given prefix should also be cleaned up. For details: https://github.com/dgraph-io/badger/issues/1288
err = tables.Db().DropPrefix([]byte("!badger!move" + prefix))
metricDropPrefixLatency.Set(time.Since(beforeDropPrefix).Seconds())
// there will be same deletions for dropPrefix as the tables are locked when prefixes are dropped
numOfDeletedKeysForPrefix = numberOfKeysToRemove
numOfKeysToDeleteForPrefix = numberOfKeysToRemove