Skip to content

Commit 68dde35

Browse files
authored
Merge pull request #33026 from vespa-engine/vekterli/wire-proton-cfg-to-cache-lfu
Wire proton config to cache LFU sketch size
2 parents 038c83b + 0ebecc9 commit 68dde35

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

configdefinitions/src/vespa/proton.def

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,18 @@ index.cache.bitvector.maxbytes long default=0 restart
561561
index.cache.postinglist.slru_protected_segment_ratio double default=0.0 restart
562562
index.cache.bitvector.slru_protected_segment_ratio double default=0.0 restart
563563

564+
## Configures the cache to use a LFU frequency sketch to estimate the frequency
565+
## of cacheable elements and to prevent less frequently accessed elements from
566+
## displacing more frequent ones.
567+
## The specified element count should be at least as high as the expected number
568+
## of elements the cache could contain (_not_ its size in bytes), as this has
569+
## direct impact on how accurate the (inherently probabilistic) frequency
570+
## estimates are.
571+
##
572+
## Any value greater than 0 enables LFU semantics, 0 disables LFU (default).
573+
index.cache.postinglist.lfu_sketch_max_element_count long default=0 restart
574+
index.cache.bitvector.lfu_sketch_max_element_count long default=0 restart
575+
564576
## Specifies which tensor implementation to use for all backend code.
565577
##
566578
## TENSOR_ENGINE (default) uses DefaultTensorEngine, which has been the production implementation for years.

searchcore/src/vespa/searchcore/proton/server/proton.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,12 @@ make_posting_list_cache(const ProtonConfig& cfg)
175175
// assumptions about how things work...! Otherwise, things will likely explode.
176176
posting_max_bytes = std::max(posting_max_bytes, 0L);
177177
int64_t bitvector_max_bytes = std::max(cfg.index.cache.bitvector.maxbytes, 0L);
178+
int64_t posting_lfu_max_element_count = std::max(cfg.index.cache.postinglist.lfuSketchMaxElementCount, 0L);
179+
int64_t bitvector_lfu_max_element_count = std::max(cfg.index.cache.bitvector.lfuSketchMaxElementCount, 0L);
178180
PostingListCache::CacheSizingParams params(posting_max_bytes, bitvector_max_bytes,
179181
cfg.index.cache.postinglist.slruProtectedSegmentRatio,
180-
cfg.index.cache.bitvector.slruProtectedSegmentRatio);
182+
cfg.index.cache.bitvector.slruProtectedSegmentRatio,
183+
posting_lfu_max_element_count, bitvector_lfu_max_element_count);
181184
return std::make_shared<PostingListCache>(params);
182185
}
183186

searchlib/src/vespa/searchlib/diskindex/posting_list_cache.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PostingListCache::Cache : public vespalib::cache<CacheParams> {
5656
public:
5757
using Parent = vespalib::cache<CacheParams>;
5858
Cache(BackingStore& backing_store, size_t max_bytes, size_t max_protected_bytes);
59-
~Cache();
59+
~Cache() override;
6060
static size_t element_size() { return sizeof(value_type); }
6161
};
6262

@@ -82,7 +82,7 @@ class PostingListCache::BitVectorCache : public vespalib::cache<BitVectorCachePa
8282
public:
8383
using Parent = vespalib::cache<BitVectorCacheParams>;
8484
BitVectorCache(BackingStore& backing_store, size_t max_bytes, size_t max_protected_bytes);
85-
~BitVectorCache();
85+
~BitVectorCache() override;
8686
static size_t element_size() { return sizeof(value_type); }
8787
};
8888

@@ -103,10 +103,16 @@ PostingListCache::PostingListCache(const CacheSizingParams& params)
103103
params.bitvector_slru_probationary_bytes(),
104104
params.bitvector_slru_protected_bytes()))
105105
{
106+
if (params.posting_lfu_max_element_count() > 0) {
107+
_cache->set_frequency_sketch_size(params.posting_lfu_max_element_count());
108+
}
109+
if (params.bitvector_lfu_max_element_count() > 0) {
110+
_bitvector_cache->set_frequency_sketch_size(params.bitvector_lfu_max_element_count());
111+
}
106112
}
107113

108114
PostingListCache::PostingListCache(size_t max_bytes, size_t bitvector_max_bytes)
109-
: PostingListCache(CacheSizingParams(max_bytes, bitvector_max_bytes, 0.0, 0.0))
115+
: PostingListCache(CacheSizingParams(max_bytes, bitvector_max_bytes, 0.0, 0.0, 0, 0))
110116
{}
111117

112118
PostingListCache::~PostingListCache() = default;

searchlib/src/vespa/searchlib/diskindex/posting_list_cache.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ class PostingListCache : public IPostingListCache {
2121
std::unique_ptr<BitVectorCache> _bitvector_cache;
2222
public:
2323
class CacheSizingParams {
24-
size_t _posting_max_bytes = 0;
25-
size_t _bitvector_max_bytes = 0;
26-
double _posting_slru_protected_ratio = 0.0; // [0, 1]
27-
double _bitvector_slru_protected_ratio = 0.0; // [0, 1]
24+
size_t _posting_max_bytes = 0;
25+
size_t _bitvector_max_bytes = 0;
26+
double _posting_slru_protected_ratio = 0.0; // [0, 1]
27+
double _bitvector_slru_protected_ratio = 0.0; // [0, 1]
28+
size_t _posting_lfu_max_element_count = 0;
29+
size_t _bitvector_lfu_max_element_count = 0;
2830
public:
2931
constexpr CacheSizingParams() noexcept = default;
3032
CacheSizingParams(size_t posting_max_bytes, size_t bitvector_max_bytes,
31-
double posting_slru_protected_ratio, double bitvector_slru_protected_ratio) noexcept
33+
double posting_slru_protected_ratio, double bitvector_slru_protected_ratio,
34+
size_t posting_lfu_max_element_count, size_t bitvector_lfu_max_element_count) noexcept
3235
: _posting_max_bytes(posting_max_bytes),
3336
_bitvector_max_bytes(bitvector_max_bytes),
3437
_posting_slru_protected_ratio(std::min(std::max(posting_slru_protected_ratio, 0.0), 1.0)),
35-
_bitvector_slru_protected_ratio(std::min(std::max(bitvector_slru_protected_ratio, 0.0), 1.0))
38+
_bitvector_slru_protected_ratio(std::min(std::max(bitvector_slru_protected_ratio, 0.0), 1.0)),
39+
_posting_lfu_max_element_count(posting_lfu_max_element_count),
40+
_bitvector_lfu_max_element_count(bitvector_lfu_max_element_count)
3641
{
3742
}
3843

@@ -55,6 +60,12 @@ class PostingListCache : public IPostingListCache {
5560
[[nodiscard]] size_t bitvector_slru_probationary_bytes() const noexcept {
5661
return _bitvector_max_bytes - bitvector_slru_protected_bytes();
5762
}
63+
[[nodiscard]] size_t posting_lfu_max_element_count() const noexcept {
64+
return _posting_lfu_max_element_count;
65+
}
66+
[[nodiscard]] size_t bitvector_lfu_max_element_count() const noexcept {
67+
return _bitvector_lfu_max_element_count;
68+
}
5869
};
5970

6071
explicit PostingListCache(const CacheSizingParams& params);

0 commit comments

Comments
 (0)