我在django-storages
运行时遇到了使用 S3Boto 后端的内存泄漏问题default_storage.exists()
我在这里关注文档:http: //django-storages.readthedocs.org/en/latest/backends/amazon-S3.html
这是我的设置文件的相关部分:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
这是我重复这个问题的方法:
./manage.py shell
from django.core.files.storage import default_storage
# Check default storage is right
default_storage.connection
>>> S3Connection:s3.amazonaws.com
# Check I can write to a file
file = default_storage.open('storage_test_2014', 'w')
file.write("does this work?")
file.close()
file2 = default_storage.open('storage_test_2014', 'r')
file2.read()
>>> 'does this work?'
# Run the exists command
default_storage.exists("asdfjkl") # This file doesn't exist - but the same thing happens no matter what I put here - even if I put 'storage_test_2014'
# Memory usage of the python process creeps up over the next 45 seconds, until it nears 100%
# iPython shell then crashes
>>> Killed
我想到的唯一潜在问题是我的 S3 存储桶中有 93,000 个项目 - 我想知道 .exists 是否只是下载整个文件列表以进行检查?如果是这样的话,肯定还有别的办法吗?不幸的是 sorl-thumbnail 在生成新缩略图时使用了这个 .exists() 函数,这导致缩略图生成非常慢。