我制作了一个简单的文件服务器,可以在我的树莓派(1/2 gb RAM,1 个 CPU)上运行。它在 nginx(1 个工作人员)后面的 gunicorn(3 个工作人员)下运行。
我有一个奇怪的问题,当我尝试同时下载太多文件(比如 5 个)时,它们都会部分通过然后中止。django 服务器没有输出(我也使用开发服务器遇到了这个问题,这就是为什么它现在在 gunicorn 和 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 重定向和提供静态内容)。
任何人都知道如果我同时提出多个请求,为什么它会退出?