Commit d40bd88e authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Add feature toggles to tune leveldb performance

We've seen an increase in Memory.Browser.PrivateMemoryFootprint that is
suspected to be caused by leveldb use for sync purposes, which is more
common the more datatypes are migrated to USS.

In order to tune leveldb's memory usage and confirm that recent
regressions are caused by sync, various feature toggles are introduced.
By default, there is no behavioral differences.

Bug: 887068
Change-Id: Idada6be78a39db7ef04ee582ca01b8ed0c427838
Reviewed-on: https://chromium-review.googlesource.com/1257912Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596296}
parent f26b3a8d
......@@ -6,6 +6,7 @@
#include <utility>
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "components/sync/protocol/model_type_store_schema_descriptor.pb.h"
......@@ -29,6 +30,11 @@ const char ModelTypeStoreBackend::kDBSchemaDescriptorRecordId[] =
const char ModelTypeStoreBackend::kStoreInitResultHistogramName[] =
"Sync.ModelTypeStoreInitResult";
const base::Feature kModelTypeStoreAvoidReadCache{
"kModelTypeStoreAvoidReadCache", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kModelTypeStoreSmallWriteBufferSize{
"kModelTypeStoreSmallWriteBufferSize", base::FEATURE_DISABLED_BY_DEFAULT};
namespace {
StoreInitResultForHistogram LevelDbStatusToStoreInitResult(
......@@ -133,6 +139,10 @@ leveldb::Status ModelTypeStoreBackend::OpenDatabase(const std::string& path,
leveldb_env::Options options;
options.create_if_missing = true;
options.paranoid_checks = true;
if (base::FeatureList::IsEnabled(kModelTypeStoreSmallWriteBufferSize))
options.write_buffer_size = 512 * 1024;
if (env)
options.env = env;
......@@ -157,6 +167,8 @@ base::Optional<ModelError> ModelTypeStoreBackend::ReadRecordsWithPrefix(
record_list->reserve(id_list.size());
leveldb::ReadOptions read_options;
read_options.verify_checksums = true;
if (base::FeatureList::IsEnabled(kModelTypeStoreAvoidReadCache))
read_options.fill_cache = false;
std::string key;
std::string value;
for (const std::string& id : id_list) {
......@@ -180,6 +192,8 @@ base::Optional<ModelError> ModelTypeStoreBackend::ReadAllRecordsWithPrefix(
DCHECK(db_);
leveldb::ReadOptions read_options;
read_options.verify_checksums = true;
if (base::FeatureList::IsEnabled(kModelTypeStoreAvoidReadCache))
read_options.fill_cache = false;
std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options));
const leveldb::Slice prefix_slice(prefix);
for (iter->Seek(prefix_slice); iter->Valid(); iter->Next()) {
......@@ -211,8 +225,10 @@ ModelTypeStoreBackend::DeleteDataAndMetadataForPrefix(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(db_);
leveldb::WriteBatch write_batch;
std::unique_ptr<leveldb::Iterator> iter(
db_->NewIterator(leveldb::ReadOptions()));
leveldb::ReadOptions read_options;
if (base::FeatureList::IsEnabled(kModelTypeStoreAvoidReadCache))
read_options.fill_cache = false;
std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options));
const leveldb::Slice prefix_slice(prefix);
for (iter->Seek(prefix_slice); iter->Valid(); iter->Next()) {
leveldb::Slice key = iter->key();
......@@ -240,6 +256,8 @@ int64_t ModelTypeStoreBackend::GetStoreVersion() {
DCHECK(db_);
leveldb::ReadOptions read_options;
read_options.verify_checksums = true;
if (base::FeatureList::IsEnabled(kModelTypeStoreAvoidReadCache))
read_options.fill_cache = false;
std::string value;
ModelTypeStoreSchemaDescriptor schema_descriptor;
leveldb::Status status =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment