我有下面的代码是在一个大桌子试图环路(〜100K行;〜30GB)内存泄漏
def updateEmailsInLoop(cursor=None, stats={}):
BATCH_SIZE=10
try:
rawEmails, next_cursor, more = RawEmailModel.query().fetch_page(BATCH_SIZE, start_cursor=cursor)
for index, rawEmail in enumerate(rawEmails):
stats = process_stats(rawEmail, stats)
i = 0
while more and next_cursor:
rawEmails, next_cursor, more = RawEmailModel.query().fetch_page(BATCH_SIZE, start_cursor=next_cursor)
for index, rawEmail in enumerate(rawEmails):
stats = process_stats(rawEmail, stats)
i = (i + 1) %100
if i == 99:
logging.info("foobar: Finished 100 more %s", str(stats))
write_stats(stats)
except DeadlineExceededError:
logging.info("foobar: Deadline exceeded")
for index, rawEmail in enumerate(rawEmails[index:], start=index):
stats = process_stats(rawEmail, stats)
if more and next_cursor:
deferred.defer(updateEmailsInLoop, cursor = next_cursor, stats=stats, _queue="adminStats")
不过,我不断收到以下错误:
在处理此请求时,处理此请求的进程被发现使用的内存过多并被终止。这很可能会导致下一个请求应用程序使用新的进程。如果您经常看到此消息,那么您的应用程序中可能会有内存泄漏。
...有时....
超出软私有内存128 MB与154 MB服务9个请求总
我改变了我的代码,所以我总是只在10后拉限在任何特定时间的参赛作品,所以我不明白为什么我还在用完内存?
进程统计信息做什么,可能是内存使用的来源。尽管t只能在dev中运行,但您也可能想看看Apptrace。 https://code.google.com/p/apptrace/ – 2015-05-07 11:26:13
你也可以看到在离开该函数之前调用gc.collect是否会回收任何内存。 – 2015-05-07 11:27:07