跳转到主要内容

当服务器承受压力时,自动用静态页面替换重页面,优雅降级。

项目描述

Django Scaler

当服务器承受压力时,自动用静态页面替换重页面,优雅降级。

安装

  1. django-scaler 安装或添加到您的Python路径。

  2. scaler 添加到您的 INSTALLED_APPS 设置。

  3. scaler.middleware.ScalerMiddleware 添加到您的 MIDDLEWARE_CLASSES 设置的顶部。

  4. 将 (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: [],
}

作者

Praekelt Foundation

  • Hedley Roos

变更日志

0.2

  1. 正则表达式URL匹配用于显式重定向。

  2. 最慢的显式重定向的百分比。

0.1

  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 查看哈希值)

上传时间

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面