如何使用ZODB进行适当的内存管理? [英] How to do proper memory management with ZODB?

查看:74
本文介绍了如何使用ZODB进行适当的内存管理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了几本ZODB教程,但是我仍然不了解一件事:如何释放已经序列化(并提交)到(例如)FileStorage的内存?

I read several ZODB tutorials but here is one thing I still don't get: How do you free memory that is already serialized (and committed) to the (say) FileStorage?

更具体地说,我希望以下代码停止消耗我的所有内存:

More specifically, I want the following code to stop eating all my memory:

for i in xrange(bignumber):
    iobtree[i]=Bigobject() # Bigobject is about 1Mb
    if(i%10==0): 
        transaction.commit() # or savepoint(True)
transaction.commit()

如何实现?是否可以释放iobtree存储的引用,并用按需访问的弱引用"代替它们?

How can this be achieved? Is it possible to release references stored by iobtree and replace them by 'weak references' that would be accessible on demand?

推荐答案

创建保存点并提交事务已经清除了很多内存.

Creating savepoints and commiting the transaction already clears a lot of you memory.

  • 您需要检查ZODB缓存参数设置为什么,并根据需要进行调整.缓存大小参数表示缓存的对象的数量,而不是字节,因此您必须根据对象的大小进行调整.

  • You'll need to check what your ZODB cache parameters are set to, and tune these as necessary. The cache size parameter indicates the number of objects cached, not bytes, so you'll have to adjust this based on the size of your objects.

您可以尝试在ZODB连接对象上调用.cacheMinimize(),这将显式停用缓存中所有未修改(或已提交)的对象.

You can try and call .cacheMinimize() on the ZODB connection object, this explicitly deactivates any unmodified (or already committed) objects in the cache.

除此之外,请注意,即使Python从内存中释放对象,操作系统也不会总是回收释放的内存,直到需要其他东西为止.操作系统报告的内存使用情况不一定反映Python进程的实际内存要求.

Other than that, do note that even when Python frees objects from memory, the OS doesn't always reclaim that freed memory until it is needed for something else. OS-reported memory usage doesn't necessarily reflect actual memory requirements for a Python process.

这篇关于如何使用ZODB进行适当的内存管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆