当服务器处于紧张状态时,自动用静态页面替换较重的页面,从而优雅地降级。

django-scaler的Python项目详细描述


Django Scaler

在服务器处于紧张状态时自动用静态页替换重页,从而优雅地降级。

Installation

  1. 在python路径中安装或添加django-scaler
  2. scaler添加到INSTALLED_APPS设置中。
  3. scaler.middleware.ScalerMiddleware添加到MIDDLEWARE_CLASSES设置的顶部。
  4. 将(r“^scaler/”,include('scaler.url')添加到urlpatterns。

Overview

由于各种原因,服务器有时可能会过载。当那 碰巧你不想让昂贵的请求破坏你的整个网站。这个 站点必须将昂贵的请求重定向到“服务器忙”页,而服务器 处于加载状态,然后在加载后自动删除重定向 掉得够多了。

django-scaler用两种方式解决这种情况。首先,它知道 请求自行重定向。其次,可以指示它重新定向 n最昂贵的要求。它将响应时间数据存储在内存缓存中 使它能够做出这些决定。

Usage

粘贴自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: [],
}

Authors

praekelt基金会

  • 赫德利·鲁斯

Changelog

0.2

  1. 用于显式重定向的regex url匹配。
  2. 最慢显式重定向百分比。

0.1

  1. 第一次释放。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpring重定向请求处理程序   SwingJava:拆分字符串并将其放入文本区域的   Java:标记“”上出现语法错误,此标记后面应为表达式   web服务Java RestService从日志文件写入和读取数据   java如何将ArrayList<String>转换为char数组,然后向后打印每个单词?   java SimpleDataFormat解析返回年终日期   加密Java aes解密bytebuffer,包括填充为空字节   java有没有办法从特定的if语句调用变量?   java从更新返回到渲染   spring GRPC Java登录测试   java为什么下面的代码不工作(StringBuffer.toString!=null)   java是一种可行的模式吗?   使用Spring集成测试的JavaOSGi片段   java jCommander为未知和未使用的值引发异常?   在imageView的editText中输入的java图像URL