【发布时间】:2014-12-07 14:26:38
【问题描述】:
我需要帮助来减少此 python 脚本的 RAM 使用量:
tempproducts = TempProducts.objects.filter()
for url in tempproducts:
scrap_and_save_product(url.url,True,0)
scrap_and_save_product 是一个使用 BeautifulSoup 抓取数据并将其保存在数据库中的功能。
TempProducts 有大约 100,000 种产品
每 30 分钟 RAM 使用量增加约 50 MB
内存使用日志:
220.059 MB
271.594 MB
313.316 MB
355.492 MB
373.516 MB
402.266 MB
437.328 MB
470.746 MB
507.195 MB
543.059 MB
574.215 MB
614.906 MB
643.902 MB
742.559 MB
787.93 MB
823.988 MB
856.949 MB
896.645 MB
931.93 MB
964.68 MB
我如何才能准确地检查哪个数据结构占用了我的 RAM?如何减少 Python/Django 中的 RAM 使用量? ...更好地使用元组或列表?
【问题讨论】: