From e3c6ba37dd8705de804fbd3388627c47253c3ef0 Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 5 May 2016 16:50:32 -0700 Subject: [PATCH] OptimizeForSmallDb(): revert some options whose defaults were just changed Summary: We changed default options of max_open_files and max_file_opening_threads but didn't revert it in OptimizeForSmallDb(). Test Plan: Add a unit test Reviewers: igor, yhchiang, IslamAbdelRahman Reviewed By: IslamAbdelRahman Subscribers: leveldb, andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D57675 --- include/rocksdb/options.h | 12 +++++++++++- util/options.cc | 12 ++++++++++++ util/options_test.cc | 7 ++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index d93af2314..982bd16c6 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -824,6 +824,10 @@ struct DBOptions { // Some functions that make it easier to optimize RocksDB + // Use this if your DB is very small (like under 1GB) and you don't want to + // spend lots of memory for memtables. + DBOptions* OptimizeForSmallDb(); + #ifndef ROCKSDB_LITE // By default, RocksDB uses only one background thread for flush and // compaction. Calling this function will set it up such that total of @@ -898,7 +902,7 @@ struct DBOptions { // If max_open_files is -1, DB will open all files on DB::Open(). You can // use this option to increase the number of threads used to open the files. - // Default: 1 + // Default: 16 int max_file_opening_threads; // Once write-ahead logs exceed this size, we will start forcing the flush of @@ -1343,6 +1347,8 @@ struct Options : public DBOptions, public ColumnFamilyOptions { void DumpCFOptions(Logger* log) const; + // Some functions that make it easier to optimize RocksDB + // Set appropriate parameters for bulk loading. // The reason that this is a function that returns "this" instead of a // constructor is to enable chaining of multiple similar calls in the future. @@ -1352,6 +1358,10 @@ struct Options : public DBOptions, public ColumnFamilyOptions { // It's recommended to manually call CompactRange(NULL, NULL) before reading // from the database, because otherwise the read can be very slow. Options* PrepareForBulkLoad(); + + // Use this if your DB is very small (like under 1GB) and you don't want to + // spend lots of memory for memtables. + Options* OptimizeForSmallDb(); }; // diff --git a/util/options.cc b/util/options.cc index 7eef1ab27..a4587d2ed 100644 --- a/util/options.cc +++ b/util/options.cc @@ -668,6 +668,12 @@ Options::PrepareForBulkLoad() return this; } +Options* Options::OptimizeForSmallDb() { + ColumnFamilyOptions::OptimizeForSmallDb(); + DBOptions::OptimizeForSmallDb(); + return this; +} + Options* Options::OldDefaults(int rocksdb_major_version, int rocksdb_minor_version) { ColumnFamilyOptions::OldDefaults(rocksdb_major_version, @@ -705,6 +711,12 @@ ColumnFamilyOptions* ColumnFamilyOptions::OldDefaults( } // Optimization functions +DBOptions* DBOptions::OptimizeForSmallDb() { + max_file_opening_threads = 1; + max_open_files = 5000; + return this; +} + ColumnFamilyOptions* ColumnFamilyOptions::OptimizeForSmallDb() { write_buffer_size = 2 << 20; target_file_size_base = 2 * 1048576; diff --git a/util/options_test.cc b/util/options_test.cc index 4ed94d082..9451bf580 100644 --- a/util/options_test.cc +++ b/util/options_test.cc @@ -1315,9 +1315,10 @@ TEST_F(OptionsParserTest, DifferentDefault) { old_default_cf_opts.compaction_pri); } - ColumnFamilyOptions cf_small_opts; - cf_small_opts.OptimizeForSmallDb(); - ASSERT_EQ(2 << 20, cf_small_opts.write_buffer_size); + Options small_opts; + small_opts.OptimizeForSmallDb(); + ASSERT_EQ(2 << 20, small_opts.write_buffer_size); + ASSERT_EQ(5000, small_opts.max_open_files); } class OptionsSanityCheckTest : public OptionsParserTest {