受Hystrix启发的延迟和容错库。
项目描述
Pycopine是一个延迟和容错库,旨在隔离对远程系统、服务和第三方库的访问点,停止级联故障,并使在不可避免的故障中具有弹性的复杂分布式系统能够恢复。
如这段复制的文本所示,pycopine深受Hystrix的启发。
先决条件
Pycopine需要Python 3.2+,但将来可能回滚到2.7。
安装
Pycopine尚未发布。
(计划) 功能
检测和报告失败的服务。
在负载高时短路失败的服务以帮助它们恢复。
监控失败率和性能指标以检测瓶颈。
按需、在运行时、从任何地方管理线程池和队列大小。
… (更多待定)
示例
假设我们想要与一个缓慢、不可靠或两者兼而有之的远程服务进行通信
import time
import random
def crappy_service(input):
''' The most useless piece of code ever.'''
time.sleep(5)
if 'OK' != random.choice(['OK', 'OK', 'f**ck']):
raise RuntimeError('We broke something.')
return input
您可以向问题抛出大量的线程和try/except子句,并希望不会打破互联网。或者您可以使用pycopine
from pycopine import Command
class MyCommand(Command):
''' Does nothing with the input, but with style. '''
def run(self, input):
return crappy_service(input)
def fallback(self, input):
return input
# Run and wait for the result
result = MyCommand('input').result()
# Give up after 2 seconds
result = MyCommand('input').result(timeout=2)
# Fire and forget
MyCommand('input').submit()
# Do stuff in parallel
foo = MyCommand('input_a').submit()
bar = MyCommand('input_b').submit()
results = [foo.result(), bar.result()]
# Change your mind midway through
foobar = MyCommand('input').submit()
if foobar.wait(timeout=2):
result = foobar.reault()
else:
foobar.cancel(RuntimeError('No time for this sh**t'))
项目详情
关闭
pycopine-0.1.dev1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 622d9648f9a53ad278b68bf37006bddee404b81fde1df280ba2ce4f1f01d0de2 |
|
MD5 | be5f55087eba33fc51164b6b3e41c3c7 |
|
BLAKE2b-256 | 727eb55d00dc206c446c6559e6da14a37e179f015086445430ad536110ee156f |