Db open memory usage regression
- Dominant language
- C++
- Stars
- 32.1k
- Forks
- 6.9k
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
There was a serious DB::Open() regression between 5.17.2 and 6.2.4 which results in memory usage of Open() in the latter to be at 4500% of the former (making it impossible to even open on the machine I was using)
### Expected behavior
DB::Open() finishes in a reasonable amount of time using a reasonable amount of memory in version v6.2.4 just like it did in v5.17.2
### Actual behavior
DB::Open() takes 8.5 seconds and uses 3,117 MB in v6.2.4 instead taking 0.2 seconds and using 68 MB to open as it does in v5.17.2 (4200% of the time and 4500% of the memory memory)
Note that in my case this results in an inability to even open the database on the server before memory is exhausted. The tests below had to be run on a separate machine.
### Steps to reproduce the behavior
I have an example database which reliably reproduces this error (using the following code to open, and always resetting database to original state after successful open before next test)
```c++
#include
#include
#include "rocksdb/db.h"
int main() {
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
std::vector families;
families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, rocksdb::ColumnFamilyOptions()));
families.push_back(rocksdb::ColumnFamilyDescriptor("export", rocksdb::ColumnFamilyOptions()));
families.push_back(rocksdb::ColumnFamilyDescriptor("items,1", *rocksdb::ColumnFamilyOptions().OptimizeForPointLookup(20)));
families.push_back(rocksdb::ColumnFamilyDescriptor("items,2", rocksdb::ColumnFamilyOptions()));
std::vector handles;
rocksdb::Status status = rocksdb::DB::Open(options, "example-db", families, &handles, &db);
std::cout << "Status: " << status.ToString() << std::endl;
}
```
And using `/usr/bin/time -v`, I get these results in 5.17.2 (asterisks are mine):
```
/usr/bin/time -v ./memissue
Status: OK
Command being timed: "./memissue"
User time (seconds): 0.15
System time (seconds): 0.07
Percent of CPU this job got: 116%
* Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.20
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
* Maximum resident set size (kbytes): 69360
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 13
Minor (reclaiming a frame) page faults: 19484
Voluntary context switches: 808
Involuntary context switches: 42
Swaps: 0
File system inputs: 1512
File system outputs: 168
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
```
and these results in 6.2.4 (and after commit 8fe1e06c)
```
/usr/bin/time -v ./memissue
Status: OK
Command being timed: "./memissue"
User time (seconds): 7.71
System time (seconds): 0.81
Percent of CPU this job got: 100%
* Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.50
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
* Maximum resident set size (kbytes): 3191588
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 11
Minor (reclaiming a frame) page faults: 863595
Voluntary context switches: 854
Involuntary context switches: 221
Swaps: 0
File system inputs: 1408
File system outputs: 168
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
```
`git bisect` implicates the following commit:
```
8fe1e06ca0b898a51d7ab796a7419745d080c17b is the first bad commit
commit 8fe1e06ca0b898a51d7ab796a7419745d080c17b
Author: Abhishek Madan
Date: Wed Nov 28 15:26:56 2018 -0800
Clean up FragmentedRangeTombstoneList (#4692)
Summary:
Removed `one_time_use` flag, which removed the need for some
tests, and changed all `NewRangeTombstoneIterator` methods to return
`FragmentedRangeTombstoneIterators`.
These changes also led to removing `RangeDelAggregatorV2::AddUnfragmentedTombstones`
and one of the `MemTableListVersion::AddRangeTombstoneIterators` methods.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4692
Differential Revision: D13106570
Pulled By: abhimadan
fbshipit-source-id: cbab5432d7fc2d9cdfd8d9d40361a1bffaa8f845
:040000 040000 b48d5233238d44275ab02356e37d813327b5f5ac fc1e7ec02fb9f5cc40168abc605b344c88c0ad3e M db
:040000 040000 34d8658fa1b38462b0f43dff338c9369f677f93a b912e6c9a04a24592e48cdfcc3f1d98fd8dfddde M table
:040000 040000 c1687d32daf5073b9ee54346b928ba0801a9ab84 bd8aab0ce39fecabc86de51c167eef98151e619c M util
:040000 040000 d6349653b0aec75a9211d2c9fe8a1f051f585af1 459781b77dad361014ebbefcdd74cd3d659d918d M utilities
```
Contributor guide
Assessment
This issue has not been assessed yet.