From 0a3259afae9077301bc8e7e0a47da085492658e3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 14 Apr 2018 23:00:56 -0700 Subject: [PATCH] ircd::db: Custom table opts; table cache; introduce the bloom filter. --- include/ircd/db/database/column.h | 1 + include/ircd/db/database/descriptor.h | 3 +++ ircd/db.cc | 26 +++++++++++++++++++++++--- ircd/m/dbs.cc | 27 +++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/include/ircd/db/database/column.h b/include/ircd/db/database/column.h index d4a1c2977..e26d026db 100644 --- a/include/ircd/db/database/column.h +++ b/include/ircd/db/database/column.h @@ -38,6 +38,7 @@ struct ircd::db::database::column final database::descriptor descriptor; comparator cmp; prefix_transform prefix; + rocksdb::BlockBasedTableOptions table_opts; custom_ptr handle; public: diff --git a/include/ircd/db/database/descriptor.h b/include/ircd/db/database/descriptor.h index 8509ada01..ffb73e4bc 100644 --- a/include/ircd/db/database/descriptor.h +++ b/include/ircd/db/database/descriptor.h @@ -23,4 +23,7 @@ struct ircd::db::database::descriptor std::string options {}; db::comparator cmp {}; db::prefix_transform prefix {}; + size_t cache_size { 16_MiB }; + size_t cache_size_comp { 8_MiB }; + size_t bloom_bits { 10 }; }; diff --git a/ircd/db.cc b/ircd/db.cc index 07a4a8fce..49bb83cdd 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include @@ -305,8 +307,8 @@ try ,cache{[this] () -> std::shared_ptr { - //TODO: XXX - const auto lru_cache_size{512_MiB}; + //TODO: conf + const auto lru_cache_size{256_MiB}; return rocksdb::NewLRUCache(lru_cache_size); }()} ,descriptors @@ -873,15 +875,33 @@ ircd::db::database::column::column(database *const &d, //if(d->mergeop->merger) // this->options.merge_operator = d->mergeop; + const auto &cache_size(this->descriptor.cache_size); + table_opts.block_cache = rocksdb::NewLRUCache(cache_size); + + const auto &cache_size_comp(this->descriptor.cache_size_comp); + table_opts.block_cache_compressed = rocksdb::NewLRUCache(cache_size_comp); + + // Tickers::READ_AMP_TOTAL_READ_BYTES / Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES + //table_opts.read_amp_bytes_per_bit = 8; + + const auto &bloom_bits(this->descriptor.bloom_bits); + if(bloom_bits) + table_opts.filter_policy.reset(rocksdb::NewBloomFilterPolicy(bloom_bits, false)); + + this->options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_opts)); + //log.debug("'%s': Creating new column '%s'", d->name, this->name); //throw_on_error(d->d->CreateColumnFamily(this->options, this->name, &this->handle)); - log.debug("schema '%s' declares column [%s => %s] cmp[%s] prefix[%s]: %s", + log.debug("schema '%s' declares column [%s => %s] cmp[%s] pfx[%s] lru:%zu:%zu bloom:%zu %s", db::name(*d), demangle(key_type.name()), demangle(mapped_type.name()), this->cmp.Name(), this->options.prefix_extractor? this->prefix.Name() : "none", + cache_size, + cache_size_comp, + bloom_bits, this->descriptor.name); } diff --git a/ircd/m/dbs.cc b/ircd/m/dbs.cc index 6e790d7f8..57c645b10 100644 --- a/ircd/m/dbs.cc +++ b/ircd/m/dbs.cc @@ -444,6 +444,12 @@ ircd::m::dbs::desc::events__state_node // prefix transform {}, + + // cache size + 96_MiB, //TODO: conf + + // cache size for compressed assets + 24_MiB, //TODO: conf }; /// Prefix transform for the events__room_events. The prefix here is a room_id @@ -635,6 +641,15 @@ ircd::m::dbs::desc::events__room_events // prefix transform events__room_events__pfx, + + // cache size + 64_MiB, //TODO: conf + + // cache size for compressed assets + 24_MiB, //TODO: conf + + // bloom filter bits + 0, // no bloom filter because of possible comparator issues }; // @@ -734,6 +749,12 @@ ircd::m::dbs::desc::events__room_origins // prefix transform events__room_origins__pfx, + + // cache size + 64_MiB, //TODO: conf + + // cache size for compressed assets + 16_MiB, //TODO: conf }; // @@ -831,6 +852,12 @@ ircd::m::dbs::desc::events__room_state // prefix transform events__room_state__pfx, + + // cache size + 128_MiB, //TODO: conf + + // cache size for compressed assets + 32_MiB, //TODO: conf }; //