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.2.0.tar.gz (125.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded CPython 3.11Windows x86-64

xoscar-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

xoscar-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

xoscar-0.2.0-cp311-cp311-macosx_10_9_universal2.whl (2.1 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

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

Uploaded CPython 3.10Windows x86-64

xoscar-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

xoscar-0.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

xoscar-0.2.0-cp310-cp310-macosx_10_9_universal2.whl (2.1 MB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

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

Uploaded CPython 3.9Windows x86-64

xoscar-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

xoscar-0.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.9macOS 10.9+ x86-64

xoscar-0.2.0-cp39-cp39-macosx_10_9_universal2.whl (2.1 MB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

xoscar-0.2.0-cp38-cp38-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.8Windows x86-64

xoscar-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

xoscar-0.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

xoscar-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

xoscar-0.2.0-cp38-cp38-macosx_10_9_universal2.whl (2.1 MB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: xoscar-0.2.0.tar.gz
  • Upload date:
  • Size: 125.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for xoscar-0.2.0.tar.gz
Algorithm Hash digest
SHA256 46a7bde16748e6344fe024c5f540dfeb9730e9691dfd370fb4a164eb52114bcb
MD5 025276dbe1e888ea34c2d2b4f344c89c
BLAKE2b-256 e3574010465a059415964ce4d916b9948857eb64da77c4969fbfb5b171df375d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.2.0-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/4.0.2 CPython/3.9.18

File hashes

Hashes for xoscar-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a766cbbe4d490ed143fbf2ba6c485b6a027ebcc159c108cdf786ce23d0ba8217
MD5 a9185b32c3d0aed826435bf67243d46c
BLAKE2b-256 d0f6561ba9a1ab75f17dbb612000aad58bfa0efe8934144295e9286eee89c37d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9fd0b8e6ce994af25e4f7340804b82cdc4aae87c8da27f30e645488bf1dc505
MD5 088e5b7355ee1a2cafaa4e6d0f851cd7
BLAKE2b-256 f65ef361ecfe1e2aada245566a41e41cb2a04e61ff67fd5578dbe2622b07710e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 97a7a884032ce6f5de4fa0ed90fd6b30425cca052f9def74b7b5ca5f8a19874d
MD5 69c98949151bb6a2d0aebda1ccb144ba
BLAKE2b-256 d99e8234003a5f9249c691b9d719e99b696f5e8f7943417daf4e7aeab93fab93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4c30e53a2b9c5528aa22f315989692130434ce813201f0dd702f88aa5e22f7be
MD5 206c6766a6fbd3fa6e8d3fc2699624d9
BLAKE2b-256 43157ff5a1e60b318ab2a38b2b8f2d13af939ace9f7976e8a9b1d93ee4b1b130

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4d6bc2e03dafd4beac455857a1938830656e1626f9092d2c0f0dae0249c74db4
MD5 9de0c946f3a5e0bca6782709d97366fd
BLAKE2b-256 0c2c5b94b7002f81f56f876519bede587a192946895e66cd8276191063d2e6b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.2.0-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/4.0.2 CPython/3.9.18

File hashes

Hashes for xoscar-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f5f2d46f38be5968c4158685be9ee3505462878017fe32c649a3cab467c8b05a
MD5 020c82c75cc6efe04bdf9987c0574c49
BLAKE2b-256 212dd9a2fca2eda2d6fd5013bb1d479b0ea3102c1fda0a67c8727c60047dfe91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45939e2137bc81ec785998283f4bb6b6104694a2e152eb9abda3039d28931a61
MD5 243f8504a48674a07411da162b298096
BLAKE2b-256 6fbab1b849e663b0b61d01fc3c0f8e5c703c61a9ca40ce15a0b62ac77e2df5fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6b13948f7645ed8578d766c40742c2327b23df65ea48f8139e9c45f8c90249f7
MD5 314cb9fdc01e2f2fa207ba57bb2fe8a2
BLAKE2b-256 42a266b43794bb87988e1a8fbabbb884e980f87b8ad125ff37bec751fa9c541a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e0a24aed88153a53044bd26324b73abab9a789e80cd79a54da71cdfebcdc4492
MD5 90cb5d89aa8658491afb20ba77550b01
BLAKE2b-256 ad7b2361904b7bc6b0c32c11d296edc7d84fc87363f67e835b0a6e450eafae1b

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 793c1d85c68459e4abbf85f0f7bfb87aeb9da49f4e34b5db928288ea6fd5fd9e
MD5 629e850573ddb164bc9b039a4f12366e
BLAKE2b-256 04749221849bea33f2a29dbd446eae50c79a10bfc7c6146eef9a8ec6b5f949bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.2.0-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/4.0.2 CPython/3.9.18

File hashes

Hashes for xoscar-0.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 55c695dd3c6126a334948e1695f3d1ff9fc1fefcb3b5a87fe1866af1973b92c4
MD5 d2e99debc1b60980bec8bce57cba2ced
BLAKE2b-256 00dff4238617708128a88629b10c6c132b4cb4c5f524924d63e50ab34e181cea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b51af1fe212bf735d5ce178eafcf7cadd938ec704fba520026f6484b240dedba
MD5 cd214bc6b38540e9a85eabc93c6b7441
BLAKE2b-256 b81a18a9d1025c936cbcb94dfe9680fea106d9b3e48bf1fa5a0ee82292279c05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e265ed6882160cc2c4d8f53ef830843c7485a992e490a3bfdbdf2d2538f8c21a
MD5 2a9cd20f297e10844cc54c074679049a
BLAKE2b-256 216c94c0a93c12c7c182085a01d489cd40a4dea2915abe9dd6952cd76d052c17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 27c0a1c769a9206460b966e4b2aa3bb25448ddf5c9a464bd654b5b9a029e35d2
MD5 2c24d56bdbee47efb4de11e5f0fce9d2
BLAKE2b-256 2f0980a7cfe808910aa2429e39f18c4b6b93b91d1834a7d26a58d24d6f217dde

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e7068c83ad08359eef9b414f3b593850d832c8bd0813b60b440b01b21878d333
MD5 d52104323396b213e447fe520ff6b686
BLAKE2b-256 b0b98176ea7dc0c222534b603bd9374f1872c1f3b5eba27dc260750439e65636

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: xoscar-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for xoscar-0.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 cb3ab5ba2b4da6967036aaa9c0ada60fb79c5d9fc2f8e6d72ccf11d389137e3b
MD5 869c4095a0e27a06ef0cd18e187b6742
BLAKE2b-256 c9883ea049b60e11666322789586fc49fe7b5489dc8b1a21ab40998560a57e7b

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d6163fe4c5d81325b220972445b973bcd95efb2d08775cbaeb1429132e1733e
MD5 f7112ff4b925e932c9769ad25a4ed96d
BLAKE2b-256 07f068e76cd47a655bbafc1f0a92fd2019fb54bf52b31c82ae132b36fc3d5ed7

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2c665185ab89e5287ecb41be12703c37620eee0ea91579e21dc13a736feb0d2a
MD5 723b51854660b5302ce567222fad6639
BLAKE2b-256 ffe19a2ce343d493bacfcd33bf451c419ea62583ab795642216b4fc44960e9f4

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c753133147fd86914b5149a60b51f37fedcf7d440423184148d7ee114786c6f8
MD5 d28f2bef013273727ba7ef95957c21f5
BLAKE2b-256 9d85deb4ee8862e3c88bb35b9cf3ec2bce88d1c8c51f7b0ff30696fbbd02b141

See more details on using hashes here.

File details

Details for the file xoscar-0.2.0-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for xoscar-0.2.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1ef95706c29a9f55633f58a535a090bde1834f8dacd83ec7bc90360ae78d5052
MD5 9e0bb89abfc65506edddd92aa6b51fa0
BLAKE2b-256 e91e421a25319bfa18bed9d9b4b4e15aa6fef16796b188dd4b77a67d09bf9db0

See more details on using hashes here.

Supported by

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