You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@kudu.apache.org by "Mahesh Reddy (Code Review)" <ge...@cloudera.org> on 2023/10/20 21:39:44 UTC
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Mahesh Reddy has uploaded this change for review. ( http://gerrit.cloudera.org:8080/20607
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
WIP KUDU-613: Scan Resistant Caching
This patch introduces a new class, the SLRU cache with two segments,
the probationary and protected, to protect the cache from long/random
reads.
Looking for feedback on general approach for implementation so far.
TODO:
- Add tests
- Add mutex when reading/writing from cache
- Add metrics on SLRU cache level, both segments already have their
own metrics
- Add parameter for how hits on a cache entry until it's upgraded
to protected segment
- Use SLRU cache in BlockCache
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
3 files changed, 268 insertions(+), 3 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/1
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 1
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 22: Verified-1
Build Failed
http://jenkins.kudu.apache.org/job/pre_commit/220/ : FAILURE
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 22
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Sat, 08 Jun 2024 00:46:01 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
(10 comments)
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@254
PS16, Line 254: e = table_.Lookup(key, hash);
What guarantees do we have to be sure that 'table_' cannot be modified under the hood by concurrently running SLRUCacheShard::Insert()? It would be great to add a note about that.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@267
PS16, Line 267: e = table_.Lookup(key, hash);
ditto: what if Insert() is running concurrently and modifying the 'table_' -- what protects us from such concurrency issues? Would be great to add a note in the code.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@273
PS17, Line 273: bool last_reference = Unref(e);
: if (last_reference) {
nit: could these be joined, adding a comment on what's the intention of this code?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@471
PS17, Line 471: {
What is the purpose of this extra scope?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@501
PS17, Line 501: {
What is the purpose of this extra scope?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@552
PS17, Line 552: {
What is the purpose of this extra scope?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@561
PS17, Line 561: {
What is the purpose of this extra scope?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@581
PS17, Line 581:
nit:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@601
PS17, Line 601: // Similar to STLDeleteElements().
: auto begin = shards_.begin();
: while (begin != shards_.end()) {
: auto temp = begin;
: ++begin;
: temp->reset(nullptr);
: }
Is this really needed? Wouldn't the contained unique_ptr be destroyed automatically upon the destruction of the containing vector?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@694
PS17, Line 694: uint8_t* data = reinterpret_cast<uint8_t*>(h);
: delete [] data;
nit: could these lines be joined?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 May 2024 21:33:01 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 19:
(12 comments)
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG@22
PS16, Line 22:
> Thanks for clarifying.
Pushing out this patch for now to get reviews, will work on setting up a release build to get accurate stats.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h@228
PS14, Line 228: // original metrics.
: kReset,
: };
: // Set the cache metrics to update corresponding counters accordingly.
: virtual void SetMetrics(std::unique_ptr<CacheMetrics> metrics,
: ExistingMetricsPolicy metrics_policy) = 0;
:
: // Opaque handle to an entry stored in the cache.
: struct Handle { };
:
: // Custom deleter: intended for use with std::unique_ptr<Handle>.
: class HandleDeleter {
: public:
: explicit HandleDeleter(Cache* c)
: : c_(c) {
: }
:
: void operator()(Handle* h) const {
: if (h != nullptr) {
> OK, I guess one can try to circle back on the attempts to clean up this mes
Changed the SLRUCache metrics to inherit from CacheMetrics, so this method is no longer necessary.,
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc@280
PS18, Line 280: try t
> nit: Although self explanatory, it'd good to have a comment to brief what i
Done
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc@442
PS18, Line 442: added_weight += weight;
> It would be great to add a comment to explain what 'downgrade eviction' mea
Done
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h@40
PS16, Line 40: emTracker;
> Those are the usual benefits of having common approach: this is to have mor
Done
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@57
PS16, Line 57:
> IIUC, you could get away from pollution by using std::enable_if construct,
I ended up moving all the SLRUCache specific methods outside of the Cache interface, so at least that looks cleaner now.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@581
PS17, Line 581:
> Whoops, the comment is lost, indeed.
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@601
PS17, Line 601:
: bool ShardedSLRUCache::ProbationaryContains(const Slice& key) {
: const uint32_t hash = HashSlice(key);
: return shards_[Shard(hash)]->ProbationaryContains(key, hash);
: }
:
: bool
> I'm not sure I understand: if each of the elements is of std::unique_ptr<>
The issue doesn't manifest itself in the unit tests, but it does when running the cache benchmarks.
The SLRUCacheShard destructor updates the mem_tracker to release all the memory consumed. But without this custom destructor seen in ShardedSLRUCache, the destructor for mem_tracker is called before the SLRUCacheShard desutrctor. Then in the mem_tracker destructor the check for unreleased consumption == 0 fails.
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@188
PS18, Line 188: if (new_deferred > max_deferred_consumption_ ||
: new_deferred < -max_deferred_consumption_) {
: int64_t to_propagate = deferred_consumption_.exchange(0, std::memory_order_relaxed);
: mem_tracker_->Consume(to_propagate);
: }
> Is it possible to avoid code repetition here and SoftFreeEntry()?
Removed metrics from this patch, will be added in follow up patch. But will work in your feedback there.
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@448
PS18, Line 448:
> Could this be 'const'?
Done
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@460
PS18, Line 460: return probationary_handle;
: }
:
: // Upgrade from the probationary segment.
: // Erase entry from the probationary segment then add entry to the
> nit: fix the indent
Done
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@574
PS18, Line 574:
> style nit: fix the indent
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 30 May 2024 17:08:57 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 11:
(5 comments)
Running into an ASAN error after the latest changes, it might also be related to the templatized code for HandleDeleter/PendingHandleDeleter since I don't recall seeing it before those changes.
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@76
PS10, Line 76:
> nit: the indent should be 2 + 4 = 6 spaces here
Done
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@80
PS10, Line 80:
> nit: wrong indent
Done
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@209
PS10, Line 209: RETURN_IF_NO_NVM_CACHE(GetParam().first);
> Here and below: does it mean the test is run only on NVM cache? If so, how
It means that the test will be skipped for caches with memory type NVM if the machine does not support NVM caches. Caches with memory type DRAM are unaffected by this macro.
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@244
PS10, Line 244: Erase
> Does it make sense to test the erase operation for both the cases when an e
Done
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache.h@136
PS10, Line 136: // Creates a new SLRU cache with 'probationary_capacity' being the capacity of
> It would be great to document the parameters of this NewSLRUCache() functio
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 11
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 08 Feb 2024 22:05:59 +0000
Gerrit-HasComments: Yes
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#2).
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
WIP KUDU-613: Scan Resistant Caching
This patch introduces a new class, the SLRU cache with two segments,
the probationary and protected, to protect the cache from long/random
reads.
Looking for feedback on general approach for implementation so far.
TODO:
- Add tests
- Add mutex when reading/writing from cache
- Add metrics on SLRU cache level, both segments already have their
own metrics
- Add parameter for how hits on a cache entry until it's upgraded
to protected segment
- Use SLRU cache in BlockCache
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
3 files changed, 273 insertions(+), 3 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/2
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 2
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 14:
(6 comments)
http://gerrit.cloudera.org:8080/#/c/20607/14//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/14//COMMIT_MSG@21
PS14, Line 21: TODO:
: - Add performance tests
Do I understand correctly that this is still a WIP patch, i.e. do you plan to add those performance tests as a part of this patch, or whatever is in slru_cache-test.cc in PS14 are those performance tests referred to?
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h@228
PS14, Line 228: // Sets probationary and protected segments metrics to update corresponding counters accordingly.
: //
: // An upgrade of one entry will increment the number of evictions from the probationary segment by
: // one and the number of insertions into the protected segment by one.
: //
: // A downgrade of one entry will increment the number of evictions from the protected segment by
: // one and the number of insertions into the probationary segment by one.
: //
: // To calculate the number of inserts for the SLRU cache, subtract the number of evictions
: // of the protected segment from the number of inserts of the probationary segment.
: //
: // To calculate the number of evictions for the SLRU cache, subtract the number of insertions
: // of the protected segment from the number of evictions of the probationary segment.
: //
: // Other than insertions and evictions, to calculate the metric for the SLRU cache, add the
: // corresponding metric from the probationary and protected segment together.
: virtual void SetSegmentMetrics(std::unique_ptr<CacheMetrics> probationary_metrics,
: std::unique_ptr<CacheMetrics> protected_metrics,
: ExistingMetricsPolicy metrics_policy) = 0;
I'm not sure I understand the premise of introducing this method in the base Cache class.
So far it seems the only place it's used is slru_cache-test.cc. And there, why not to store the instance as std::unique_ptr<ShardedSLRUCache> ?
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h@35
PS14, Line 35: Creates a new SLRU cache with 'probationary_capacity' being the capacity of
: // the probationary segment, 'protected_capacity' being the capacity
Is the capacity in bytes, kBytes, number of entries in the cache? It would be nice to clarify in the comment.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h@40
PS14, Line 40: Cache
Why not to return this as ShardedSLRUCache*?
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.cc@62
PS14, Line 62: GetCapacity
nit: capacity
In most of the Kudu's code, accessor methods follow the convention mentioned in the C++ style guide at https://google.github.io/styleguide/cppguide.html#Function_Names
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.cc@131
PS14, Line 131: size_t capacity_;
Could this be 'const'?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 14
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 09 Apr 2024 19:07:42 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#15).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 6.37M | 99.3%
ZIPFIAN ratio=1.00x | SLRU | 5.81M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 6.15M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 5.49M | 99.0%
UNIFORM ratio=1.00x | LRU | 6.76M | 99.7%
UNIFORM ratio=1.00x | SLRU | 7.03M | 100.0%
UNIFORM ratio=3.00x | LRU | 3.84M | 33.4%
UNIFORM ratio=3.00x | SLRU | 3.60M | 36.5%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
9 files changed, 1,567 insertions(+), 6 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/15
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 15
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#22).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Metrics will be added in a follow-up patch.
Ran cache benchmarks for RELEASE build.
Used default flag values in cache-bench.
Build ran locally on macOS, 6 cores and 2.6GHz.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 11.01M | 99.8%
ZIPFIAN ratio=1.00x | SLRU | 10.62M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 11.06M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 9.69M | 95.9%
UNIFORM ratio=1.00x | LRU | 8.54M | 99.7%
UNIFORM ratio=1.00x | SLRU | 6.18M | 99.7%
UNIFORM ratio=3.00x | LRU | 6.53M | 33.3%
UNIFORM ratio=3.00x | SLRU | 4.99M | 33.3%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
7 files changed, 1,486 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/22
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 22
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 22: Code-Review+2
> (4 comments)
>
> Created new SLRUHandle to mimic RLHandle to resolve the ASAN
> issues. Any new field in the RLHandle resulted in ASAN issues in
> codegen.
I guess the issue with ASAN is a thing on its own. I was suspecting a conflict with cache implementation from rocksdb library (Kudu picked up its cache implementation from LevelDB a long time ago), but Mahesh confirmed that rolling back https://gerrit.cloudera.org/c/21075/ didn't help to resolve the problem.
Apart from that, I think this patch looks good enough. There were several follow-up candidates to address, but as of PS22 this looks OK.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 22
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 11 Jun 2024 21:54:10 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#18).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Ran cache benchmarks for DEBUG build.
Build ran locally on macOS, 6 cores and 2.6GHz.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 6.37M | 99.3%
ZIPFIAN ratio=1.00x | SLRU | 5.81M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 6.15M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 5.49M | 99.0%
UNIFORM ratio=1.00x | LRU | 6.76M | 99.7%
UNIFORM ratio=1.00x | SLRU | 7.03M | 100.0%
UNIFORM ratio=3.00x | LRU | 3.84M | 33.4%
UNIFORM ratio=3.00x | SLRU | 3.60M | 36.5%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
8 files changed, 1,615 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/18
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 18
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 18:
(29 comments)
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG@22
PS16, Line 22: s and 2.6GHz
> It would be nice to mentions the following details:
This was a DEBUG build run locally on macOS. 6 cores and 2.6 GHz. I'll try to run it on a release build on a linux machine, but having some issues with va1022 right now.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache-bench.cc
File src/kudu/util/cache-bench.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache-bench.cc@92
PS16, Line 92: ret += " SLRU";
> nit for here and elsewhere: separate variable and the operator by space
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/cache.h@520
PS17, Line 520: // Returns true if probationary segment contains key.
: // Returns false if not.
: // Only used for SLRU cache.
: virtual bool ProbationaryContains(const Slice& key) = 0;
:
: // Returns true if protected segment contains key.
: // Returns false if not.
: // Only used for SLRU cache.
: virtual bool ProtectedContains(const Slice& key) = 0;
> SLRUCacheShard is the right place for these, even without any extras, I don
I guess the issue stems from returning a pointer to Cache rather than ShardedSLRUCache. If we return a pointer to Cache, then all methods used in the SLRU cache will have to be defined in the base class and overridden in the appropriate derived class. If we return a pointer to ShardedSLRUCache, then we don't have to define all these methods in the base class, but then the integration with block_cache and the cache tests is more difficult as they all accept a pointer to Cache for the old LRU implementation, but they don't accept a pointer to the new ShardedSLRUCache.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h@58
PS16, Line 58:
> nit: consider either making this part of the comment more generic (as it sh
Done
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h@91
PS16, Line 91: in_protected_segm
> nit: should be rather named 'in_protected_segment'?
Done
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h@116
PS16, Line 116: Sanitize
> style nit: since this isn't an accessor-like method, its name should be cap
Done
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h@228
PS14, Line 228: // ensure this is safe, e.g. by destructing the entity that owned the
: // original metrics.
: kReset,
: };
: // Set the cache metrics to update corresponding counters accordingly.
: virtual void SetMetrics(std::unique_ptr<CacheMetrics> metrics,
: ExistingMetricsPolicy metrics_policy) = 0;
:
: // Sets probationary and protected segments metrics to update corresponding counters accordingly.
: //
: // An upgrade of one entry will increment the number of evictions from the probationary segment by
: // one and the number of insertions into the protected segment by one.
: //
: // A downgrade of one entry will increment the number of evictions from the protected segment by
: // one and the number of insertions into the probationary segment by one.
: //
: // To calculate the number of inserts for the SLRU cache, subtract the number of evictions
: // of the protected segment from the number of inserts of the probationary segment.
: //
> OK. But even with that, instead of polluting the interface of the base Cac
SetMetrics() is used in other areas of the code that use a cache (file_cache, ttl_cache), so that can't be removed from the Cache interface. Similar to my comment from ProbationaryContains and ProtectedContains, this has to do with returning a pointer to Cache instead of ShardedSLRUCache so all methods will have to be defined here.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/nvm_cache.h
File src/kudu/util/nvm_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/nvm_cache.h@46
PS16, Line 46: Slice key() const {
: return Slice(kv_data, key_length);
: }
> Is this really needed? I didn't see NVM-based implementation of SLRU cache
Removed it for now, a follow up patch with the NVM-based implementation of SLRU cache will include this instead.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache-test.cc@413
PS17, Line 413: evicted to probationary segment
> If the probationary segment doesn't have enough free space for this new ent
Yep that's right. I guess the entry being upgraded from the probationary segment will create some space in the probationary segment, but if the entry being evicted from the protected segment is larger than the entry being upgraded, then more entries from the probationary segment will have to be evicted to create space. Added a test case to test for this behavior.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h@40
PS16, Line 40: NewSLRUCache
> Instead, is it possible to use the same approach as in cache.cc where it's
I guess then the question is what are the template parameters? It makes sense in cache.cc since there are multiple possible eviction policies (FIFO and LRU). This file is just for DRAM and for SLRU eviction policy so I don't think specializing this for template parameters makes sense since there's only one combination of parameters. Let me know if you think otherwise or if there are other benefits to doing this.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h@40
PS14, Line 40: Cache
> ShardedSLRUCache inherits from Cache, so the returned ShardedSLRUCache* cou
Tried to make this change, but the cache in block_cache is a unique pointer to Cache. Given the old LRU cache returns Cache*, it makes the most sense to keep this as Cache* as it doesn't accept ShardedSLRUCache*.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@57
PS16, Line 57: // A single shard of s
> Did you consider using the CacheShard template, templatized by EvictionPoli
It's definitely possible, however, the cache file would be even more polluted with SLRUCacheShard specific methods (ProtectedInsert(), InsertAndReturnEvicted(), ReInsert()). I also removed the use of the mutex in the SLRUCacheShard level methods since the ShardPair has a mutex now, so all methods on the shard level with a mutex would need a new method just for SLRUCacheShard.
So it's definitely possible, but it would pollute the cache.cc file even more. Let me know if you think it's worth the tradeoff.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@254
PS16, Line 254:
> What guarantees do we have to be sure that 'table_' cannot be modified unde
Only SLRUCacheShardPair::Lookup() calls this method, and within it everything is protected by a mutex. So until that mutex is released, no other ShardPair method can access the underlying shards and thus the underlying table within each shard. I'll add a note about the use of the mutex in the pair level methods.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@267
PS16, Line 267: return reinterpret_cast<Cache
> ditto: what if Insert() is running concurrently and modifying the 'table_'
Its only usage in the slru_cache.cc is protected by a mutex, similar to the explanation above where it's used within a ShardPair method that's protected by a mutex. Other than that, it's only used in unit tests through ProbationaryContains and ProtectedContains..
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@401
PS16, Line 401: }
: }
> nit here and below: define 'e' along with assigning the value at the same l
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@57
PS17, Line 57: ingle shard of
> Does it make sense to explicitly forbid copying and assigning of this class
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@273
PS17, Line 273: }
:
> nit: could these be joined, adding a comment on what's the intention of thi
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@434
PS17, Line 434: on_callback);
> Why to pass this as a parameter instead of having it as a constant for SLRU
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@441
PS17, Line 441:
: private:
> What's the reason of wrapping instances of SLRUCacheShard into std::unique_
Good point, removed the use of unique pointers here.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@460
PS17, Line 460: probationary_shard_(SLRUCacheShard(mem_tracker,
:
> This isn't needed.
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@471
PS17, Line 471: //
> What is the purpose of this extra scope?
Removed it
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@490
PS17, Line 490: seg
> nit: delete 'and'
Done
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@501
PS17, Line 501: C
> What is the purpose of this extra scope?
Removed it
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@543
PS17, Line 543: } else {
: protected_shard_.Release(handle);
: }
: }
:
: void SLRUCacheShardPair::Erase(const Slice& key, uint32_t hash) {
:
> What guards against the following scenarios:
I don't think having the atomic bool protects us from the scenarios you described.
The only shard agnostic behavior happens when the lookup handle in thread A is the last reference to the entry. Since in both scenarios you described thread B calls Lookup() thus adding another reference to the entry, both the contents and the metrics of the SLRU cache will stay consistent.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@552
PS17, Line 552: }
> What is the purpose of this extra scope?
Removed it
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@561
PS17, Line 561: boo
> What is the purpose of this extra scope?
Removed it
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@581
PS17, Line 581:
> nit:
I'm not sure I understand the proposed suggestion here. A clarification would be great, thanks!
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@601
PS17, Line 601: }
: shards_.clear();
: }
:
: UniquePendingHandle Allocate(Slice key, int val_len, int charge) override {
: int key_len = key.size();
: D
> Is this really needed? Wouldn't the contained unique_ptr be destroyed auto
The mem tracker doesn't get properly updated unless we explicitly clear each pointer to shard within the vector.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@694
PS17, Line 694: }
:
> nit: could these lines be joined?
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 18
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 16 May 2024 21:17:03 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 8:
(3 comments)
I took a quick look.
My request is to split this changelist into multiple pieces, at least separate out the following:
* refactoring on cache.{h,cc} and nvm_cache.{h,cc} that preclude introducing the SLRU cache
* introducing the SLRU cache
* introducing block cache metrics
Thank you!
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/block_cache_metrics.h
File src/kudu/util/block_cache_metrics.h:
PS8:
Why is it necessary to update the block cache metrics in the same changelist where implementing a new type of a cache?
Is it possible to introduce block cache metrics in a separate follow-up changelist?
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/cache.h@67
PS8, Line 67: // Recency list cache implementations (FIFO, LRU, etc.)
Is it possible to separate out this and other refactoring (i.e. moving duplicated code from nvm_cache.{h,cc} and cache.{h,cc}) into a separate changelist?
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/slru_cache.h@50
PS8, Line 50: class HandleDeleter {
: public:
: explicit HandleDeleter(SLRUCache* c)
: : c_(c) {
: }
:
: void operator()(Handle* h) const {
: if (h != nullptr) {
: c_->Release(h);
: }
: }
:
: SLRUCache* cache() const {
: return c_;
: }
:
: private:
: SLRUCache* c_;
: };
nit: maybe, it's time to templatize this class and re-use it throughout various types of caches in util?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 8
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 31 Jan 2024 04:44:16 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 7:
> Uploaded patch set 7.
Moving locking down to shard level.
SLRU cache is built on top of vector of pair of shards now.
Current approach is just for DRAM memory based caches.
A separate file similar to slru_cache will have to be written for NVM memory based caches.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 7
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 18 Jan 2024 20:49:55 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#20).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Metrics will be added in a follow-up patch.
Ran cache benchmarks for RELEASE build.
Build ran locally on macOS, 6 cores and 2.6GHz.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 10.68M | 99.5%
ZIPFIAN ratio=1.00x | SLRU | 10.68M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 10.68M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 9.86M | 95.9%
UNIFORM ratio=1.00x | LRU | 9.61M | 99.7%
UNIFORM ratio=1.00x | SLRU | 7.14M | 99.7%
UNIFORM ratio=3.00x | LRU | 6.43M | 33.3%
UNIFORM ratio=3.00x | SLRU | 5.09M | 27.6%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
7 files changed, 1,460 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/20
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 20
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 22: Verified+1
unrelated test failure in Java tests
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 22
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 11 Jun 2024 21:50:49 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#5).
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
KUDU-613: Scan Resistant Caching
This patch introduces the SLRU cache that has two internal caches,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected cache. Any random scans would
then only evict entries from the probationary cache.
Both the protected and probationary caches have their own
configurable capacities. When the protected cache is at capacity,
any entries evicted will be added to the MRU end of the
probationary cache.
TODO:
- Add performance tests
- Add upgrade/downgrade metrics for SLRU cache
- Use SLRU cache in BlockCache
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
8 files changed, 984 insertions(+), 157 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/5
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 5
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 4:
(9 comments)
It's very important to add performance tests to be able to reason about the performance of the current approach under heavy concurrent load.
Please add such a test -- you could take a look at the existing test scenarios for the cache with the plain LRU eviction policy.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@46
PS4, Line 46: Cache::MemoryType mem_type
Could this be templatized instead based on the 'mem_type'?
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@46
PS4, Line 46: lookups
nit: probably, 'lookup_threshold' or something similar might be a better moniker?
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@51
PS4, Line 51: CHECK_GT(lookups, 0);
: lookups_ = lookups;
nit: initialize lookups_ in the init list above, and then run CHECK_GT() on lookups_.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@83
PS4, Line 83: simple_spinlock mutex_;
Add a comment on what this synchronization primitive is used for?
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@84
PS4, Line 84: uint32_t lookups_;
nit: add const?
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@25
PS4, Line 25: Cache::UniqueHandle
nit: could add 'using' for this and drop the 'Cache::' prefix?
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@39
PS4, Line 39: std::lock_guard<decltype(mutex_)> l(mutex_);
Is this the giant lock on all the cache or that's per-shard one? If that's a giant lock, I don't think this is going to fit the bill since this is a bottleneck for a cache that's supposed to handle very high rate of concurrent requests.
I'd suggest you add performance tests to see how it fares compared with regular LRU cache -- if the concurrent performance is two times less or more than LRU cache with many shards, then this approach needs to be changed, so the locks are taken on a shard level, not the whole cache level.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@40
PS4, Line 40: Cache::UniqueHandle protected_handle(protected_cache_->Lookup(key, caching));
: Cache::UniqueHandle probationary_handle(probationary_cache_->Lookup(key, caching));
Could this be optimized to return right away if an element find in the protected section?
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@42
PS4, Line 42: // If an entry exists, it should not exist in both caches.
: CHECK(!(protected_handle && probationary_handle));
Have this only for when NDEBUG is not defined?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 4
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 09 Nov 2023 21:03:24 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#7).
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
KUDU-613: Scan Resistant Caching
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/block_cache_metrics.cc
M src/kudu/util/block_cache_metrics.h
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
10 files changed, 1,843 insertions(+), 228 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/7
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 7
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 17:
(16 comments)
A few more high-level observations.
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG@22
PS16, Line 22: Lookups/sec
It would be nice to mentions the following details:
* What type of build it was?
* What sort of machine it was: CPU cores and frequency?
It's crucial to measure this for RELEASE builds, we aren't interested to look at other types of builds here, I guess.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache-bench.cc
File src/kudu/util/cache-bench.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache-bench.cc@92
PS16, Line 92: ret+= " SLRU";
nit for here and elsewhere: separate variable and the operator by space
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/cache.h@520
PS17, Line 520: // Returns true if probationary segment contains key.
: // Returns false if not.
: // Only used for SLRU cache.
: virtual bool ProbationaryContains(const Slice& key) = 0;
:
: // Returns true if protected segment contains key.
: // Returns false if not.
: // Only used for SLRU cache.
: virtual bool ProtectedContains(const Slice& key) = 0;
Similar to SetSegmentMetrics(), this doesn't seem to be a place for these methods.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h@58
PS16, Line 58: Protects against random/long reads polluting cache.
nit: consider either making this part of the comment more generic (as it should be at this level) or dropping this part altogether
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h@91
PS16, Line 91: protected_segment
nit: should be rather named 'in_protected_segment'?
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/cache.h@116
PS16, Line 116: sanitize
style nit: since this isn't an accessor-like method, its name should be capitalized
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h@228
PS14, Line 228: // ensure this is safe, e.g. by destructing the entity that owned the
: // original metrics.
: kReset,
: };
: // Set the cache metrics to update corresponding counters accordingly.
: virtual void SetMetrics(std::unique_ptr<CacheMetrics> metrics,
: ExistingMetricsPolicy metrics_policy) = 0;
:
: // Sets probationary and protected segments metrics to update corresponding counters accordingly.
: //
: // An upgrade of one entry will increment the number of evictions from the probationary segment by
: // one and the number of insertions into the protected segment by one.
: //
: // A downgrade of one entry will increment the number of evictions from the protected segment by
: // one and the number of insertions into the probationary segment by one.
: //
: // To calculate the number of inserts for the SLRU cache, subtract the number of evictions
: // of the protected segment from the number of inserts of the probationary segment.
: //
> This will be used in the block cache to set the metrics for both segments o
OK. But even with that, instead of polluting the interface of the base Cache class you could make the BlockCache class to be a template by the type of the underlying cache implementation, and remove both SetMetrics() and SetSegmentMetrics() from the common Cache interface.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/nvm_cache.h
File src/kudu/util/nvm_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/nvm_cache.h@46
PS16, Line 46: // Number of lookups for this entry. Used for upgrading to protected segment in SLRU cache.
: // Resets to 0 when moved between probationary and protected segments in both directions.
: uint32_t lookups;
Is this really needed? I didn't see NVM-based implementation of SLRU cache, so this looks a bit strange given you decided not to converge on {S}LRUHandle structure
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h@40
PS16, Line 40: NewSLRUCache
Instead, is it possible to use the same approach as in cache.cc where it's just NewCache<> specialized for particular set of template parameters?
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h@40
PS14, Line 40: Cache
> The ShardedSLRUCache is local to the slru_cache.cc file. But for the logic
ShardedSLRUCache inherits from Cache, so the returned ShardedSLRUCache* could be used in all scenarios that accept Cache*.
Meanwhile, all the methods specific to ShardedSLRUCache could be moved out from the Cache interface (e.g. SetSegmentMetrics()).
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@57
PS16, Line 57: class SLRUCacheShard {
Did you consider using the CacheShard template, templatized by EvictionPolicy instead of duplicating significant amount of the code? Particular methods might be added using std::enable_if, and particular implementations might be specialized. You could take a look at how std::enable_if is used in current Kudu code.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@401
PS16, Line 401: Cache::RLHandle* e;
: e = table_.Remove(key, hash);
nit here and below: define 'e' along with assigning the value at the same line
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@57
PS17, Line 57: SLRUCacheShard
Does it make sense to explicitly forbid copying and assigning of this class' instances?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@434
PS17, Line 434: lookups_threshold
Why to pass this as a parameter instead of having it as a constant for SLRUCacheShardPair instance, similar to the capacity settings?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@441
PS17, Line 441: std::unique_ptr<SLRUCacheShard> probationary_shard_;
: std::unique_ptr<SLRUCacheShard> protected_shard_;
What's the reason of wrapping instances of SLRUCacheShard into std::unique_ptr? FWIW, these two are always instantiated in the constructor of the SLRUCacheShardPair class, and cannot be nullptr in any case, so why not to have them on the stack?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@460
PS17, Line 460: probationary_shard_.reset(nullptr);
: protected_shard_.reset(nullptr);
This isn't needed.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 17
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 May 2024 20:40:01 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 18:
Build Aborted
http://jenkins.kudu.apache.org/job/pre_commit/151/ : ABORTED
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 18
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 17 May 2024 09:14:36 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 19:
(11 comments)
First portion of comments: I'm going to post the second one later tonight.
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG
Commit Message:
PS16:
Don't forget to re-base this patch on top of the HEAD in the main branch, otherwise it might hit logical conflicts when pushed into the git repo (i.e. risking a broken build, etc.).
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG@22
PS16, Line 22:
> Pushing out this patch for now to get reviews, will work on setting up a re
I guess it's not a big deal to build in RELEASE configuration and run the test, so I hope to see the updates on the stats soon.
Thank you!
http://gerrit.cloudera.org:8080/#/c/20607/19//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/19//COMMIT_MSG@23
PS19, Line 23: Ran cache benchmarks for DEBUG build.
: Build ran locally on macOS, 6 cores and 2.6GHz.
We need stats for RELEASE build, not DEBUG. Please add those when you have a chance. Thanks a lot!
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/nvm_cache.cc
File src/kudu/util/nvm_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/nvm_cache.cc@556
PS19, Line 556:
nit: why to change this at all?
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.h@74
PS19, Line 74: // Returns true if probationary segment contains key.
: // Returns false if not.
: bool ProbationaryContains(const Slice& key);
:
: // Returns true if protected segment contains key.
: // Returns false if not.
: bool ProtectedContains(const Slice& key);
It seems the code evolved and these methods are now used only in tests. If so, maybe remove these from the interface and move their implementation into the test code since the tests are already marked as friends and have access to any fields and methods?
Alternatively, you could add Test suffix to the names, but I guess moving these out would be cleaner.
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.h@113
PS19, Line 113: Cache::EvictionPolicy eviction_policy = Cache::EvictionPolicy::SLRU,
The name of the method already assumes this cannot be anything but Cache::EvictionPolicy::SLRU, so why to have this parameter then?
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@63
PS19, Line 63: Cache::
nit for here and elsewhere in this file: maybe, add corresponding 'using' directives in this .cc file and omit 'Cache::' prefix?
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@231
PS19, Line 231: Cache::RLHandle* e = table_.Lookup(key, hash);
: return e != nullptr;
nit: could this be just
return table_.Lookup(key, hash) != nullptr;
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@516
PS19, Line 516: std::unique_ptr<SLRUCacheShardPair> shard(new SLRUCacheShardPair(mem_tracker_.get(),
: per_probationary_shard,
: per_protected_shard,
: lookups));
: shards_.push_back(std::move(shard));
nit: it could be
shards_.emplace_back(new ...);
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@526
PS19, Line 526: Without it, the destructor for memtracker is called before
: // the destructor for the SLRUCacheShards.
Instead of doing this, maybe just switch the order of the 'shards_' and the 'mem_tracker_' fields, so the destructor of 'shards_' is called first? Also, move this text blurb in there.
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@539
PS19, Line 539: Cache::UniquePendingHandle ShardedSLRUCache::Allocate(Slice key, int val_len, int charge) {
: int key_len = key.size();
: DCHECK_GE(key_len, 0);
: DCHECK_GE(val_len, 0);
: int key_len_padded = KUDU_ALIGN_UP(key_len, sizeof(void*));
: UniquePendingHandle h(reinterpret_cast<Cache::PendingHandle*>(
: new uint8_t[sizeof(Cache::RLHandle)
: + key_len_padded + val_len // the kv_data VLA data
: - 1 // (the VLA has a 1-byte placeholder)
: ]),
: Cache::PendingHandleDeleter(this));
: Cache::RLHandle* handle = reinterpret_cast<Cache::RLHandle*>(h.get());
: handle->lookups = 0;
: handle->in_protected_segment = false;
: handle->key_length = key_len;
: handle->val_length = val_len;
: // TODO(KUDU-1091): account for the footprint of structures used by Cache's
: // internal housekeeping (RL handles, etc.) in case of
: // non-automatic charge.
: handle->charge = (charge == Cache::kAutomaticCharge) ? kudu_malloc_usable_size(h.get())
: : charge;
: handle->hash = HashSlice(key);
: memcpy(handle->kv_data, key.data(), key_len);
:
: return h;
This and other methods below look to be exactly identical to the code in ShardedCache. Could you add a TODO to mention a re-factoring opportunity to avoid the duplication of the code? There is no need to address it right away (unless you really want to do so), just add a TODO for posterity, please. Thanks!
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 31 May 2024 23:48:12 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 19:
(1 comment)
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/cache-bench.cc
File src/kudu/util/cache-bench.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/cache-bench.cc@104
PS19, Line 104: std::max(kProbationarySegmentCapacity, kProtectedSegmentCapacity)
I think this should have been (kProbationarySegmentCapacity + kProtectedSegmentCapacity) instead to semantically match the fact that the total capacity of the cache is used to host all the test entries, similar to what's done for the LRU cache.
What do you think?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 03 Jun 2024 21:41:18 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 15: Verified-1
Build Failed
http://jenkins.kudu.apache.org/job/pre_commit/89/ : FAILURE
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 15
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 02 May 2024 21:48:22 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#16).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 6.37M | 99.3%
ZIPFIAN ratio=1.00x | SLRU | 5.81M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 6.15M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 5.49M | 99.0%
UNIFORM ratio=1.00x | LRU | 6.76M | 99.7%
UNIFORM ratio=1.00x | SLRU | 7.03M | 100.0%
UNIFORM ratio=3.00x | LRU | 3.84M | 33.4%
UNIFORM ratio=3.00x | SLRU | 3.60M | 36.5%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
9 files changed, 1,569 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/16
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/108/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 06 May 2024 11:18:26 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Abhishek Chennaka (Code Review)" <ge...@cloudera.org>.
Abhishek Chennaka has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 17:
(2 comments)
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache-test.cc@413
PS17, Line 413: evicted to probationary segment
If the probationary segment doesn't have enough free space for this new entry, the least recently accessed entry will be evicted to free up space - is that correct? If so, does it make sense to have a test case for that?
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@490
PS17, Line 490: and
nit: delete 'and'
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 17
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 May 2024 20:38:10 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has removed a vote on this change.
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Removed Verified-1 by Kudu Jenkins (120)
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: deleteVote
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 22
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#21).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Metrics will be added in a follow-up patch.
Ran cache benchmarks for RELEASE build.
Used default flag values in cache-bench.
Build ran locally on macOS, 6 cores and 2.6GHz.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 11.01M | 99.8%
ZIPFIAN ratio=1.00x | SLRU | 10.62M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 11.06M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 9.69M | 95.9%
UNIFORM ratio=1.00x | LRU | 8.54M | 99.7%
UNIFORM ratio=1.00x | SLRU | 6.18M | 99.7%
UNIFORM ratio=3.00x | LRU | 6.53M | 33.3%
UNIFORM ratio=3.00x | SLRU | 4.99M | 33.3%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
7 files changed, 1,486 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/21
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 21
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 21:
(4 comments)
Created new SLRUHandle to mimic RLHandle to resolve the ASAN issues. Any new field in the RLHandle resulted in ASAN issues in codegen.
http://gerrit.cloudera.org:8080/#/c/20607/20//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/20//COMMIT_MSG@23
PS20, Line 23: Ran cache benchmarks for RELEASE build
> nit: please also note whether you were using the default flag settings or t
Done
http://gerrit.cloudera.org:8080/#/c/20607/20//COMMIT_MSG@25
PS20, Line 25: Build ran locally on macOS, 6 cores and 2.6GHz.
> It would be great to add a few patterns into the cache-bench.cc that clearl
That's a good idea considering the SLRU cache doesn't perform better even for the ZIPFIAN distributions. I'll work on this for the next revision.
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/cache-bench.cc
File src/kudu/util/cache-bench.cc:
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/cache-bench.cc@60
PS20, Line 60: 3
> nit: did you experiment with other settings for the protected segment looku
Changed value to 3, ran the benchmarks again and updated commit message. The hit rates for all workloads are the same, the throughput lags though.
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/slru_cache.cc@400
PS20, Line 400: int key_len = key.size();
> nit: this could be replaced with the following in the header file
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 21
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 07 Jun 2024 22:48:35 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Abhishek Chennaka (Code Review)" <ge...@cloudera.org>.
Abhishek Chennaka has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 23: Code-Review+2
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 23
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 12 Jun 2024 01:54:48 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 5:
> Patch Set 4:
>
> (9 comments)
>
> It's very important to add performance tests to be able to reason about the performance of the current approach under heavy concurrent load.
>
> Please add such a test -- you could take a look at the existing test scenarios for the cache with the plain LRU eviction policy.
Just played around with some cache performance testing using the same workloads from cache-bench right now. The SLRU cache is significantly slower (4-6x) than the LRU cache. Looks like the locking will have to be on a shard level. I'll look into how to do that this weekend, any pointers/tips would be appreciated.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 5
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 Nov 2023 07:31:33 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 14:
(16 comments)
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@446
PS12, Line 446: while (added_weight < 0.99 * protected_segment_size_) {
> Consider adding the following test scenarios as well:
Added the scenarios in the first bullet point.
The second scenario you mentioned is covered in Upgrade already.
Let me know if the added tests are not enough.
http://gerrit.cloudera.org:8080/#/c/20607/13/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/13/src/kudu/util/slru_cache-test.cc@482
PS13, Line 482: TEST_P(SLRUSingleShardCacheTest, CornerCases) {
> warning: narrowing conversion from constant 'double' to 'int' [bugprone-nar
Done
http://gerrit.cloudera.org:8080/#/c/20607/13/src/kudu/util/slru_cache-test.cc@520
PS13, Line 520:
> warning: narrowing conversion from 'unsigned long' to signed type 'int' is
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@40
PS12, Line 40: NewSLRUC
> It seems there are many common methods between the Cache's and SLRUCache's
Made it inherit from Cache now, it's not the cleanest inheritance as there are some methods in the Cache interface there just for the SLRUCache and some methods in the Cache interface that are not used in the SLRUCache.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@89
PS12, Line 89:
> nit: Maybe add the reasoning why the handle to probationary segments is ret
I guess the next part of the sentence explains it, since it's the same handle being moved between segments and the protected segment lookup handle is null. But I can make it more clear.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@121
PS12, Line 121:
:
:
:
:
> Why to have these two methods in the public interface? If only the impleme
They're protected methods in the Cache interface now.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@134
PS12, Line 134:
:
:
> Consider moving this into the concrete class implementation: SRLUCache is j
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@507
PS12, Line 507: SLRUCacheShardPair(MemTracker* mem_tracker,
: size_t probationary_capacity,
: size_t protected_capacity);
: ~SLRUCacheShardPair();
:
: void SetMetrics(CacheMetrics* probationary_metrics, CacheMetrics* protected_metrics);
:
> Why to have these as methods instead of supplying the capacity for the prob
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@526
PS12, Line 526: // mutex_ protects the state of the shard pair from other threads reading/modifying the data.
: simple_spinlock mutex_;
> Why to have these created on the heap, not on the stack? Please add a comm
I mimicked the Cache interface's style of creating on the heap rather than the stack. I'd imagine it has to do with dynamic memory management (allocation) of entries. I'll look into this more.
Changed to using unique pointers instead of raw pointers.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@529
PS12, Line 529:
> What state?
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@556
PS12, Line 556: urn probationary_shard_->Insert(handle,
> nit: use reverse iterator instead?
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@558
PS12, Line 558: // If newly inserted entry has greater charge than previous one,
: // possible that entries can be evicted if at capacity.
: vector<Cache::RLHandle*> evictions;
: auto* inserted = protected_shard_->Pr
> Does it make sense to move this sanitization into the ReInsert() method?
Made a separate method for this sanitization and moved the callsites into the appropriate Insert methods.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@590
PS12, Line 590: return protected_handle;
: }
:
> If the entry is not present in both the segments, don't we insert the entry
We do insert into the probationary segment if the entry isn't present in either segment, but here since both handles are null it doesn't matter which one we return. That being said, I changed this logic in the latest patch and now it returns the probationary handle if the entry doesn't exist in either segment.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@627
PS12, Line 627: if (ProbationaryContains(e->key(), e->hash)) {
: probationary_shard_->Release(handle);
: } else {
: protected_shard_->Release(handle);
:
> Is it possible to have any race between the ProbationaryContains() check an
Release() is called when handles from Lookup() go out of scope. It is possible that an entry can be looked up, and while the handle is being released it's upgraded to the protected segment by another thread. I added a lock to this method as result. Given that this method is called every time a lookup handle is out of scope, performance testing showed that adding a mutex here did result in less lookups per second (by around 50%).
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@800
PS12, Line 800:
> Is it possible to store unique_ptr instead of raw pointers in the shards_ c
Done
http://gerrit.cloudera.org:8080/#/c/20607/13/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/13/src/kudu/util/slru_cache.cc@69
PS13, Line 69: Cache::Handle* Insert(Cache::RLHandle* handle, Cache::EvictionCallback* eviction_callback);
> warning: method 'GetCapacity' can be made const [readability-make-member-fu
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 14
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 28 Feb 2024 09:42:12 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#6).
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
KUDU-613: Scan Resistant Caching
This patch introduces the SLRU cache that has two internal caches,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected cache. Any random scans would
then only evict entries from the probationary cache.
Both the protected and probationary caches have their own
configurable capacities. When the protected cache is at capacity,
any entries evicted will be added to the MRU end of the
probationary cache.
TODO:
- Add performance tests
- Improve concurrency (shard level locking)
- Use SLRU cache in BlockCache
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/block_cache_metrics.cc
M src/kudu/util/block_cache_metrics.h
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
10 files changed, 1,219 insertions(+), 157 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/6
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 6
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Abhishek Chennaka (Code Review)" <ge...@cloudera.org>.
Abhishek Chennaka has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 18:
(1 comment)
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc@280
PS18, Line 280: Erase
nit: Although self explanatory, it'd good to have a comment to brief what is done here for uniformity.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 18
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 27 May 2024 20:16:51 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Abhishek Chennaka (Code Review)" <ge...@cloudera.org>.
Abhishek Chennaka has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 18:
(1 comment)
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@188
PS18, Line 188: UpdateMemTracker(-static_cast<int64_t>(e->charge));
: if (PREDICT_TRUE(metrics_)) {
: metrics_->cache_usage->DecrementBy(e->charge);
: metrics_->evictions->Increment();
: }
Is it possible to avoid code repetition here and SoftFreeEntry()?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 18
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 29 May 2024 18:35:24 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 19:
Build Aborted
http://jenkins.kudu.apache.org/job/pre_commit/190/ : ABORTED
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 31 May 2024 05:19:27 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 20:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/195/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 20
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 04 Jun 2024 20:54:37 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
Build Aborted
http://jenkins.kudu.apache.org/job/pre_commit/108/ : ABORTED
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 06 May 2024 13:09:18 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 17:
Build Aborted
http://jenkins.kudu.apache.org/job/pre_commit/131/ : ABORTED
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 17
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Sat, 11 May 2024 04:54:11 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 17:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/131/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 17
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 May 2024 16:54:10 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 18:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/151/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 18
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 16 May 2024 21:14:35 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 14:
(10 comments)
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG@22
PS16, Line 22:
> This was a DEBUG build run locally on macOS. 6 cores and 2.6 GHz. I'll try
Thanks for clarifying.
We are mostly interested in RELEASE build stats in the context of performance evaluation. DEBUG and sanitizer builds don't provide any meaningful stats since
nobody runs DEBUG builds in production :)
You can always create create a VM in hosted or public cloud providers, build Kudu from scratch there and run performance tests.
I think it's essential to have the actual stats for the lookup operations provides for a RELEASE build in this description.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h@228
PS14, Line 228: // Sets probationary and protected segments metrics to update corresponding counters accordingly.
: //
: // An upgrade of one entry will increment the number of evictions from the probationary segment by
: // one and the number of insertions into the protected segment by one.
: //
: // A downgrade of one entry will increment the number of evictions from the protected segment by
: // one and the number of insertions into the probationary segment by one.
: //
: // To calculate the number of inserts for the SLRU cache, subtract the number of evictions
: // of the protected segment from the number of inserts of the probationary segment.
: //
: // To calculate the number of evictions for the SLRU cache, subtract the number of insertions
: // of the protected segment from the number of evictions of the probationary segment.
: //
: // Other than insertions and evictions, to calculate the metric for the SLRU cache, add the
: // corresponding metric from the probationary and protected segment together.
: virtual void SetSegmentMetrics(std::unique_ptr<CacheMetrics> probationary_metrics,
: std::unique_ptr<CacheMetrics> protected_metrics,
: ExistingMetricsPolicy metrics_policy) = 0;
> SetMetrics() is used in other areas of the code that use a cache (file_cach
OK, I guess one can try to circle back on the attempts to clean up this mess and bad smell in a follow-up patch.
In this iteration, please add a TODO for the extra methods that are specific to the SLRU cache. One approach might be adding extra interface(s) and moving the specific methods out of the common Cache interface.
Thank you!
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache-test.cc@442
PS18, Line 442: const int weight = static_cast<int>(protected_segment_size_ / 100);
It would be great to add a comment to explain what 'downgrade eviction' means along with short description on what essential invariants we have to track in this scenario and why.
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.h@40
PS16, Line 40: NewSLRUCache
> I guess then the question is what are the template parameters? It makes sen
Those are the usual benefits of having common approach: this is to have more uniform code when instantiating cache, and it automatically helps in a templatized code. It could also help with differences in the signatures of the constructors.
For example, one extra level of indirection to help with the different signatures of the constructors might be introducing CacheParameters template and hiding differences in the set of parameters for the constructors. That's a common way of doing so -- you could check SslTypeTraits in openssl_util.h for an inspiration.
I guess we could keep this as-is for now, especially if you are not fond of getting rid of the code ugliness in this patch itself. There might be an opportunity to clean this up later on, but most likely this will stay as ugly as its left in the first version :)
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/16/src/kudu/util/slru_cache.cc@57
PS16, Line 57: class SLRUCacheShard {
> It's definitely possible, however, the cache file would be even more pollut
IIUC, you could get away from pollution by using std::enable_if construct, so only classes of particular template parameter get particular methods instantiated. That's orthogonal to the idea of inheritance and will require updates in several other places, though.
I agree that a detailed plan is needed to switch to a particular way of consolidating all this feedback on improving the structure of the cache code.
My concern is that the cache code becomes more and more hairy, but I had high hopes to keep it cleaner. The first step into the spaghetti realm was with the introduction of the NVRAM-backed cache, as you could see in your attempt to unify on common data structures in your preliminary patches. Once somebody try adding SLRU NVRAM-backed cache later one, it will diverge even further.
For some reason I naively thought this work might be a good opportunity to clean up the cache code. Some cleanup has been done, but it seems the rest of it is better to bring in in separate follow-up steps.
To sum this up: I'm OK with keeping it as-is, especially if there is a pressure to bring in the functionality sooner than later: it's been 18 revisions already.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@581
PS17, Line 581:
> I'm not sure I understand the proposed suggestion here. A clarification wou
Whoops, the comment is lost, indeed.
I guess that nit was about keeping each of the initializer's values in its down line.
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@601
PS17, Line 601: // in probationary segment to avoid evicting any entries in the protected segment.
: if (val_handle->lookups < lookups_threshold ||
: val_handle->charge > protected_shard_->GetCapacity()) {
: return probationary_handle;
: }
:
: /
> The mem tracker doesn't get properly updated unless we explicitly clear eac
I'm not sure I understand: if each of the elements is of std::unique_ptr<> type, the calling reset(nullptr) on it effectively invokes the destructor of the SLRUCacheShardPair class, and nothing else, right?
But that's exactly what happens upon destroying ShardedSLRUCache::shards_ when its destructor is being invoked, no? The only difference is that the order of calling the destructors are reverse compared with the extra code there.
Anyway, if there is any non-trivial logic behind, please add a comment about that.
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@448
PS18, Line 448:
Could this be 'const'?
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@460
PS18, Line 460: // We free the entries here outside mutex for performance reasons.
: while (to_remove_head != nullptr) {
: Cache::RLHandle* next = to_remove_head->next;
: FreeEntry(to_remove_head);
: to_remove_head = next;
nit: fix the indent
http://gerrit.cloudera.org:8080/#/c/20607/18/src/kudu/util/slru_cache.cc@574
PS18, Line 574:
style nit: fix the indent
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 14
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 22 May 2024 02:25:41 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 9:
(3 comments)
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/block_cache_metrics.h
File src/kudu/util/block_cache_metrics.h:
PS8:
> +1
Moved the block cache metrics out of this patch, will be part of a follow up patch.
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/cache.h@67
PS8, Line 67: // Recency list handle. An entry is a variable length heap-allocated structure.
> +1
Done
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/slru_cache.h@50
PS8, Line 50: // UniquePendingHandle -- a wrapper around opaque PendingHandle structure
: // to facilitate automatic reference counting newly allocated cache's handles.
: typedef std::unique_ptr<Cache::PendingHandle,
: Cache::PendingHandleDeleter<SLRUCache>> UniquePendingHandle;
:
: // Sets probationary and protected segments metrics to update corresponding counters accordingly.
: //
: // Entries are reconstructed on any movement between the segments (upgrade/downgrade).
: //
: // An upgrade of one entry will increment the number of evictions from the probationary segment by
: // one and the number of insertions into the protected segment by one.
: //
: // A downgrade of one entry will increment the number of evictions from the protected segment by
: // one and the number of insertions into the probationary segment by one.
: //
: // To calculate the number of inserts for the SLRU cache, subtract the number of evictions
: // of the protected segment from the number of inserts of the probationary segment.
: //
: //
> nit: maybe, it's time to templatize this class and re-use it throughout var
I did so, but for any uses of this templatized class both Free() and Release() will have to be made public as it was done so for SLRUCache. If this is not an acceptable tradeoff, let me know and I can revert these changes.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 9
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 07 Feb 2024 20:35:21 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#11).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
6 files changed, 1,421 insertions(+), 0 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/11
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 11
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 4:
(1 comment)
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@39
PS4, Line 39: std::lock_guard<decltype(mutex_)> l(mutex_);
> It's a giant lock for now, I'll look into performance testing with this app
The LRU cache doesn't have a lock at the top level: that's just lock-free lookups in the shard vector first, and then it comes does to operations within a shard.
Locking per shard helps to increase the concurrency of the cache in real world scenarios when used as a block cache for Kudu tablet servers. Since a tablet server hosts multiple tablets which contain different data, per-shard locks are engaged only when the data is accessed within a shard. Assuming the hashing function gives a good projection of the global key space, it allows to run N threads concurrently, assuming each thread is accessing a separate shard.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 4
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 13 Nov 2023 18:08:24 +0000
Gerrit-HasComments: Yes
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 2:
(7 comments)
Thanks for your feedback! I left comments addressing your concerns about the eviction callbacks. For the block cache, there's no callback interface used anyways as a null pointer is passed in for the eviction_callback object when inserting into a cache.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc
File src/kudu/util/cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@546
PS1, Line 546: to_remove_head = next;
> In this context, I'd think of having more control over the eviction callbac
The actual handle for this entry isn't being returned to insert into the probationary cache. Only the necessary information from the evicted entries are being returned as part of EvictedHandle, so it's fine if the eviction callback is called now since it would just delete the entry from the protected cache, then we construct a new entry for the probationary cache.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@780
PS1, Line 780: / 'prote
> Do we really need explicit here?
Done
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@780
PS1, Line 780: ted-capacity'. T
> Would be nice to document the parameters of the constructor (e.g., what cap
Good point, changed it to one id and auto generated ids for sub caches
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@797
PS1, Line 797: s are evicted from protected cache,
> Would be great to clarify whether that insert is constrained by the capacit
Yep the insert is constrained by the capacity, but the cache will evict as many entries as necessary to be able to insert the new entry while being within the capacity of the cache. That's all done as part of the Insert() method.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@797
PS1, Line 797: If any e
> Do we really need to allocate anything at that point?
When entries are evicted from the protected cache, the logic I wrote right now only returns the necessary information to build a new entry by using the Allocate/Insert methods. So the actual entry gets erased from the protected cache, but we retain the necessary information to build a new handle for the same entry.
The alternative to this would be to retain the actual handle that points to the entry, but when it's being evicted FreeEntry() is called which deletes the data. I could add a reference to this handle which would prevent the data from being deleted, some other information (the hash) would have to be changed to reflect the entry being in a new cache (probationary). Instead of doing this, I thought it would be more straightforward/less error prone to retain the necessary information to build a new entry and go through the insertion path again by calling Allocate() and Insert().
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@810
PS1, Line 810: obati
> It seems Erase() might trigger calling the eviction callback, and that's no
If the eviction callback was defined, it would just evict it from the probationary cache, not the entire SLRU cache. So that behavior is consistent with what we expect here.
I actually have to move this logic after the allocation and insertion of this entry into the protected cache, since the allocation/insertion uses the handle returned from a Get call() which returns a pointer to the entry. If we erase this entry here, then IIUC the value would be erased.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/nvm_cache.cc
File src/kudu/util/nvm_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/nvm_cache.cc@339
PS1, Line 339: // Useful for SLRU cac
> It would be great to clarify on the ownership of the returned items in the
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 2
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 25 Oct 2023 20:22:49 +0000
Gerrit-HasComments: Yes
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 1:
(7 comments)
Overall this approach makes sense to me.
At this point, it seems there is at least an issue with eviction callbacks, if I'm not mistaken. It seems more attention needs to be paid to the overall flow of those when an entry is evicted from a region/sub-cache of the SLRU cache.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc
File src/kudu/util/cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@546
PS1, Line 546: FreeEntry(to_remove_head);
In this context, I'd think of having more control over the eviction callback that's a part of the FreeEntry() call. IIUC, the actual eviction could happen later on when the entry is definitely pushed out of the SLRU cache, but at this time it could not be possible to tell whether . What do you think?
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@780
PS1, Line 780: explicit
Do we really need explicit here?
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@780
PS1, Line 780: ShardedSLRUCache
Would be nice to document the parameters of the constructor (e.g., what capacity units are used).
BTW, do we really need to expose two separate ID strings for the part of the cache? Would it be enough to have just a single ID string, and the ID strings for the probationary and the protected parts might be auto-generated based on that single ID string?
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@797
PS1, Line 797: insert them into probationary cache
Would be great to clarify whether that insert is constrained by the capacity of the probationary part of the cache.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@797
PS1, Line 797: allocate
Do we really need to allocate anything at that point?
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/cache.cc@810
PS1, Line 810: Erase
It seems Erase() might trigger calling the eviction callback, and that's not the expected behavior, I guess.
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/nvm_cache.cc
File src/kudu/util/nvm_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/1/src/kudu/util/nvm_cache.cc@339
PS1, Line 339: vector<Cache::Handle*>
It would be great to clarify on the ownership of the returned items in the inline doc comment.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 1
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 23 Oct 2023 18:31:46 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/99/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 03 May 2024 18:12:28 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/104/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Sun, 05 May 2024 20:18:59 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#9).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
4 files changed, 1,399 insertions(+), 0 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/9
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 9
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 19:
(2 comments)
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@66
PS19, Line 66: vector<Cache::RLHandle*> InsertAndReturnEvicted(Cache::RLHandle* handle);
For this and other methods that are specific to protected or probational segments: it would be great if those were present only in classes for corresponding segments, otherwise the code is bit brittle since corresponding invariants aren't checked. I'm not sure whether you have capacity to take care of this in this patch, but for the future consider either using one extra level of inheritance (ProbationalShardSegment --> SLRUCacheShard, ProtectedShardSegment --> SLRUCacheShard) to have those specific methods only in particular shards, or maybe using templatized approach and std::enable_if template meta-programming construct.
I'm OK with keeping it as-is in this patch, maybe just add TODO to make the code more robust.
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@468
PS19, Line 468: // Go through all evicted entries from the protected segment and insert them into
: // the probationary segment. Reverse iterate through evictions to insert MRU first.
: for (auto it = evictions.rbegin(); it != evictions.rend(); ++it) {
: Cache::RLHandle* evicted_entry = *it;
: probationary_shard_.ReInsert(evicted_entry);
: }
After consideration, inserting MRU first seems counter-productive. For simplicity, let's assume the target segment is empty before all this elements start being inserted. If MRU are inserted first, and LRU inserted last, then:
* among all the inserted, MRU becomes LRU after insertion is complete
* if there isn't enough space in the segment, then LRU elements that are inserted last would push out elements inserted earlier (i.e. those that used to be MRU elements), which means MRU elements be evicted, but LRU elements stay
I might be missing something, please correct me if I'm wrong.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Sat, 01 Jun 2024 06:24:43 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 21: Verified-1
Build Failed
http://jenkins.kudu.apache.org/job/pre_commit/218/ : FAILURE
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 21
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 07 Jun 2024 22:52:36 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#13).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
6 files changed, 1,583 insertions(+), 0 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/13
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 13
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 12:
(4 comments)
Fixed the ASAN test error and addressed the comments left by tidy bot.
http://gerrit.cloudera.org:8080/#/c/20607/11/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/11/src/kudu/util/slru_cache-test.cc@310
PS11, Line 310: const int size_per_elem = static_cast<int>(total_cache_size_ / kNumElems);
> warning: narrowing conversion from 'unsigned long' to signed type 'int' is
Done
http://gerrit.cloudera.org:8080/#/c/20607/11/src/kudu/util/slru_cache-test.cc@333
PS11, Line 333: const int weight = static_cast<int>(protected_segment_size_ / 100);
> warning: narrowing conversion from 'unsigned long' to signed type 'int' is
Done
http://gerrit.cloudera.org:8080/#/c/20607/11/src/kudu/util/slru_cache-test.cc@396
PS11, Line 396: Insert(entry, delta * 2 + entry, static_cast<int>(1.25 * weight));
> warning: narrowing conversion from 'double' to 'int' [bugprone-narrowing-co
Done
http://gerrit.cloudera.org:8080/#/c/20607/11/src/kudu/util/slru_cache-test.cc@409
PS11, Line 409: const int weight = static_cast<int>(protected_segment_size_ / 100);
> warning: narrowing conversion from 'unsigned long' to signed type 'int' is
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 12
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 13 Feb 2024 21:39:50 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#19).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Metrics will be added in a follow-up patch.
Ran cache benchmarks for DEBUG build.
Build ran locally on macOS, 6 cores and 2.6GHz.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 6.37M | 99.3%
ZIPFIAN ratio=1.00x | SLRU | 5.81M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 6.15M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 5.49M | 99.0%
UNIFORM ratio=1.00x | LRU | 6.76M | 99.7%
UNIFORM ratio=1.00x | SLRU | 7.03M | 100.0%
UNIFORM ratio=3.00x | LRU | 3.84M | 33.4%
UNIFORM ratio=3.00x | SLRU | 3.60M | 36.5%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
8 files changed, 1,514 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/19
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 19:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/190/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 19
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 30 May 2024 17:06:50 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 21:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/218/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 21
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 07 Jun 2024 22:47:17 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 22:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/220/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 22
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 07 Jun 2024 23:10:07 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has submitted this change and it was merged. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
Metrics will be added in a follow-up patch.
Ran cache benchmarks for RELEASE build.
Used default flag values in cache-bench.
Build ran locally on macOS, 6 cores and 2.6GHz.
Here are some benchmark numbers for SLRU cache:
Test case | Algorithm | Lookups/sec | Hit rate
ZIPFIAN ratio=1.00x | LRU | 11.01M | 99.8%
ZIPFIAN ratio=1.00x | SLRU | 10.62M | 99.9%
ZIPFIAN ratio=3.00x | LRU | 11.06M | 95.9%
ZIPFIAN ratio=3.00x | SLRU | 9.69M | 95.9%
UNIFORM ratio=1.00x | LRU | 8.54M | 99.7%
UNIFORM ratio=1.00x | SLRU | 6.18M | 99.7%
UNIFORM ratio=3.00x | LRU | 6.53M | 33.3%
UNIFORM ratio=3.00x | SLRU | 4.99M | 33.3%
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Reviewed-on: http://gerrit.cloudera.org:8080/20607
Tested-by: Alexey Serbin <al...@apache.org>
Reviewed-by: Alexey Serbin <al...@apache.org>
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache-bench.cc
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
7 files changed, 1,486 insertions(+), 5 deletions(-)
Approvals:
Alexey Serbin: Looks good to me, approved; Verified
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 23
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 12:
(11 comments)
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@446
PS12, Line 446:
Consider adding the following test scenarios as well:
* trying to insert an entry with the same key into SLRU cache: (sub-case A) the entry is in probation segment (sub-case B) the entry is in protected segment; in both sub-cases add a sub-sub-case to work with relatively tiny entries (1/10 of the segment capacity) and large entries (1/2, 1/3, and 1/1 of the segment size)
* insert-and-then-lookup for the same key: do it multiple times, up to and over the lookup threshold
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@40
PS12, Line 40: SLRUCache
It seems there are many common methods between the Cache's and SLRUCache's interfaces. Does it make sense to have SLRUCache inheriting from Cache? Is it really necessary to put SLRUCache in a separate inheritance branch?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@121
PS12, Line 121: // Returns true if the probationary segment contains key, false if not.
: virtual bool ProbationaryContains(const Slice& key) = 0;
:
: // Returns true if the protected segment contains key, false if not.
: virtual bool ProtectedContains(const Slice& key) = 0;
Why to have these two methods in the public interface? If only the implementation and tests use these, maybe make them private and add the corresponding tests into the list of friends.
Also, why not to have those just at the level of SLRUShardedCache?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@134
PS12, Line 134:
: private:
: DISALLOW_COPY_AND_ASSIGN(SLRUCache);
Consider moving this into the concrete class implementation: SRLUCache is just an interface, right?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@507
PS12, Line 507: void SetProbationaryCapacity(size_t probationary_capacity) {
: probationary_shard_->SetCapacity(probationary_capacity);
: }
:
: void SetProtectedCapacity(size_t protected_capacity) {
: protected_shard_->SetCapacity(protected_capacity);
: }
Why to have these as methods instead of supplying the capacity for the probationary and the protected segments as parameters for the SLRUCacheShardPair's constructor? So far it seems these methods are used only right after an instance of SLRUCacheShardPair is created, before adding it into the 'shards_' container of the ShardedSLRUCache class.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@526
PS12, Line 526: SLRUCacheShard* probationary_shard_;
: SLRUCacheShard* protected_shard_;
Why to have these created on the heap, not on the stack? Please add a comment with the reasoning.
If having these on the heap, why to keep the raw pointers instead wrapping them into std::unique_ptr?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@529
PS12, Line 529: the following state
What state?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@556
PS12, Line 556: size_t i = evictions.size(); i > 0; --i
nit: use reverse iterator instead?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@558
PS12, Line 558: evicted_entry->lookups = 0;
: evicted_entry->prev = nullptr;
: evicted_entry->next = nullptr;
: evicted_entry->next_hash = nullptr;
Does it make sense to move this sanitization into the ReInsert() method?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@627
PS12, Line 627: if (ProbationaryContains(e->key(), e->hash)) {
: probationary_shard_->Release(handle);
: } else {
: protected_shard_->Release(handle);
: }
Is it possible to have any race between the ProbationaryContains() check and some other thread that might move the entry between the segments?
If not, please add a comment explaining why there cannot be any
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@800
PS12, Line 800: SLRUCacheShardPair*
Is it possible to store unique_ptr instead of raw pointers in the shards_ container?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 12
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 14 Feb 2024 22:28:52 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 17:
(1 comment)
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/slru_cache.cc@543
PS17, Line 543: // Release from either the probationary or the protected shard.
: if (!e->protected_segment) {
: probationary_shard_->Release(handle);
: } else {
: protected_shard_->Release(handle);
: }
: }
What guards against the following scenarios:
Scenario_0:
* thread_A: an instance of Cache::UniqueHandle as a wrapper for entry_X is being destroyed
* thread_A: while executing SLRUCacheShardPair::Release(), finds entry_X isn't in the protected shard
* thread_B: calls SLRUCacheShardPair::Lookup(), moving entry_X into the protected shard
* thread_A: calls Release() on the corresponding probationary shard for entry_X
Scenario_1:
* thread_A: an instance of Cache::UniqueHandle as a wrapper for entry_X is being destroyed
* thread_A: while executing SLRUCacheShardPair::Release(), finds entry_X is in the protected shard
* thread_B: calls SLRUCacheShardPair::Lookup() for some other entry_Y which is in the probationary shard, but due to crossing the threshold of lookup operations per entry, it's now being moved into the protected shard, so entry_X is pushed out of the protected shard
* thread_A: calls Release() on the corresponding protected shard for entry_X
If nothing prevents from having such scenarios, then a few questions:
* Does the contents SLRU cache stay consistent after that?
* Do metrics of the SLRU cache stay consistent after that?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 17
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Sat, 11 May 2024 01:09:24 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 15:
Build Started http://jenkins.kudu.apache.org/job/pre_commit/89/
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 15
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 02 May 2024 20:47:39 +0000
Gerrit-HasComments: No
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#3).
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
WIP KUDU-613: Scan Resistant Caching
This patch introduces a new class, the SLRU cache with two segments,
the probationary and protected, to protect the cache from long/random
reads.
Looking for feedback on general approach for implementation so far.
TODO:
- Add tests
- Add metrics on SLRU cache level, both segments already have their
own metrics
- Use SLRU cache in BlockCache
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
3 files changed, 305 insertions(+), 4 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/3
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 3
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 10:
(4 comments)
Just glanced over the tests, and there is one question I'd like to clarify before going over the rest of the code.
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@76
PS10, Line 76:
nit: the indent should be 2 + 4 = 6 spaces here
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@80
PS10, Line 80: { }
nit: wrong indent
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@209
PS10, Line 209: RETURN_IF_NO_NVM_CACHE(GetParam().first);
Here and below: does it mean the test is run only on NVM cache? If so, how to test SLRU cache on DRAM then?
And why running/skipping SLRU-related tests is predicated in NVM cache presence at all?
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache-test.cc@244
PS10, Line 244: Erase
Does it make sense to test the erase operation for both the cases when an entry is in probationary and protected segments?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 10
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 08 Feb 2024 06:12:33 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#12).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
6 files changed, 1,424 insertions(+), 0 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/12
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 12
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 12:
(18 comments)
I took a quick look and left a few comments. I'm going to continue tomorrow, but if it makes sense, you might consider addressing the items that I already pointed at.
Thank you!
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@75
PS12, Line 75: lookups
What's the unit for the 'size'? Maybe add a small doc blurb about that, documenting the constructor.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@90
PS12, Line 90: -1;
nit: indeed, -1 is quite a special value :) Do you think it's safer to use std::optional instead of introducing the special value semantics? Or the performance here is the priority?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@170
PS12, Line 170: 4 * 1024 * 1024, 12 * 1024 * 1024
nit: would be great to add a small doc blurb to explain why 1/3 is the preferred ratio for the tests.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@193
PS12, Line 193: 4 * 1024 * 1024, 12 * 1024 * 1024
nit for here and above: maybe, create two constants out of these two arguments and use those instead?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@447
PS12, Line 447: } // namespace kudu
Please add a few test scenarios to make sure the code works as expected at least for a few corner cases, such as:
* trying to insert an entry that's larger than the capacity of the cache's sections: both, greater than just the probationary segment
* inserting an entry that isn't in the cache when the probationary segment is exactly at capacity, and the entry being inserted is exactly of the probationary segment's side
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@71
PS12, Line 71: Cache::Handle* Insert(Cache::RLHandle* handle, Cache::EvictionCallback* eviction_callback);
nit: add a comment as for the other methods in this interface?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@291
PS12, Line 291: handle->eviction_callback = eviction_callback;
Is it OK to override an already set eviction callback for a handle? If not, maybe add corresponding DCHECK() here?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@573
PS12, Line 573: are
nit: is?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@573
PS12, Line 573: number
nit: the number
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@574
PS12, Line 574: are
nit: is ?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@574
PS12, Line 574: number
nit: the number
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@583
PS12, Line 583: Cache::Handle* protected_handle = protected_shard_->Lookup(key, hash, caching);
Does it make sense to optimize for the case when the entry is already in the protected segment? If it's there, just return it immediately. Then it's not necessary to run look it up in the probationary shard, right?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@595
PS12, Line 595: aren't
nit: isn't ?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@596
PS12, Line 596: protected segment
nit: the protected segment
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@596
PS12, Line 596: return lookup of entry in probationary segment
return the entry found in the probationary segment
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@608
PS12, Line 608: vector<Cache::RLHandle*> evictions
What if the entry that has just been inserted evicted right away with all the rest of the entries due to capacity limit?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@610
PS12, Line 610: protected segment
nit: the protected segment
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@612
PS12, Line 612: for (size_t i = evictions.size(); i > 0; --i) {
Could use reverse iterator instead of dancing with indices?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 12
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 14 Feb 2024 05:21:08 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 5:
(9 comments)
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@46
PS4, Line 46: rded LRU caches with a fix
> Could this be templatized instead based on the 'mem_type'?
I need access to the mem_type for some logic in slru_cache. DRAM-based cache uses a RLHandle while the NVM-based cache uses an LRUHandle.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@46
PS4, Line 46: onary_c
> nit: probably, 'lookup_threshold' or something similar might be a better mo
Done
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@51
PS4, Line 51: SLRUCache(size_t probationary_capacity, size_t protected_capacity,
: Cache::Memo
> nit: initialize lookups_ in the init list above, and then run CHECK_GT() on
Done
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@83
PS4, Line 83: // entry is erased from
> Add a comment on what this synchronization primitive is used for?
Done
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.h@84
PS4, Line 84: // inserted into t
> nit: add const?
Done
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@25
PS4, Line 25: namespace kudu {
> nit: could add 'using' for this and drop the 'Cache::' prefix?
Tried, but can't use 'using' for class members.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@39
PS4, Line 39:
> Is this the giant lock on all the cache or that's per-shard one? If that's
It's a giant lock for now, I'll look into performance testing with this approach this weekend.
How would locking on the per shard level work for this use case? On a shard level within both the probationary and the protected cache, locks already exist, but this giant lock just prevents any actions from taking place on the entire slru cache during the lookup operation since entries can be erased, allocated/inserted, and lookups exist. Maybe I don't quite fully understand how the per shard level locking would look here.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@40
PS4, Line 40: std::lock_guard<decltype(mutex_)> l(mutex_);
: Cache::UniqueHandle probationary_handle(probationary_cache_->Lookup(key, caching));
> Could this be optimized to return right away if an element find in the prot
It could but then we can't check the condition below, checking that the entry doesn't exist in both the probationary and protected cache.
http://gerrit.cloudera.org:8080/#/c/20607/4/src/kudu/util/slru_cache.cc@42
PS4, Line 42: Cache::UniqueHandle protected_handle(protected_cache_->Lookup(key, caching));
: // If an entry exists, it should not exist in both
> Have this only for when NDEBUG is not defined?
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 5
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 Nov 2023 00:33:07 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 6:
> Uploaded patch set 6.
Added metrics. Added another unit test and fixed ASAN error. Will work on shard level locking now.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 6
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 14 Nov 2023 18:44:32 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Marton Greber, Alexey Serbin, Attila Bukor, Kudu Jenkins, Abhishek Chennaka,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#14).
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
KUDU-613: Introduce SLRU cache
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
8 files changed, 1,610 insertions(+), 0 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/14
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 14
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 13:
(18 comments)
Addressed the first batch of comments, I'll address the next batch of comments in the next revision.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc
File src/kudu/util/slru_cache-test.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@75
PS12, Line 75: lic Cac
> What's the unit for the 'size'? Maybe add a small doc blurb about that, do
Do you mean for 'probationary_segment_size' and 'protected_segment_size'? Just size_t which is an unsigned long I believe. Maybe I don't fully understand the question.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@90
PS12, Line 90:
> nit: indeed, -1 is quite a special value :) Do you think it's safer to use
I think it's ok to use -1 here, I'll add a comment noting how -1 is used as the default value for no value was found.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@170
PS12, Line 170:
> nit: would be great to add a small doc blurb to explain why 1/3 is the pref
I'm not sure what the preferred ratio is, I just chose a ratio that I thought would make sense here.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@193
PS12, Line 193: Test :
> nit for here and above: maybe, create two constants out of these two argume
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache-test.cc@447
PS12, Line 447: ASSERT_FALSE(slru_cache_->ProbationaryContains(EncodeInt(i)));
> Please add a few test scenarios to make sure the code works as expected at
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@71
PS12, Line 71: }
> nit: add a comment as for the other methods in this interface?
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@291
PS12, Line 291: }
> Is it OK to override an already set eviction callback for a handle? If not
This is a newly allocated handle, so it won't have an eviction callback set until this line.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@573
PS12, Line 573:
> nit: the number
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@573
PS12, Line 573:
> nit: is?
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@574
PS12, Line 574: kup
> nit: is ?
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@574
PS12, Line 574: acheSh
> nit: the number
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@583
PS12, Line 583: // segment. Return the lookup handle. If any entries are evicted f
> Does it make sense to optimize for the case when the entry is already in th
I thought about this as well, the reason I called both Lookup methods was to update the lookup metrics for both segments. I guess I could simply call UpdateLookupMetrics for the probationary shard before returning the protected segment handle. That would help increase the concurrency too as less time would be spent with the probationary shard locked.
The one drawback would this approach is we wouldn't be able to check the invariant that both segments shouldn't contain the same entry.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@595
PS12, Line 595:
> nit: isn't ?
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@596
PS12, Line 596:
> return the entry found in the probationary segment
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@596
PS12, Line 596:
> nit: the protected segment
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@608
PS12, Line 608: return probationary_handle;
> What if the entry that has just been inserted evicted right away with all t
So this would only happen in the case that the entry being upgraded is larger than the capacity limit of the protected segment IIUC. It would also be then be part of 'evictions' here and re-inserted into the probationary segment. There would be no way for this entry to be protected if its charge is larger than the capacity of the protected segment.
In this case, perhaps it would be better to check if the entry's charge is larger than the capacity before adding it to the segment as that would evict all the other entries from the protected segment for no reason. I didn't think about this edge case, thanks for bringing it up, I'll add a test case for it.
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@610
PS12, Line 610:
> nit: the protected segment
Done
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@612
PS12, Line 612: // Erase entry from the probationary segment th
> Could use reverse iterator instead of dancing with indices?
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 13
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 15 Feb 2024 23:12:50 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
Build Aborted
http://jenkins.kudu.apache.org/job/pre_commit/104/ : ABORTED
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Mon, 06 May 2024 11:16:21 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 16:
Build Aborted
http://jenkins.kudu.apache.org/job/pre_commit/99/ : ABORTED
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 16
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Sun, 05 May 2024 20:18:34 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 17:
(1 comment)
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/17/src/kudu/util/cache.h@520
PS17, Line 520: // Returns true if probationary segment contains key.
: // Returns false if not.
: // Only used for SLRU cache.
: virtual bool ProbationaryContains(const Slice& key) = 0;
:
: // Returns true if protected segment contains key.
: // Returns false if not.
: // Only used for SLRU cache.
: virtual bool ProtectedContains(const Slice& key) = 0;
> Similar to SetSegmentMetrics(), this doesn't seem to be a place for these m
SLRUCacheShard is the right place for these, even without any extras, I don't see any reason to keep these specific methods in this generic interface (but I might be missing something).
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 17
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Fri, 10 May 2024 20:57:44 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 15:
(6 comments)
http://gerrit.cloudera.org:8080/#/c/20607/14//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/14//COMMIT_MSG@21
PS14, Line 21: Here are some benchmark numbers for SLRU cache:
: Test case | A
> Do I understand correctly that this is still a WIP patch, i.e. do you plan
It's no longer a WIP patch. The performance related tests are now added to this patch.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/cache.h@228
PS14, Line 228: // ensure this is safe, e.g. by destructing the entity that owned the
: // original metrics.
: kReset,
: };
: // Set the cache metrics to update corresponding counters accordingly.
: virtual void SetMetrics(std::unique_ptr<CacheMetrics> metrics,
: ExistingMetricsPolicy metrics_policy) = 0;
:
: // Sets probationary and protected segments metrics to update corresponding counters accordingly.
: //
: // An upgrade of one entry will increment the number of evictions from the probationary segment by
: // one and the number of insertions into the protected segment by one.
: //
: // A downgrade of one entry will increment the number of evictions from the protected segment by
: // one and the number of insertions into the probationary segment by one.
: //
: // To calculate the number of inserts for the SLRU cache, subtract the number of evictions
: // of the protected segment from the number of inserts of the probationary segment.
: //
> I'm not sure I understand the premise of introducing this method in the bas
This will be used in the block cache to set the metrics for both segments of the SLRU cache.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h@35
PS14, Line 35: Creates a new SLRU cache with 'probationary_capacity' being the capacity of
: // the probationary segment in bytes, 'protected_capacity' being the
> Is the capacity in bytes, kBytes, number of entries in the cache? It would
Done
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.h@40
PS14, Line 40: Cache
> Why not to return this as ShardedSLRUCache*?
The ShardedSLRUCache is local to the slru_cache.cc file. But for the logic in the patch that integrates this cache into the block_cache it's easier to return a Cache as the previous LRU implementation does too.
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.cc@62
PS14, Line 62: capacity()
> nit: capacity
Done
http://gerrit.cloudera.org:8080/#/c/20607/14/src/kudu/util/slru_cache.cc@131
PS14, Line 131: const size_t capa
> Could this be 'const'?
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 15
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 02 May 2024 20:49:33 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#8).
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
KUDU-613: Scan Resistant Caching
This patch introduces the SLRU cache that has two internal segments,
the probationary and protected, to protect the cache from long/random
reads. The SLRU cache has a parameter named 'lookups_threshold_' that
determines the minimum amount of times an entry can be accessed
before it's upgraded to the protected segment. Any random scans would
then only evict entries from the probationary segment.
Both the protected and probationary segment have their own
configurable capacities. When the protected segment is at capacity,
any entries evicted will be added to the MRU end of the
probationary segment.
TODO:
- Add performance tests
- Use SLRU cache in BlockCache
- Write a similar cache for NVM memory
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/block_cache_metrics.cc
M src/kudu/util/block_cache_metrics.h
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache-test.cc
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
10 files changed, 1,826 insertions(+), 228 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/8
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 8
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Scan Resistant Caching
Posted by "Marton Greber (Code Review)" <ge...@cloudera.org>.
Marton Greber has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Scan Resistant Caching
......................................................................
Patch Set 8:
(2 comments)
+1 on what Alexey was proposing, spliting up the changelist into smaller chunks.
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/block_cache_metrics.h
File src/kudu/util/block_cache_metrics.h:
PS8:
> Why is it necessary to update the block cache metrics in the same changelis
+1
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/cache.h
File src/kudu/util/cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/cache.h@67
PS8, Line 67: // Recency list cache implementations (FIFO, LRU, etc.)
> Is it possible to separate out this and other refactoring (i.e. moving dupl
+1
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 8
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 06 Feb 2024 13:21:02 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 8:
(2 comments)
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/10/src/kudu/util/slru_cache.h@136
PS10, Line 136: // Returns the lookup handle of entry from probationary segment, same entry is moved to
It would be great to document the parameters of this NewSLRUCache() function, in particular, it's not exactly clear what 'lookups' might be necessary for if somebody is looking at this function the very first time.
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/8/src/kudu/util/slru_cache.h@50
PS8, Line 50: class HandleDeleter {
: public:
: explicit HandleDeleter(SLRUCache* c)
: : c_(c) {
: }
:
: void operator()(Handle* h) const {
: if (h != nullptr) {
: c_->Release(h);
: }
: }
:
: SLRUCache* cache() const {
: return c_;
: }
:
: private:
: SLRUCache* c_;
: };
> I did so, but for any uses of this templatized class both Free() and Releas
I guess that's OK.
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 8
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Thu, 08 Feb 2024 05:57:37 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Abhishek Chennaka (Code Review)" <ge...@cloudera.org>.
Abhishek Chennaka has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 12:
(2 comments)
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.h@89
PS12, Line 89: probationary segment
nit: Maybe add the reasoning why the handle to probationary segments is returned and not the protected segment where it is inserted?
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/12/src/kudu/util/slru_cache.cc@590
PS12, Line 590: if ((!protected_handle && !probationary_handle) || protected_handle) {
: return protected_handle;
: }
If the entry is not present in both the segments, don't we insert the entry into probationary segment? So I believe returning probationary handle is what should be done here?
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 12
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 14 Feb 2024 23:00:09 +0000
Gerrit-HasComments: Yes
[kudu-CR] WIP KUDU-613: Scan Resistant Caching
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Alexey Serbin, Kudu Jenkins,
I'd like you to reexamine a change. Please visit
http://gerrit.cloudera.org:8080/20607
to look at the new patch set (#4).
Change subject: WIP KUDU-613: Scan Resistant Caching
......................................................................
WIP KUDU-613: Scan Resistant Caching
This patch introduces a new class, the SLRU cache with two segments,
the probationary and protected, to protect the cache from long/random
reads.
Looking for feedback on general approach for implementation so far.
TODO:
- Add tests
- Add metrics on SLRU cache level, both segments already have their
own metrics
- Use SLRU cache in BlockCache
Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
---
M src/kudu/util/CMakeLists.txt
M src/kudu/util/cache.cc
M src/kudu/util/cache.h
M src/kudu/util/nvm_cache.cc
M src/kudu/util/nvm_cache.h
A src/kudu/util/slru_cache.cc
A src/kudu/util/slru_cache.h
7 files changed, 575 insertions(+), 157 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/07/20607/4
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 4
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Tidy Bot (241)
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 20: Code-Review+1
(4 comments)
Almost there.
Just a few nits.
http://gerrit.cloudera.org:8080/#/c/20607/20//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/20//COMMIT_MSG@23
PS20, Line 23: Ran cache benchmarks for RELEASE build
nit: please also note whether you were using the default flag settings or there were any custom settings
http://gerrit.cloudera.org:8080/#/c/20607/20//COMMIT_MSG@25
PS20, Line 25: Here are some benchmark numbers for SLRU cache:
It would be great to add a few patterns into the cache-bench.cc that clearly show the benefits of using the SLRU cache. The very obvious one is something like multiple requests to many relatively small values, sprinkled with once-at-a-time requests for relatively large values that push out many elements out of the LRU, but not from the SLRU cache.
Otherwise, without presenting the actual hit ratio as an evidence, it's a hard call to sell the idea of using this SLRU implementation vs the LRU one if the former shows worse characteristics in both the lookup rate and hit ratio for all the benchmarked patterns (0.4% hit ratio gain vs LRU for
ZIPFIAN ratio=1.00x looks like an aberration).
Probably, adding that in a separate patch is a good option. If you have capacity to do so in this patch, that would be even better.
Thanks!
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/cache-bench.cc
File src/kudu/util/cache-bench.cc:
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/cache-bench.cc@60
PS20, Line 60: 5
nit: did you experiment with other settings for the protected segment lookup threshold? I guess the hit ratio of the SLRU vs LRU might improve a bit for the uniformly distributed keys if using 2 or 3 for the threshold setting
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/20/src/kudu/util/slru_cache.cc@400
PS20, Line 400: ShardedSLRUCache::~ShardedSLRUCache() { };
nit: this could be replaced with the following in the header file
~ShardedSLRUCache() = default;
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 20
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Wed, 05 Jun 2024 23:48:55 +0000
Gerrit-HasComments: Yes
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Kudu Jenkins (Code Review)" <ge...@cloudera.org>.
Kudu Jenkins has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 20: Verified-1
Build Failed
http://jenkins.kudu.apache.org/job/pre_commit/195/ : FAILURE
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 20
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 04 Jun 2024 21:11:41 +0000
Gerrit-HasComments: No
[kudu-CR] KUDU-613: Introduce SLRU cache
Posted by "Mahesh Reddy (Code Review)" <ge...@cloudera.org>.
Mahesh Reddy has posted comments on this change. ( http://gerrit.cloudera.org:8080/20607 )
Change subject: KUDU-613: Introduce SLRU cache
......................................................................
Patch Set 20:
(14 comments)
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG
Commit Message:
PS16:
> Don't forget to re-base this patch on top of the HEAD in the main branch, o
Done
http://gerrit.cloudera.org:8080/#/c/20607/16//COMMIT_MSG@22
PS16, Line 22:
> I guess it's not a big deal to build in RELEASE configuration and run the t
Done
http://gerrit.cloudera.org:8080/#/c/20607/19//COMMIT_MSG
Commit Message:
http://gerrit.cloudera.org:8080/#/c/20607/19//COMMIT_MSG@23
PS19, Line 23: Ran cache benchmarks for RELEASE build.
: Build ran locally on macOS, 6 cores and 2.6GHz.
> We need stats for RELEASE build, not DEBUG. Please add those when you have
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/cache-bench.cc
File src/kudu/util/cache-bench.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/cache-bench.cc@104
PS19, Line 104: / kEntrySize;
> I think this should have been (kProbationarySegmentCapacity + kProtectedSeg
Good catch. I was mistaken that max_key had to do with the entry size.
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/nvm_cache.cc
File src/kudu/util/nvm_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/nvm_cache.cc@556
PS19, Line 556: UniquePendingHandle Allocate(Slice key, int val_len, int charge) override {
> nit: why to change this at all?
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.h
File src/kudu/util/slru_cache.h:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.h@74
PS19, Line 74: // Removes entry from shard, frees the entry if no refs are remaining.
: void Erase(const Slice& key, uint32_t hash);
: // Like Erase, but underlying entry is not freed.
: // Necessary when upgrading entry to protected segment.
: void SoftErase(const Slice& key, uint32_t hash);
: // Returns true if shard contains entry, false if not.
: bool Contains(const Slice& key, uint32_t
> It seems the code evolved and these methods are now used only in tests. If
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.h@113
PS19, Line 113: cause the cache implementation is sharded, we do this tracking in a
> The name of the method already assumes this cannot be anything but Cache::E
Removed it. Only template parameter now is the MemoryType but even that will only be DRAM. What template parameters would you like to see here?
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc
File src/kudu/util/slru_cache.cc:
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@63
PS19, Line 63: RLHan
> nit for here and elsewhere in this file: maybe, add corresponding 'using' d
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@66
PS19, Line 66: if (Unref(e)) {
> For this and other methods that are specific to protected or probational se
Added it as a TODO for now, this is a good idea, thanks for the feedback.
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@231
PS19, Line 231: return reinterpret_cast<Handle*>(handle);
: }
> nit: could this be just
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@468
PS19, Line 468: int bits = PREDICT_FALSE(FLAGS_cache_force_single_shard) ?
: 0 : Bits::Log2Ceiling(base::NumCPUs());
: VLOG(1) << "Will use " << (1 << bits) << " shards for SLRU cache.";
: return bits;
: }
:
> After consideration, inserting MRU first seems counter-productive. For sim
Good catch, changed it to insert the LRU entries first. Also changed this same logic in SLRUCacheShardPair::Insert().
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@516
PS19, Line 516:
:
:
:
:
> nit: it could be
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@526
PS19, Line 526:
:
> Instead of doing this, maybe just switch the order of the 'shards_' and t
Done
http://gerrit.cloudera.org:8080/#/c/20607/19/src/kudu/util/slru_cache.cc@539
PS19, Line 539:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
> This and other methods below look to be exactly identical to the code in Sh
Done
--
To view, visit http://gerrit.cloudera.org:8080/20607
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I45531534a2049dd38c002f4dc7982df9fd46e0bb
Gerrit-Change-Number: 20607
Gerrit-PatchSet: 20
Gerrit-Owner: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Abhishek Chennaka <ac...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Mahesh Reddy <mr...@cloudera.com>
Gerrit-Reviewer: Marton Greber <gr...@gmail.com>
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Comment-Date: Tue, 04 Jun 2024 20:55:58 +0000
Gerrit-HasComments: Yes