我有一个非常大的SQLite表,其中包含超过500,000行和约15列(主要是浮点数).我想将数据从SQLite数据库传输到Django应用程序(可以由许多RDBM支持,但以我的情况为Postgres).一切正常,但是随着迭代的进行,Python进程的内存使用量每秒跳2-3兆.我尝试使用“ del”在每次迭代结束时删除EVEMapDenormalize和row对象,但是膨胀仍在继续.这是摘录,有什么想法吗?
class Importer_mapDenormalize(SQLImporter):
def run_importer(self, conn):
c = conn.cursor()
for row in c.execute('select * from mapDenormalize'):
mapdenorm, created = EVEMapDenormalize.objects.get_or_create(id=row['itemID'])
mapdenorm.x = row['x']
mapdenorm.y = row['y']
mapdenorm.z = row['z']
if row['typeID']:
mapdenorm.type = EVEInventoryType.objects.get(id=row['typeID'])
if row['groupID']:
mapdenorm.group = EVEInventoryGroup.objects.get(id=row['groupID'])
if row['solarSystemID']:
mapdenorm.solar_system = EVESolarSystem.objects.get(id=row['solarSystemID'])
if row['constellationID']:
mapdenorm.constellation = EVEConstellation.objects.get(id=row['constellationID'])
if row['regionID']:
mapdenorm.region = EVERegion.objects.get(id=row['regionID'])
mapdenorm.save()
c.close()
我对用Django ORM包装此SQLite数据库完全不感兴趣.我真的很想弄清楚如何在不占用我所有RAM的情况下传输数据.
解决方法:
愚蠢的我,这是在Django FAQ中解决的.
在调试模式下需要清除数据库查询缓存.
from django import db
db.reset_queries()
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!