我制作了一个简单的文件服务器,运行在我的树莓派(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