Reputation: 1377
I establish ZODB connection with the following code:
connection = ZODB.connection('zodb/connect4_reinf.fs')
dbroot = connection.root()
How can I set RAM cache size?
Upvotes: 1
Views: 456
Reputation: 194
Regarding the connection between cache_size and cache_size_bytes (I'm posting this as an answer, since comments are a bit short for this purpose)
This time, we can find the answer in picklecache.py, again in the source code. After some renaming, it boils down to the following lines (in method _sweep):
for value in self.ring:
if self.non_ghost_count <= target and (self.total_estimated_size <= target_size_bytes or not target_size_bytes):
break
(delete some objects from the cache)
here target
is the cache_size
of connection
, in number of objects, and target_size_bytes
is the cache_size_bytes
passed to connection
, in bytes. So in short, if cache_size_bytes
evals to False
(as the default value 0
, but also None
, etc...), only the number of objects is taken into account. If cache_size_bytes
is present, both cache_size
and cache_size_bytes
are taken into account, and both conditions must apply, that is when an object must be brought into the cache, if the addition will lead to have more than cache_size
living objects or more than cache_size_bytes
bytes (estimated), some object will be deleted from the cache to make more room available.
Upvotes: 0
Reputation: 194
From the source code of class DB:
def __init__(self, storage,
pool_size=7,
pool_timeout=1<<31,
cache_size=400,
cache_size_bytes=0,
historical_pool_size=3,
historical_cache_size=1000,
historical_cache_size_bytes=0,
historical_timeout=300,
database_name='unnamed',
databases=None,
xrefs=True,
large_record_size=1<<24,
**storage_args):
When ZODB.connection
is defined as follows:
def connection(*args, **kw):
return DB(*args, **kw).open_then_close_db_when_connection_closes()
I would say
connection = ZODB.connection('zodb/connect4_reinf.fs',
cache_size=<your-cache-size>)
Also there's a cache_size_bytes if you prefer the limit to be in (estimated) bytes. 0 means unlimited for this parameter.
Upvotes: 2