Skip to content

Latest commit

 

History

History
37 lines (22 loc) · 625 Bytes

README.rst

File metadata and controls

37 lines (22 loc) · 625 Bytes

Flask-TrafficShape

对flask 单个请求进行流量整形,支持漏桶算法和令牌桶算法

# coding=utf-8
from flask import Flask
import hibiscus_traffic

app = Flask(__name__)


@app.route('/')
@hibiscus_traffic.tokenbucket(rate=2, default=5)
def hello_world():
    return 'Hello World!'


@app.route('/test')
@hibiscus_traffic.leakbucket(rate=3, default=20)
def hello():
    return 'hello test'


if __name__ == '__main__':
    app.run(port=8070, debug=True)