Skip to content

Commit b73d331

Browse files
dbwrapper: Bump max file size to 32 MiB
The default max file size for LevelDB is 2 MiB, which results in the LevelDB compaction code generating ~4 disk cache flushes per second when syncing with the Bitcoin network. These disk cache flushes are triggered by fdatasync() syscall issued by the LevelDB compaction code when reaching the max file size. If the database is on a HDD this flush rate brings the whole system to a crawl. It also results in very slow throughput since 2 MiB * 4 flushes per second is about 8 MiB / second max throughput, while even an old HDD can pull 100 - 200 MiB / second streaming throughput. Increase the max file size for LevelDB to 32 MiB instead so the flush rate drops significantly and the system no longer gets so sluggish. The new max file size value chosen is a compromise between the one that works best for HDD and SSD performance, as determined by benchmarks done by various people.
1 parent dbc8ba1 commit b73d331

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/dbwrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
147147
// on corruption in later versions.
148148
options.paranoid_checks = true;
149149
}
150+
options.max_file_size = std::max(options.max_file_size, DBWRAPPER_MAX_FILE_SIZE);
150151
SetMaxOpenFiles(&options);
151152
return options;
152153
}

src/dbwrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
2424
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
25+
static const size_t DBWRAPPER_MAX_FILE_SIZE = 32 << 20; // 32 MiB
2526

2627
//! User-controlled performance and debug options.
2728
struct DBOptions {

0 commit comments

Comments
 (0)