Skip to content

Commit e8d40c3

Browse files
committed
[RocksDB perf] Cache speedup
Summary: I have ran a get benchmark where all the data is in the cache and observed that most of the time is spent on waiting for lock in LRUCache. This is an effort to optimize LRUCache. Test Plan: The data was loaded with fillseq. Then, I ran a benchmark: /db_bench --db=/tmp/rocksdb_stat_bench --num=1000000 --benchmarks=readrandom --statistics=1 --use_existing_db=1 --threads=16 --disable_seek_compaction=1 --cache_size=20000000000 --cache_numshardbits=8 --table_cache_numshardbits=8 I ran the benchmark three times. Here are the results: AFTER THE PATCH: 798072, 803998, 811807 BEFORE THE PATCH: 782008, 815593, 763017 Reviewers: dhruba, haobo, kailiu Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D14571
1 parent 5e4ab76 commit e8d40c3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

util/cache.cc

+13-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <assert.h>
1111
#include <stdio.h>
1212
#include <stdlib.h>
13-
#include <list>
13+
#include <vector>
1414

1515
#include "rocksdb/cache.h"
1616
#include "port/port.h"
@@ -111,8 +111,8 @@ class HandleTable {
111111
}
112112

113113
void Resize() {
114-
uint32_t new_length = 4;
115-
while (new_length < elems_) {
114+
uint32_t new_length = 16;
115+
while (new_length < elems_ * 1.5) {
116116
new_length *= 2;
117117
}
118118
LRUHandle** new_list = new LRUHandle*[new_length];
@@ -255,18 +255,20 @@ Cache::Handle* LRUCache::Insert(
255255

256256
LRUHandle* e = reinterpret_cast<LRUHandle*>(
257257
malloc(sizeof(LRUHandle)-1 + key.size()));
258-
std::list<LRUHandle*> last_reference_list;
258+
std::vector<LRUHandle*> last_reference_list;
259+
last_reference_list.reserve(1);
260+
261+
e->value = value;
262+
e->deleter = deleter;
263+
e->charge = charge;
264+
e->key_length = key.size();
265+
e->hash = hash;
266+
e->refs = 2; // One from LRUCache, one for the returned handle
267+
memcpy(e->key_data, key.data(), key.size());
259268

260269
{
261270
MutexLock l(&mutex_);
262271

263-
e->value = value;
264-
e->deleter = deleter;
265-
e->charge = charge;
266-
e->key_length = key.size();
267-
e->hash = hash;
268-
e->refs = 2; // One from LRUCache, one for the returned handle
269-
memcpy(e->key_data, key.data(), key.size());
270272
LRU_Append(e);
271273

272274
LRUHandle* old = table_.Insert(e);

0 commit comments

Comments
 (0)