Skip to main content

Latency and fault tolerance library inspired by Hystrix.

Project description

Pycopine is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.

As this copy-pasted text suggests, pycopine is heavily inspired by Hystrix.

Prerequisites

Pycopine requires Python 3.2+, but may be backportet to 2.7 in the future.

Installation

Pycopine is not released yet.

(Planned) Features

  • Detect and report failing services.

  • Short-circuit services that fail on high load to help them recover.

  • Monitor failure rates and performance metrics to detect bottlenecks.

  • Manage thread pool and queue sizes on demand, at runtime, from everywhere.

  • … (more to come)

Example

Lets say we want to speak to a remote service that is slow, unreliable or both:

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

You could throw lots of threads and try/except clauses at the problem and hope to not break the internet. Or you could use 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'))

Project details


Download files

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

Source Distribution

pycopine-0.1.dev1.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file pycopine-0.1.dev1.tar.gz.

File metadata

  • Download URL: pycopine-0.1.dev1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pycopine-0.1.dev1.tar.gz
Algorithm Hash digest
SHA256 622d9648f9a53ad278b68bf37006bddee404b81fde1df280ba2ce4f1f01d0de2
MD5 be5f55087eba33fc51164b6b3e41c3c7
BLAKE2b-256 727eb55d00dc206c446c6559e6da14a37e179f015086445430ad536110ee156f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page