通过在服务器承受压力时自动将繁重的页面替换为静态页面来优雅地降级。
项目描述
Django 缩放器
通过在服务器承受压力时自动将繁重的页面替换为静态页面来优雅地降级。
<nav class="contents" id="contents">内容
</nav>安装
在 Python 路径中安装或添加django-scaler 。
将缩放器添加到您的INSTALLED_APPS设置。
将scaler.middleware.ScalerMiddleware添加到MIDDLEWARE_CLASSES设置的顶部。
添加 (r'^scaler/', include('scaler.urls')) 到 urlpatterns。
概述
由于各种原因,服务器有时可能会过载。当这种情况发生时,您不希望昂贵的请求破坏您的整个站点。当服务器处于负载状态时,站点必须将昂贵的请求重定向到“服务器繁忙”页面,然后在负载下降到足够多时自动删除重定向。
django-scaler以两种方式解决了这种情况。首先,它知道自己重定向哪些请求。其次,可以指示它重定向N个最昂贵的请求。它将响应时间数据存储在内存缓存中,使其能够做出这些决定。
用法
从test_settings.py粘贴:
DJANGO_SCALER = { 'server_busy_url_name': 'server-busy', # How many response times to consider for an URL. A small value means slow # response times are quickly acted upon, but it may be overly aggressive. # A large value means an URL must be slow for a number of requests before # it is acted upon. The default is 100. 'trend_size': 10, # How much slower than average the trend must be before redirection kicks # in. The default is 4.0. 'slow_threshold': 2.0, # How many seconds to keep redirecting an URL before serving normally. The # default is 60. 'redirect_for': 10, # A function that returns how many of the slowest URLs must be redirected. # Depending on the site, data and load on the server this may be a large # number. This allows external processes to instruct the middleware to # redirect. The default is 0. 'redirect_n_slowest_function': lambda: 0, # A function that returns what percentage of the slowest URLs must be # redirected. Depending on the site, data and load on the server this may # approach 100. The default is 0. 'redirect_percentage_slowest_function': lambda: 0, # A function that returns a list of regexes. URLs matching the regexes are # redirected. Each regex is a simple string. Do not prefix with r''. The # default is an empty list. 'redirect_regexes_function': lambda: [], }
变更日志
0.2
用于显式重定向的正则表达式 URL 匹配。
最慢显式重定向的百分比。
0.1
第一次发布。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
django-scaler-0.2.tar.gz
(8.7 kB
查看哈希)
内置发行版
django_scaler-0.2-py2.7.egg
(13.5 kB
查看哈希)
django_scaler-0.2-py2.6.egg
(13.6 kB
查看哈希)