Skip to main content

Python actor framework for heterogeneous computing.

Project description


Python actor framework for heterogeneous computing.

PyPI Latest Release Coverage Build Status License

What is actor

Writing parallel and distributed programs is often challenging and requires a lot of time to deal with concurrency issues. Actor model provides a high-level, scalable and robust abstraction for building distributed applications. It provides several benefits:

  • Scalability: Actors easily scale across nodes. The asynchronous, non-blocking nature of actors allows them to handle huge volumes of concurrent tasks efficiently.
  • Concurrency: The actor model abstracts over concurrency, allowing developers to avoid raw threads and locks.
  • Modularity: An actor system decomposes naturally into a collection of actors that can be understood independently. Actor logic is encapsulated within the actor itself.

Why Xoscar

Xoscar implements the actor model in Python and provides user-friendly APIs that offer significant benefits for building applications on heterogeneous hardware:

  • Abstraction over low-level communication details: Xoscar handles all communication between actors transparently, whether on CPUs, GPUs, or across nodes. Developers focus on application logic rather than managing hardware resources and optimizing data transfer.
  • Flexible actor models: Xoscar supports both stateful and stateless actors. Stateful actors ensure thread safety for concurrent systems while stateless actors can handle massive volumes of concurrent messages. Developers choose the appropriate actor model for their needs.
  • Batch method: Xoscar provides a batch interface to significantly improve call efficiency when an actor interface is invoked a large number of times.
  • Advanced debugging support: Xoscar can detect potential issues like deadlocks, long-running calls, and performance bottlenecks that would otherwise be nearly impossible to troubleshoot in a heterogeneous environment.
  • Automated recovery: If an actor fails for any reason, Xoscar will automatically restart it if you want. It can monitor actors and restart them upon failure, enabling fault-tolerant systems.

Overview

architecture.png Xoscar allows you to create multiple actor pools on each worker node, typically binding an actor pool to a CPU core or a GPU card. Xoscar provides allocation policies so that whenever an actor is created, it will be instantiated in the appropriate pool based on the specified policy.

When actors communicate, Xoscar will choose the optimal communication mechanism based on which pools the actors belong to. This allows Xoscar to optimize communication in heterogeneous environments with multiple processing units and accelerators.

Where to get it

PyPI

Binary installers for the latest released version are available at the Python Package Index (PyPI).

# PyPI
pip install xoscar

Build from source

The source code is currently hosted on GitHub at: https://github.com/xorbitsai/xoscar .

Building from source requires that you have cmake and gcc installed on your system.

  • cmake >= 3.11
  • gcc >= 8
# If you have never cloned xoscar before
git clone --recursive https://github.com/xorbitsai/xoscar.git
cd xoscar/python
pip install -e .

# If you have already cloned xoscar before
cd xoscar
git submodule init
git submodule update
cd python && pip install -e .

APIs

Here are basic APIs for Xoscar.

Define an actor

import xoscar as xo

# stateful actor, for stateless actor, inherit from xo.StatelessActor
class MyActor(xo.Actor):
    def __init__(self, *args, **kwargs):
        pass

    async def __post_create__(self):
        # called after created
        pass

    async def __pre_destroy__(self):
        # called before destroy
        pass

    def method_a(self, arg_1, arg_2, **kw_1):  # user-defined function
        pass

    async def method_b(self, arg_1, arg_2, **kw_1):  # user-defined async function
        pass

Create an actor

import xoscar as xo

actor_ref = await xo.create_actor(
    MyActor, 1, 2, a=1, b=2,
    address='<ip>:<port>', uid='UniqueActorName')

Get an actor reference

import xoscar as xo

actor_ref = await xo.actor_ref(address, actor_id)

Invoke a method

# send
await actor_ref.method_a.send(1, 2, a=1, b=2)
# equivalent to actor_ref.method_a.send
await actor_ref.method_a(1, 2, a=1, b=2)
# tell, it sends a message asynchronously and does not wait for a response.
await actor_ref.method_a.tell(1, 2, a=1, b=2)

Batch method

Xoscar provides a set of APIs to write batch methods. You can simply add a @extensible decorator to your actor method and create a batch version. All calls wrapped in a batch will be sent together, reducing possible RPC cost.

Define a batch method

import xoscar as xo

class ExampleActor(xo.Actor):
    @xo.extensible
    async def batch_method(self, a, b=None):
        pass

Xoscar also supports creating a batch version of the method:

class ExampleActor(xo.Actor):
    @xo.extensible
    async def batch_method(self, a, b=None):
        raise NotImplementedError  # this will redirect all requests to the batch version

    @batch_method.batch
    async def batch_method(self, args_list, kwargs_list):
        results = []
        for args, kwargs in zip(args_list, kwargs_list):
            a, b = self.batch_method.bind(*args, **kwargs)
            # process the request
            results.append(result)
        return results  # return a list of results

In a batch method, users can define how to more efficiently process a batch of requests.

Invoke a batch method

Calling batch methods is easy. You can use <method_name>.delay to make a batched call and use <method_name>.batch to send them:

ref = await xo.actor_ref(uid='ExampleActor', address='127.0.0.1:13425')
results = await ref.batch_method.batch(
    ref.batch_method.delay(10, b=20),
    ref.batch_method.delay(20),
)

License

Apache 2

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

xoscar-0.7.11.tar.gz (143.5 kB view details)

Uploaded Source

Built Distributions

xoscar-0.7.11-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

xoscar-0.7.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

xoscar-0.7.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

xoscar-0.7.11-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

xoscar-0.7.11-cp312-cp312-macosx_10_13_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

xoscar-0.7.11-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

xoscar-0.7.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

xoscar-0.7.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

xoscar-0.7.11-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

xoscar-0.7.11-cp311-cp311-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

xoscar-0.7.11-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

xoscar-0.7.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

xoscar-0.7.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

xoscar-0.7.11-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

xoscar-0.7.11-cp310-cp310-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

xoscar-0.7.11-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9Windows x86-64

xoscar-0.7.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

xoscar-0.7.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

xoscar-0.7.11-cp39-cp39-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

xoscar-0.7.11-cp39-cp39-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file xoscar-0.7.11.tar.gz.

File metadata

  • Download URL: xoscar-0.7.11.tar.gz
  • Upload date:
  • Size: 143.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for xoscar-0.7.11.tar.gz
Algorithm Hash digest
SHA256 cf22489cd1d3b0bd7fc8105123ea58bd5e837fd2c3da4b0424934e31254d02d7
MD5 ed30a56b96fc57fc87a5a4d9893809c1
BLAKE2b-256 989356003735b24ee5f128f03cbf5f941f80334734b5aa1936fc5f96eded2d73

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: xoscar-0.7.11-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for xoscar-0.7.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3698cbd91ec449872d17decfb18f22364b2c1b601991dbae1c0c4183e4daae51
MD5 6ca45cf214b65f8dfb7b6ba913f95900
BLAKE2b-256 1bc4fe13b0fbbdc29f3cff256d7492de7e487adb0752ea253e11c1c45b7b5622

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 462434bcbce2d2ec166a8c268c63399f3a2760d4f2e959ed4e39151bd634bae0
MD5 858b83be6423daec879bafa498a2b00b
BLAKE2b-256 6e14b551d2b7e3a93356250774bcb27b6dd3dca0ac1c03e2180f926c17275a4d

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 36899713fbc86365a91b4d428a248bd1c97219319e35bec879ecd3260c369fdf
MD5 7f80336667740ae14de1dd71e8f59675
BLAKE2b-256 fe4c4ff39738bce81ced31b70a81263f4761649ebdd84d621f700258bad82d84

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e649e19ffac05f3c42cec641c72e76aea20a6343c3c1aca329e08410c080f9ed
MD5 42dfedf901a052b2ea79e22df52c2ad6
BLAKE2b-256 71d95541e866e77947d38ef77d5444bdd12ac9ce1969c57ca4ed3a926f2264aa

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 8fceeaf500a07e2ccb486e01a7d2911e981a2811e1d549dd3b92d2ef6c85a16d
MD5 5c8da06c5f7a84b3b2ad9f96cc0195f2
BLAKE2b-256 2ad4aff79a52ba969cfae0fc9aa6e3738129b7906ff3177c49741617629738b1

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: xoscar-0.7.11-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for xoscar-0.7.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 aaa4c563ec884bc0a9f85de3449df6e40f9a263951f79c450a0fb2bf01126ef5
MD5 780f796dd14f03c3ae0bc79c3f3102dd
BLAKE2b-256 be263293a8f6badbd68fea7353cf70e122efefd9a97997b75b7ddf38a4a183ba

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c36bde723cc9b69670b9bbe9165ac73ffc85b446788bb1de38abfb87d5579fd
MD5 46f4b5575300f57ba5abdf535d34bd41
BLAKE2b-256 bc4932158622ec63c2053258d42e78a3b13d2b6a508e9e459fa1f9630bdc4931

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9f35a9458e7debe4cd50fed0bafcd660a6526d7f4a1d36a7fa412bf50bc8bade
MD5 fd272eca918cfc52c8014934885d5b2c
BLAKE2b-256 375157aac1b0ce3bd438df6f343a12346c8a74975de04c3660b49d752787aa32

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c90060dd6c3ef1a80c7395db6ff9f15405d31814d569f18c6e58951bc6e854d
MD5 4dcebf8e8404f94bd5ed3db2371cfc94
BLAKE2b-256 50196ab89b30fb72d683a9361916633fdefb479add5b7f0116d01e20f8cf0271

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0a314557e92ec2f38c0905a0a427768a8c5d6b209db4e550e0a5690d31fba5bf
MD5 aa7d3bb1713439c9b2f21c90751fdc1f
BLAKE2b-256 4d4553fe7e2afe9a8f6c8e0f6a826617aa51b4b317eab9e7f954d04231fa2977

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: xoscar-0.7.11-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for xoscar-0.7.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c49d108f42606bccec8b78b3697dd43016aef1f88a91ab41e6dd4a8864c0d9d1
MD5 f69f6eac107a9a0efa3fa7f69de8ad6d
BLAKE2b-256 41e7ae6ef96398d83d28add0c5d22baa5dc80172b1c6e28099cd2729a4709d89

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d120ad2b3ab7f37e6be79b3caa0e188c44ff7e1875ff0d5e0823d252c14fe70d
MD5 6f3d34393ff03e71cf4776a21b01f137
BLAKE2b-256 090cbb401bd5488b3cdbba8bcd969784bfda4b19e8ea86e3a3a42003f5c1e356

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4fc683f7e8dd46a99b7c375d84f16e35e3766203c3767fa7e1af2055c7cf856f
MD5 3201679f742f918343cdd7bb2abb6bdb
BLAKE2b-256 6541289ffd03340bb026ae824685ae2b21c13aa6295313c89003492f17e9b160

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b587d288800a5abdb4c12cad092009aedadd068e610eac58036edbddde3e82f
MD5 90496b1a00d1d90c80080237dbe984cc
BLAKE2b-256 4390f84be5890eb853813826cd09663e3568837f51dc0a597852caf2a1de1fe5

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e71a3455d4e1a82d7fb6af6cf07df3c3e4f70e78b4a1b2874a1562c511d4b61e
MD5 91e868bc4d995b53c73c9765dc51cdff
BLAKE2b-256 c7bdcf199d13ed0b7b35ba3679a17abda762a7edb21c2fbba0f7bb8957573534

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: xoscar-0.7.11-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for xoscar-0.7.11-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ae76ec0c81a6fd6f32ec37331902d2bf007217011c0ff50772017a987ae328b3
MD5 461449dea9908002919bf0e939d1b0cb
BLAKE2b-256 a5f1a33efd8babf9d4f59ad26e8c6f3aa6a7ed756c6ec19d5a18eaf04702154e

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb72265e8810071ea943e298755ece6223878a0e5e61a7ae429448a681be1a1a
MD5 e6ef426b08312d55871903c8a08c71bd
BLAKE2b-256 1a1faab575800e1a8eb5ae5ab60f5df261149f128ac669071853da72d72e0605

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c73db090922d1d3e98be43abd832fd2b6518ba6972e9a713b94be1f94993a83b
MD5 443fe62427e5f42800ff52dd31e8720c
BLAKE2b-256 3942802f4a8f4dea97da6d487f3b2e0f1e2e081046e24e79be46f3a9f44283f2

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d5afe80634d07e35b7272afbaddc59891b5b4bba718766b8ac7725f1eb03576
MD5 8efe9d4d2d953920782d7c05d1be5452
BLAKE2b-256 db3432e773fb1b32f439d9c43066d645063a76f7b256f36e17b343d4ad928a7c

See more details on using hashes here.

File details

Details for the file xoscar-0.7.11-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.7.11-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 40fa809cd84ad5f444f4ab72ed1e194d505f37d2e0fbef07ce1198abab8660a0
MD5 0764ad921d3595ea1333db8cae61bdd5
BLAKE2b-256 ae4880e426e2c615273814501086f6f1f9067ccc8b0ed74ed2fab962cf05b1d3

See more details on using hashes here.

Supported by

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