Skip to main content

Async decentralized actor

Project description

AsyncActor is an async Python module that aids in service discovery and “somewhat-leader” election in a heterogenous, sometimes-disconnected network.

AsyncActor can run on top of any reliable broadcast channel. This version includes back-ends for Serf and MQTT.

AsyncActor sends as few packets as possible, thus is well-suited for IoT-related applications with many stations but limited bandwidth.

Theory of operation

Assume that you have a non-lossy network with a bounded latency (let’s assume one second). Assume further that you’d like to know within ten seconds whether your node is still online.

AsyncActor sends one beacon message every seven to nine seconds. The message includes a list of N previous hosts that have transmitted the beacon; the host that’s last in this list will be the next transmitter.

The time slot starting at the seven-second mark is used for random hosts which would like to enter the beacon sending business. This is somewhat likely if the list of hosts is currently smaller than N. The slot at eight seconds is used for the hosts at the end of the list; the last host will send first, but if its beacon is not seen then the next-to-last will send its message, and so on.

The time slot at nine seconds is used for last-resort messages, i.e. any participating host can and will send its beacon message.

Collisions are resolved at the ten-second mark, i.e. the list of messages is ordered deterministically: the winner will announce to its clients that a new slot has started and whether all N host slots are filled.

It uses anyio <https://github.com/agronholm/anyio> as its underlying async framework.

PyPI latest version badge Code coverage badge

Installation

AsyncActor requires a back-end, i.e. either a running Serf agent or a MQTT broker.

To install AsyncActor, run the following command:

$ pip install asyncactor

or alternatively (you really should be using pip though):

$ easy_install asyncactor

or from source:

$ python setup.py install

Getting Started

These examples require a running async loop. Trio <https://github.com/python-trio/trio> is recommended, though asyncio works too.

from asyncactor import client as actor
from somewhere import some_transport

async with some_transport.connect('localhost') as t:
    async with actor(t, prefix=('actor','test')) as client:
        async for client.events as m:
            print(m)

Development

You can run the tests using the following commands:

$ serf agent & # start serf agent
$ mosquitto
$ python3 -mpytest tests

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

asyncactor-0.25.0.tar.gz (34.6 kB view details)

Uploaded Source

Built Distribution

asyncactor-0.25.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file asyncactor-0.25.0.tar.gz.

File metadata

  • Download URL: asyncactor-0.25.0.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for asyncactor-0.25.0.tar.gz
Algorithm Hash digest
SHA256 6751e2d646dfe7c83e17eb4f35a9bbc0a61e17ca7d2057e596f8ba01945248ec
MD5 bafb7a364f5a23329c79c30c235d4eb9
BLAKE2b-256 373fbf1ceab76cd7bde421f96286e24aa8c04a4202036dfcaca7c6f853a2e52b

See more details on using hashes here.

File details

Details for the file asyncactor-0.25.0-py3-none-any.whl.

File metadata

  • Download URL: asyncactor-0.25.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for asyncactor-0.25.0-py3-none-any.whl
Algorithm Hash digest
SHA256 957a1203763121eff5d470c3158798bbe78c3340dc5ad4d3ec0935fd8be65b56
MD5 148beabd7e66ccc5afb2b1a04581c75c
BLAKE2b-256 f5c19e1ad39462297b3c8ad11f3b0593eebbd6cb76af611819a81393068acf23

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