提交 2b4af919 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

LIRS cache: improved hit rate

上级 134a436d
...@@ -87,6 +87,9 @@ Change Log ...@@ -87,6 +87,9 @@ Change Log
when using larger databases and many threads. when using larger databases and many threads.
To re-enable, use the file name prefix "cache:". To re-enable, use the file name prefix "cache:".
</li> </li>
<li>LIRS cache: improved hit rate because now added entries get hot if they
were in the non-resident part of the cache before.
</li>
</ul> </ul>
<h2>Version 1.4.192 Beta (2016-05-26)</h2> <h2>Version 1.4.192 Beta (2016-05-26)</h2>
......
...@@ -791,9 +791,12 @@ public class CacheLongKeyLIRS<V> { ...@@ -791,9 +791,12 @@ public class CacheLongKeyLIRS<V> {
} }
V old; V old;
Entry<V> e = find(key, hash); Entry<V> e = find(key, hash);
boolean existed;
if (e == null) { if (e == null) {
existed = false;
old = null; old = null;
} else { } else {
existed = true;
old = e.value; old = e.value;
remove(key, hash); remove(key, hash);
} }
...@@ -822,6 +825,10 @@ public class CacheLongKeyLIRS<V> { ...@@ -822,6 +825,10 @@ public class CacheLongKeyLIRS<V> {
mapSize++; mapSize++;
// added entries are always added to the stack // added entries are always added to the stack
addToStack(e); addToStack(e);
if (existed) {
// if it was there before (even non-resident), it becomes hot
access(key, hash);
}
return old; return old;
} }
......
...@@ -225,8 +225,9 @@ public class TestCacheLongKeyLIRS extends TestBase { ...@@ -225,8 +225,9 @@ public class TestCacheLongKeyLIRS extends TestBase {
test.put(5, 50); test.put(5, 50);
assertTrue(test.containsValue(50)); assertTrue(test.containsValue(50));
verify(test, "mem: 4 stack: 5 4 3 2 cold: 5 non-resident: 1"); verify(test, "mem: 4 stack: 5 4 3 2 cold: 5 non-resident: 1");
// 1 was non-resident, so this should make it hot
test.put(1, 10); test.put(1, 10);
verify(test, "mem: 4 stack: 1 5 4 3 2 cold: 1 non-resident: 5"); verify(test, "mem: 4 stack: 1 5 4 3 cold: 2 non-resident: 5");
assertFalse(test.containsValue(50)); assertFalse(test.containsValue(50));
test.remove(2); test.remove(2);
test.remove(3); test.remove(3);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论