如何在ZODB中设置缓存大小?

2024-09-30 20:38:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我用以下代码建立ZODB连接:

connection = ZODB.connection('zodb/connect4_reinf.fs')
dbroot = connection.root()

如何设置RAM缓存大小?在


Tags: 代码rootconnectionfsramzodbconnect4dbroot
2条回答

来自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):

ZODB.connection定义如下:

^{pr2}$

我会说

   connection = ZODB.connection('zodb/connect4_reinf.fs',
        cache_size=<your-cache-size>)

如果您希望限制为(估计的)字节,那么还有一个缓存大小字节。0表示此参数无限制。在

关于缓存大小和缓存大小字节之间的连接 (我将此贴出来作为答案,因为评论有点简短)

这次,我们可以在picklecache.py,同样在源代码中。重命名之后,可以归结为以下几行(在method\u 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)

这里的targetconnectioncache_size,以对象数表示,target_size_bytes是传递给connection的{},以字节为单位。因此,简而言之,如果cache_size_bytes求值为False(作为默认值0,也可以是{},等等),那么只考虑对象的数量。如果cache_size_bytes存在,则cache_size和{}都要考虑在内,并且这两个条件都必须适用,即当一个对象必须被放入缓存时,如果添加将导致超过cache_size个活对象超过cache_size_bytes字节(估计值),某些对象将从缓存中删除以释放更多可用空间。在

相关问题 更多 >