Skip to content

Commit

Permalink
Make it possible to configure generation sizes.
Browse files Browse the repository at this point in the history
Document some more info about the types of the workloads and how they
respond to generation sizes.
  • Loading branch information
jamadden committed Sep 24, 2016
1 parent ae2c58a commit 47cb68b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion relstorage/cache/local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class LocalClient(object):
b'.b': bz2.decompress
}

_bucket_type = LocalClientBucket

def __init__(self, options, prefix=None):
self._lock = threading.Lock()
self.options = options
Expand Down Expand Up @@ -87,7 +89,7 @@ def _bucket0(self):

def flush_all(self):
with self._lock:
self.__bucket = LocalClientBucket(self._bucket_limit)
self.__bucket = self._bucket_type(self._bucket_limit)
options = self.options
if options.cache_local_dir:
_Loader.load_local_cache(options, self.prefix, self._bucket0)
Expand Down
4 changes: 2 additions & 2 deletions relstorage/cache/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SizedLRUMapping(object):
# When did we last age?
_aged_at = 0


_cache_type = Cache

def __init__(self, limit):
# We experimented with using OOBTree and LOBTree
Expand All @@ -67,7 +67,7 @@ def __init__(self, limit):
# large BTrees, but since that's not the case, we abandoned the idea.

# This holds all the ring entries, no matter which ring they are in.
cache = self._cache = Cache(limit)
cache = self._cache = self._cache_type(limit)
self._dict = cache.data


Expand Down
12 changes: 12 additions & 0 deletions relstorage/cache/micro_benchmark_results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ web07 76,118 20,484 53,283 22,835 8
web12 95,607 13,756 66,925 28,682 8
========== ========== ======== ========= ========== ====

Note that Financial1 and Financial2 are OLTP traces of a journal file,
and orm-busy and orm-night are traces of an ORM session cache with
short transactions. Both of these are dominated by *recency* and are
thus very easy for LRU caches; a frequency cache like the new code has
more trouble with them at smaller sizes. They are included to
demonstrate worst-case performance and are probably not representative
of typical RelStorage cache workloads (a RelStorage workload will have
some objects, such as catalog BTree objects, that are frequently
accessed which shouldn't be ejected if a more rare query occurs).
The hit rates of these workloads are strongly correlated to the size
of the eden generation.

Cache simulation
----------------

Expand Down
20 changes: 17 additions & 3 deletions relstorage/cache/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
from relstorage.tests.util import skipOnCI
from functools import partial

from relstorage.cache.cache_ring import Cache as _BaseCache
class Cache(_BaseCache):
# Tweak the generation sizes to match what we developed the tests with
_gen_protected_pct = 0.8
_gen_eden_pct = 0.1

from relstorage.cache.mapping import SizedLRUMapping as _BaseSizedLRUMapping

class SizedLRUMapping(_BaseSizedLRUMapping):
_cache_type = Cache

from relstorage.cache.local_client import LocalClient as _BaseLocalClient

class LocalClient(_BaseLocalClient):
_bucket_type = SizedLRUMapping


class StorageCacheTests(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -386,7 +403,6 @@ def assertNotNone(self, o):
raise AssertionError("Expected not None")

def getClass(self):
from relstorage.cache.mapping import SizedLRUMapping
return SizedLRUMapping

def test_age_empty(self):
Expand Down Expand Up @@ -738,7 +754,6 @@ def test_load_from_multiple_files_hit_limit(self):
class LocalClientTests(unittest.TestCase):

def getClass(self):
from relstorage.cache.local_client import LocalClient
return LocalClient

def _makeOne(self, **kw):
Expand Down Expand Up @@ -1123,7 +1138,6 @@ def test_bool(self):
self.assertFalse(lru)

def test_free_reuse(self):
from relstorage.cache.cache_ring import Cache
cache = Cache(20)
lru = cache.protected
self.assertEqual(lru.limit, 16)
Expand Down

0 comments on commit 47cb68b

Please sign in to comment.