Skip to main content

Control function call speed ,support network mode by redis

Project description

# ControlSpeed
这项目是用来控制函数调用的频率, 不仅支持本地的同步线程模式, 而且支持分布式模式.

ControlSpeed(本地版)还不兼容多进程多线程的场景, 当然你可以用ControlSpeedNetwork分布式版解决. 缺点是每次访问都会有一次网络io消耗.

from controlspeed import ControlSpeed
@ControlSpeed(max_calls=10, period=1.0)
def do_something():

from controlspeed import ControlSpeed
rate = ControlSpeed(max_calls=10, period=1.0)
for i in range(100):
with rate:

from controlspeed import ControlSpeed
import time
def limited(until):
duration = int(round(until - time.time()))
print 'Speed limited, sleeping for %d seconds' % duration

rate = ControlSpeed(max_calls=2, period=3, callback=limited)
for i in range(3):
with rate:
print i

在2.1加入了分布式限频, 借助于redis实现.
import redis
redis_conn = redis.StrictRedis()
key = ''

@ControlSpeedNetwork(redis_conn, key, max_calls=10, period=3.0)
def do_something(args):
print args

for i in xrange(20):

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for controlspeed, version 2.3
Filename, size File type Python version Upload date Hashes
Filename, size controlspeed-2.3.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page