Django 용 ajax 파일 업 로더를 만들었지 만 업로드 된 각 파일은 개 (30-80MB)의 메모리를 차지하며, 그걸 풀어주는 것처럼 보입니다.파일 업 로더 (Django on Heroku)의 Ajax 구현시 메모리 누수
우리는 dyno 당 512MB의 메모리를 할당하는 Heroku를 사용 중이므로 빨리 메모리 초과 오류가 발생하기 시작합니다. 여기
는 요청을 처리 할 수있는 장고보기 코드 :if request.is_ajax():
# the file is stored raw in the request
upload = request
is_raw = True
try:
filename = request.GET[ 'add_image' ]
except KeyError:
return HttpResponseBadRequest("AJAX request not valid")
(fileBaseName, fileExtension)=os.path.splitext(filename)
uniquename = biz_id + "__" + get_a_uuid() + fileExtension
saved = save_upload(upload, uniquename, biz)
을 그리고 여기 save_upload 코드 :이 코드는 알렉스 KUHL와 천둥 토끼에 this post (감사에서 적응
try:
#BusinessImage is my Django model. It uses django-imagekit to processs
#the raw uploaded image into three sizes (plus the original)
bi = BusinessImage(name=uploaded.GET.get("name"), business=biz)
if not BusinessImage.objects.filter(business=biz).exists():
bi.primary_image = True
bi.original_image.save(filename,ContentFile(uploaded.read()))
except IOError:
# could not open the file most likely
return False
finally:
uploaded.close()
return True
).
메모리 문제가 django-imagekit과 관련이 있거나 파일을 제대로 닫지 않았다고 생각합니다. 그러나 확실하지 않습니다. 나는 정말 어떤 도움을 주셔서 감사합니다.
감사합니다.
클레이
저는 이것이 django-imagekit과 직접 관련이 있다고 생각하지 않습니다. 같은 js 코드를 기반으로하는 django-ajax-uploader에도 누수가 존재합니다. 참조 : https://github.com/GoodCloud/django-ajax-uploader/issues/12. –
@DirkEschler - 정말 감사합니다. Dirk. django-imagekit은 메모리 문제를 문서화하고 있지만 (https://github.com/jdriscoll/django-imagekit/issues/63 참조), 멀리 떨어진 곳으로 마이그레이션 한 후에도 문제가 있음을 발견했습니다. 귀하의 링크가 그것들을 설명합니다. 다시 한번 감사드립니다. –