Python actor framework for heterogeneous computing.
Project description
Python actor framework for heterogeneous computing.
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
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
The source code is currently hosted on GitHub at: https://github.com/xorbitsai/xoscar
Binary installers for the latest released version are available at the Python Package Index (PyPI).
# PyPI
pip install xoscar
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for xoscar-0.0.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90a05e78ab38e56b4a4966959a058a13b9d1eb7aa6ae9663030debe6e9cc9c63 |
|
MD5 | 5881e32352247bb907f17710eb6752b4 |
|
BLAKE2b-256 | 39ee0ab0c54f4973ce0199dbab5f603e69e56c075e18af74d696bcf90c7e99f4 |
Hashes for xoscar-0.0.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23d2fffbeee3ca04b77ab872d3ee4ddb50721b33844051b56f2b4f8685c9e60 |
|
MD5 | ad695e314018c4bd05821bf233038dc6 |
|
BLAKE2b-256 | cac9d494f562ad880a98f8ee0df55d0290a4059c7d6512a2fa5117fe749c1f69 |
Hashes for xoscar-0.0.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf80954043e23ebe19f949ef29a88f50c9c7364483d0e1750cae90b087e46a3f |
|
MD5 | 06c41677f37fbfbeb38f09e9858d0f27 |
|
BLAKE2b-256 | 7c7fc9c3afa168610bfb55b397cb2b070548f9b5f6a26f72737f0c02294af4cd |
Hashes for xoscar-0.0.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47efeab84df77e57482efd7a487a6b21f2534a70095e7af139771c22c3c80fed |
|
MD5 | 0f7b16c5261a7077cd181aa078e95e09 |
|
BLAKE2b-256 | 08a9c6b64df47c7d9c425c0b1e0e9a4235176207dd637b38ccac8dcce8f03545 |
Hashes for xoscar-0.0.8-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38f43c6903fa6b447c84268c70d1c5311374c2f1b7bcb0db030fb0d0df1eeddc |
|
MD5 | d29c10f97946dd1c5c86e36676e74ffa |
|
BLAKE2b-256 | cd6f9e5f79b07c67a2f49dcf6964ed3da5afc9f2047b2b039aa541c7d177b312 |
Hashes for xoscar-0.0.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b847dc56652f8ae6dd4c8737b331805ec7ad54b88e418f7dbd9691307c6ab0af |
|
MD5 | aafeba678b0a14b201d4ab2e3909e164 |
|
BLAKE2b-256 | f1b03502a657fe26da0aad27595062febde8f91faa10725094abe7eb8ebc0f29 |
Hashes for xoscar-0.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c63b6bcb88c970f51d843199bd2076739aab2afcaa46007b26097f1b59a70c8 |
|
MD5 | caa2f1106e6ca0d446f729440fa0a1e0 |
|
BLAKE2b-256 | 8e04b53df774eecc94da77ed2dcb29b85b686ff612a9a07f4ff33b496de74e8a |
Hashes for xoscar-0.0.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0989fc726f74631999b8dc490a6a2191dab789532f81625470bf53ef9c11f3ec |
|
MD5 | 74887aced298fde69664e0061a5ae97a |
|
BLAKE2b-256 | 3f6fd76a394b2487cdee462b5922cee16dcefe35df1afb187ef79359eef9f4a7 |
Hashes for xoscar-0.0.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4928914c97b985db2ef8c801c5fd506369b30e2fe9c20a4c92c25dadb4dd43a4 |
|
MD5 | bd7f0e498c07e874eb65934e36ce963b |
|
BLAKE2b-256 | 01b819dddb0deca9e19700431143fecb3faa7945fc990070baaf69c49ab2d060 |
Hashes for xoscar-0.0.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f88334d3892ea719ad1da39ddb20322d916326880bc34e9162a47da64f6f9029 |
|
MD5 | f3b5f88c82dc8a82dbc31814e41a0aca |
|
BLAKE2b-256 | 023042a17e73a539cccb4b7d15bafeda2471bd6a3b2e52bed1152ae9e3768a89 |
Hashes for xoscar-0.0.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df5b5440dbb10763ad0e271c73d98808f18295a34b14273f14c3d50b1d954850 |
|
MD5 | 3245f9d63ae38a2ab6d5627ec4856fac |
|
BLAKE2b-256 | f09b19a2db9c8906f8d82829357aab6d07d923fd2c86b0a7c1246929dafa0a4e |
Hashes for xoscar-0.0.8-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d191c089b16e5b0c897fdfe61f383cfdcab43456e95cf855e701bf39a30954b |
|
MD5 | 65975891f53dc2b5055d3c5909981aef |
|
BLAKE2b-256 | db0ace0005ca792788ee53044a9ae8f5156f09582b23d376421482a63fd334ed |
Hashes for xoscar-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b3668c0a006946ea9d91676e69c6897090c82f6a63fe21b87752063b7bc61a6 |
|
MD5 | c9e652f2e4ccc30e155c3ed2aad8ef90 |
|
BLAKE2b-256 | 4088700afeb9659dd281591e927e671d2fb5143610c746e8b06cd47cb012cdad |
Hashes for xoscar-0.0.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e7c22d6bfb1d57a5ea3a16c8ecafbf09bb62cfd2d93dfaf6cfad31cf30fe21 |
|
MD5 | 928d5f0a02361c8afdb3c3b9b8549026 |
|
BLAKE2b-256 | e95b0a3023ca5d56ea7a18f67f99f5cd2c99141ff180f564e684d13da387242c |
Hashes for xoscar-0.0.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55d7104efd81f8a41f23c6516a042c6ac8784a0b09dba359b5863dbbf393f4fa |
|
MD5 | 373f1c5e7ea17e8cf0c34dc015b5a3c3 |
|
BLAKE2b-256 | 0bdb6f01d2ee215897078ba2137d42cf7c042d40bd78d0d46d004d6c842785f0 |
Hashes for xoscar-0.0.8-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3ad0ed05e1dcd4abd09444866c6e021807361d3f7761854a906381e8ef0439a |
|
MD5 | a76f4f7c525f313bacd2b639e75b95c9 |
|
BLAKE2b-256 | 2ebafae0b688ac5c52e5f06c919f23d1d7909d405e9d750aafa2f1cc8c75145f |
Hashes for xoscar-0.0.8-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bf5b7e432593d6332bfff3fa9bfbac519ac0c4f4470edff87b41ffcd53e50dc |
|
MD5 | 46ef42be2d91c8fbbd54e3601a590d72 |
|
BLAKE2b-256 | 3883c1a33ab203a684d53d3f02b9848e506b422583d83f817f0d5955c209ae59 |
Hashes for xoscar-0.0.8-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc7f356f55e1a49bca80898191702ea2bdeec8a4a8c1d2b8f22c7cc827c15cf8 |
|
MD5 | e7877b048d3ecd79d84295e8772a356c |
|
BLAKE2b-256 | f16257f64d96ace7e5c229eb67f29f8bc0d56456b7533d7e0b7bdc01d584b6b8 |
Hashes for xoscar-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f8015da9f6da2b6f92968048efe6fd0e9184158fd90998af02b902aa2afff22 |
|
MD5 | d2d17ff1d5fa6bbc627beb0ff9ebe530 |
|
BLAKE2b-256 | cd554846e21be0d3185970feb62b4a2a8d8f2d7c6a9938fcaee76904459be4e3 |
Hashes for xoscar-0.0.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f21af05948ab247c6549646d74f7970c17612986925723d449f892e84685e6fa |
|
MD5 | cff283f75191aaa8f42a9541e54d0721 |
|
BLAKE2b-256 | 70941e7903de330346aba2e627047e491c87b8785ae8b363a6faa069c316b5a1 |
Hashes for xoscar-0.0.8-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f366a163adaa6f0bbfe86d0ef94a0c44614a9c53d70eeab7a3c70561ce3ef35 |
|
MD5 | 8a46baf37ea7f4efa278bbcdb9bc00e4 |
|
BLAKE2b-256 | c3d2277fc2bedaa8bef8ffa57b6ef3b44b17d6845b85b75e4a629b1a88a702b2 |
Hashes for xoscar-0.0.8-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a9c1925c46b51744c7a4dcff66bf5815dbe65c5d25c67f49953a52379a5af58 |
|
MD5 | 19ae7d3f590a9bf929b2c50986da20bb |
|
BLAKE2b-256 | 5f5b58ab4fb5ebe98b1bb3e65d870eb0e5dcd35570279d7f4ee51e43794ccf5b |