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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11Windows x86-64

xoscar-0.3.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.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

xoscar-0.3.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.3.0-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

xoscar-0.3.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.3.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.3.0-cp310-cp310-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

xoscar-0.3.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.3.0-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9Windows x86-64

xoscar-0.3.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.3.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.3.0-cp39-cp39-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

xoscar-0.3.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.3.0-cp38-cp38-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.8Windows x86-64

xoscar-0.3.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.3.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.3.0-cp38-cp38-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

xoscar-0.3.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.3.0.tar.gz.

File metadata

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

File hashes

Hashes for xoscar-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aa04b6d3bbd470a8c9fe98704a636e7614c0b4d0f462470c0ba355f4193da8cf
MD5 84e9c33d770af75f9f719015053630ec
BLAKE2b-256 206b9e69ae616a7ff042bef159c6e9ed5b9ddb99c0eb203d2366a0bf95328fa2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.3.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/5.0.0 CPython/3.9.18

File hashes

Hashes for xoscar-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b84c66d6a9ca220835df4c342fc299a8acf08b5d92c3147bf0df90a9f927f175
MD5 adf6e86a098f9b48bffdd3760cfd0fb5
BLAKE2b-256 51b40f342feb15a8522979917a4e5b25e3e3c9127d6fd8d83e350f081fab0c0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c39bab7623222061203cee9853c8267b69b5c1838eef10b50485bdacc76ad48
MD5 9e6c20824671798eb84cfe8c48b389e5
BLAKE2b-256 8e0640593e95d52ca84e6abd428d8a53ffec0447ce13c621507d06d3b9eacbca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 38a9e013a8e9f4c9b9197a24f7e9a99817e82124a6aa1d7e57d577476b4c0296
MD5 d346ddfa2249b078e65909c8ed90a435
BLAKE2b-256 ab6a7bb79e6ba1d539e8ac7b1e257525ae8c7afb02d60ebd207402ddef77af4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cd5b16a6e0436c2d2e348b8e68376851f7042d4f868c3ed0536a31d9de04387e
MD5 184a7d2e653fb3061617527669cd95b0
BLAKE2b-256 c9ee61b808a7c03de16abd92947cf8b7326d336dbb5e1434227120d22686eafc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 78d7788b332e751cba7bb47ec5254be308f0b825ce4abd2ff7de5f5aa6710739
MD5 e543cf5cbd9fa4b50432cc0a25be83e9
BLAKE2b-256 a37b993b487b53f201bf12b11754ec7fd043aa776b8ac9334587931f468a7d3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.3.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/5.0.0 CPython/3.9.18

File hashes

Hashes for xoscar-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0097b762e752dee5bf74b6724a57aa5bd2534e1f63195f42082e2ba5b80ac094
MD5 ea2f1f0a50bc46e6440a145f61e00d1b
BLAKE2b-256 d56ca073d6a530c0fe449146de918593c7a6350851bd97267875e530edf12645

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d57a4042aed97b33cb7c7d0b5d20ecda60c84a8b005123e4d11eed508d459890
MD5 2a3a37263712358e24bbcd1de4dd89e0
BLAKE2b-256 b02e1f44131061fd26174a1d52c7c0255a7d24be077144b834f9c7191f790ce2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9217e988c558673b6af3df9084ed60854dd91cbc4e409e960d338025bd2474be
MD5 a60d15a9d207f4f6698048ac9f5bde88
BLAKE2b-256 91b7e2eaa132810fbd1418e6a5209004a22fee25c399875126e14ce30f301c09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a202e1d22860bdf97f518f5278338dc15bef26a30bb7ecad5d98d53efd8a5318
MD5 56a1c82e8b4a8429f183abab077b2cd3
BLAKE2b-256 55ca7245e1b9a820988741cffba27694892d0ffcb6daa759cd2778eb66fd3fb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 88cba411df1db367070904b9ac88ab38a1fe771464d529215988f2310698d735
MD5 5881699514f225945125053a3000b8bf
BLAKE2b-256 d46338c4d430fe9330f5106f0c93b3fff76e9e96d0e26f3ffcbf71a2a8602691

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.3.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/5.0.0 CPython/3.9.18

File hashes

Hashes for xoscar-0.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3f2c5e254b6cc80248b1a3aafdcf1058169ea5787cd3a46d011a0c53491a12c2
MD5 bb9a8e8853b4600050297d2f44b10d6b
BLAKE2b-256 0dce9d27e65cf79eabc7c01422fb04ce7491a9d97d2b41580e1add43b46b692d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83e0a389d6dc9dd7f9badec2b6b702b9b2b432055c3c79af03eddcf31bd3c6d9
MD5 7882deb4c68024f99290b99501844acd
BLAKE2b-256 37031fec76f615f9149c492287cb9b1e29e050210568a5dbff23cc03e1724de8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 39df0d540f2646c2d2531086e34bf9b671b171251777c8062127b468593af27c
MD5 762ec96ed61e67c6a8762cddc23cd3db
BLAKE2b-256 a6c7a963125394dbb05487f444e3b222250ddc1097a0eb9d3dcd2bd0b83f1554

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 93629a46428671bcb16c9668627b338fb8a6e2d52dd834ae75f306efa83ef6b6
MD5 412f17473fb8d7d17d1ec3eda0261da3
BLAKE2b-256 b46aa8f9b7e4bbafb3e8482c4b760eff6e6e587d3eff9a8871be4110bb170ccd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d83f4477fad6ddfc001e582e698c46542957fdfb85179f41f31a9d1b1183201a
MD5 de9f0b143cb8779e7b66926d932dec9f
BLAKE2b-256 dadc3aa1551bd3eec5d555827eb13f913c54c0ab7968ffdefa0ed34ef70c0c4e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xoscar-0.3.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/5.0.0 CPython/3.9.18

File hashes

Hashes for xoscar-0.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f444f12c77a690041e34e9f4c718e1524a104d41b95c4de171349de918f02e71
MD5 c31b611cc7a58b0f0412e26f6acb816b
BLAKE2b-256 eeb507ec3f911951a85cdc674c3d3c0a9654a41a1d7f3c9f3c2b2443b484eaf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ab1d082bdb998a1e90a73426186ba1f2539ea9a90ffa96d6ff015cbd0598e0a
MD5 2349bd791b74e7267563edcbee9c07c2
BLAKE2b-256 64edf41f4cfcaf3f3dd0000ec121e9ef2f2d07864417291e18078bce99b48c0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8466c1e0d36cac36302335449b1ff55b8fc5025343f059ba86e6bd2125692aad
MD5 c1016787987863bb650b2629f2bf31b7
BLAKE2b-256 7df5463f829605f34f07d39523f5fa5e40551920a08104f2ac17f5ac02a8aabc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b2ac924cfff3cc58d78c40ef232640b54ba711842163c8b0a7a4b438e39ae710
MD5 092320029be1607cd0956947a4acf39f
BLAKE2b-256 029f41faa4d09904a0f816ce53bc47fb2f8a394e4de4a85c238ee35742144bec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xoscar-0.3.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b9c187509e74d8af4425d84e45b0b5c7cacf7d875d651448ba995cccb06aca21
MD5 7d590785e05d43bebe2370b29a41687e
BLAKE2b-256 8045927a60a9c69dfbe6c13b7df8d13184c8b34a21aed6dde70870d84a9da71d

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