neverchanje commented on a change in pull request #646:
URL: https://github.com/apache/incubator-pegasus/pull/646#discussion_r529295670



##########
File path: src/server/pegasus_server_impl_init.cpp
##########
@@ -299,6 +300,130 @@ 
pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r)
         _db_opts.rate_limiter = _s_rate_limiter;
     }
 
+    bool enable_write_buffer_manager = dsn_config_get_value_bool(
+                "pegasus.server",
+                "rocksdb_enable_write_buffer_manager",
+                false,
+                "enable write buffer manager to limit total memory "
+                "used by memtables and block caches across multiple replicas");
+    ddebug("rocksdb_enable_write_buffer_manager = %d", 
enable_write_buffer_manager);
+    if (enable_write_buffer_manager) {
+        // If write buffer manager is enabled, all replicas(one DB instance 
for each
+        // replica) on this server will share the same write buffer manager 
object,
+        // thus the same block cache object. It's convenient to control the 
total memory
+        // of memtables and bloack caches used by this server

Review comment:
       ```suggestion
           // of memtables and block caches used by this server
   ```

##########
File path: src/server/pegasus_server_impl_init.cpp
##########
@@ -299,6 +300,130 @@ 
pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r)
         _db_opts.rate_limiter = _s_rate_limiter;
     }
 
+    bool enable_write_buffer_manager = dsn_config_get_value_bool(
+                "pegasus.server",
+                "rocksdb_enable_write_buffer_manager",
+                false,
+                "enable write buffer manager to limit total memory "
+                "used by memtables and block caches across multiple replicas");
+    ddebug("rocksdb_enable_write_buffer_manager = %d", 
enable_write_buffer_manager);
+    if (enable_write_buffer_manager) {
+        // If write buffer manager is enabled, all replicas(one DB instance 
for each
+        // replica) on this server will share the same write buffer manager 
object,
+        // thus the same block cache object. It's convenient to control the 
total memory
+        // of memtables and bloack caches used by this server
+        static std::once_flag flag;
+        std::call_once(flag, [&]() {
+            int64_t total_size_across_write_buffer = 
dsn_config_get_value_int64(
+                    "pegasus.server",
+                    "rocksdb_total_size_across_write_buffer",
+                    0,
+                    "total size limit used by memtables across multiple 
replicas");
+            ddebug("rocksdb_total_size_across_write_buffer = %" PRId64, 
total_size_across_write_buffer);
+            if (total_size_across_write_buffer < 0) {
+                total_size_across_write_buffer = 0;
+            }
+            _s_write_buffer_manager = 
std::make_shared<rocksdb::WriteBufferManager>(
+                    static_cast<size_t>(total_size_across_write_buffer), 
tbl_opts.block_cache);
+        });
+        _db_opts.write_buffer_manager = _s_write_buffer_manager;
+    }
+
+    int64_t max_open_files = dsn_config_get_value_int64(
+            "pegasus.server",
+            "rocksdb_max_open_files",
+            -1,
+            "number of open files that can be used by a replica(namely a DB 
instance)");
+    _db_opts.max_open_files = static_cast<int>(max_open_files);
+    ddebug("rocksdb_max_open_files = %d", _db_opts.max_open_files);
+
+    std::string index_type = dsn_config_get_value_string(
+            "pegasus.server",
+            "rocksdb_index_type",
+            "kBinarySearch",
+            "The index type that will be used for this table.");
+    const std::unordered_map<std::string, 
rocksdb::BlockBasedTableOptions::IndexType>
+    index_type_string_map = {
+        {"kBinarySearch", 
rocksdb::BlockBasedTableOptions::IndexType::kBinarySearch},
+        {"kHashSearch", 
rocksdb::BlockBasedTableOptions::IndexType::kHashSearch},
+        {"kTwoLevelIndexSearch",
+         rocksdb::BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch},
+        {"kBinarySearchWithFirstKey",
+         rocksdb::BlockBasedTableOptions::IndexType::kBinarySearchWithFirstKey}
+    };
+    auto index_type_item = index_type_string_map.find(index_type);
+    dassert(index_type_item != index_type_string_map.end(),
+            "[pegasus.server]rocksdb_index_type shold be one among 
kBinarySearch, "
+            "kHashSearch, kTwoLevelIndexSearch or kBinarySearchWithFirstKey.");
+    tbl_opts.index_type = index_type_item->second;
+    ddebug("rocksdb_index_type = %s", index_type.c_str());

Review comment:
       This is irrelevant to the topic of this PR. But I do curious if you test 
the performance effect of this configuration.
   
   I'd suggest this configuration naming to:
   
   ```
   [pegasus.server]
   rocksdb_index_type = binary_search | hash_search | two_level_index_search | 
binary_search_with_first_key
   ```
   
   without prefix "k".

##########
File path: src/server/pegasus_server_impl_init.cpp
##########
@@ -299,6 +300,130 @@ 
pegasus_server_impl::pegasus_server_impl(dsn::replication::replica *r)
         _db_opts.rate_limiter = _s_rate_limiter;
     }
 
+    bool enable_write_buffer_manager = dsn_config_get_value_bool(
+                "pegasus.server",
+                "rocksdb_enable_write_buffer_manager",
+                false,
+                "enable write buffer manager to limit total memory "
+                "used by memtables and block caches across multiple replicas");
+    ddebug("rocksdb_enable_write_buffer_manager = %d", 
enable_write_buffer_manager);
+    if (enable_write_buffer_manager) {
+        // If write buffer manager is enabled, all replicas(one DB instance 
for each
+        // replica) on this server will share the same write buffer manager 
object,
+        // thus the same block cache object. It's convenient to control the 
total memory
+        // of memtables and bloack caches used by this server
+        static std::once_flag flag;
+        std::call_once(flag, [&]() {
+            int64_t total_size_across_write_buffer = 
dsn_config_get_value_int64(
+                    "pegasus.server",
+                    "rocksdb_total_size_across_write_buffer",
+                    0,
+                    "total size limit used by memtables across multiple 
replicas");
+            ddebug("rocksdb_total_size_across_write_buffer = %" PRId64, 
total_size_across_write_buffer);
+            if (total_size_across_write_buffer < 0) {
+                total_size_across_write_buffer = 0;
+            }
+            _s_write_buffer_manager = 
std::make_shared<rocksdb::WriteBufferManager>(
+                    static_cast<size_t>(total_size_across_write_buffer), 
tbl_opts.block_cache);
+        });
+        _db_opts.write_buffer_manager = _s_write_buffer_manager;
+    }
+
+    int64_t max_open_files = dsn_config_get_value_int64(
+            "pegasus.server",
+            "rocksdb_max_open_files",
+            -1,
+            "number of open files that can be used by a replica(namely a DB 
instance)");
+    _db_opts.max_open_files = static_cast<int>(max_open_files);
+    ddebug("rocksdb_max_open_files = %d", _db_opts.max_open_files);

Review comment:
       Does that actually take effect in your case? We do not recommend a 
deployment with too large storage size per replica (around 3GB~5GB is 
prefered). Usually, it won't exceed the default rocksdb "max_open_files" limit.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to