我製作了一個簡單的文件服務器,運行在我的樹莓派(1/2 GB內存,1個CPU)上。它運行在nginx(1名工作人員)背後的gunicorn(3名工作人員)之下。Django:片狀文件下載
我有一個奇怪的問題,當我試圖同時下載太多的文件(比如5)時,他們都會部分通過,然後放棄。 django服務器沒有輸出(我也使用開發服務器來解決這個問題,這就是爲什麼它現在運行在nginx的後面,但仍然沒有喜悅)。
我下載的觀點是:
@never_cache
def download_media(request, user_id, session_key, id, filepath):
"Download an individual media file"
context = RequestContext(request)
# validate the user_id & session_key pair
if not __validate_session_key(user_id, session_key):
return HttpResponseRedirect(reverse('handle_logout'))
filepath = unicode(urllib.unquote(filepath))
if '..' in filepath:
raise SuspiciousOperation('Invalid characters in subdir parameter.')
location = MediaCollectionLocation.objects.get(id=id)
path = os.path.join(location.path, filepath)
response = HttpResponse(FileWrapper(file(path)), content_type='application/octet-stream')
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(path)
response['Content-Length'] = os.path.getsize(path)
response["Cache-Control"] = "no-cache, no-store, must-revalidate"
return response
我提供文件服務這種方式,因爲我希望客戶端進行身份驗證(所以不要只是想重定向和服務nginx的靜態內容)。
任何人都知道爲什麼它會退出,如果我並行發出幾個請求?
你有沒有試過在另一臺linux機器上運行這個腳本(即不是在你的樹莓派 - 大概運行raspbian)? – Hzmy 2013-02-24 23:04:10