跳转到主要内容

受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 (8.1 kB 查看哈希值)

上传时间: 源代码

支持者