Zero-copy shared memory IPC library for building complex streaming data pipelines capable of processing large datasets
Project description
MomentumX
MomentumX is a zero-copy shared memory IPC library for building complex streaming data pipelines capable of processing large datasets using Python.
Key Features:
- High-Throughput, Low Latency
- Supports streaming and synchronous modes for use within a wide variety of use cases.
- Bring your own encoding, or use raw binary data.
- Small footprint with zero dependencies.
- Sane data protections to ensure reliability of data in a cooperative computing environment.
- Pairs with other high-performance libraries, such as numpy and scipy, to support parallel processing of memory-intensive scientific data.
- Works on most modern versions of Linux using shared memory (via
/dev/shm
). - Seamlessly integrates into a Docker environment with minimal configuration, and readily enables lightweight container-to-container data sharing.
Examples:
Below are some simplified use cases for common MomentumX workflows. Consult the examples in the examples/
directory for additional details and implementation guidance.
Streaming Mode (e.g. lossy)
# Producer Process
import momentumx as mx
# Create a stream with a total capacity of 10MB
stream = mx.Producer('my_stream', buffer_size=int(1e6), buffer_count=10, sync=False)
# Write the series 0-9 repeatedly to a buffer 1000 times
for i in range(0, 1000):
buffer = stream.next_to_send()
buffer.write(f'{i % 10}'.encode('utf8')) # Note: writing to buffer via [<index>] and [<start_index>:<stop_index>] is also possible
buffer.send() # Note: call with .send(<num bytes>) if you want to explicitly control the data_size parameter, otherwise internal cursor will be used
# Consumer Process(es)
import momentumx as mx
stream = mx.Consumer('my_stream')
while stream.is_alive:
# Receive from the stream as long as the stream is available
buffer = stream.receive()
print(buffer[:buffer.data_size])
Syncronous Mode (e.g. lossless)
# Producer Process
import momentumx as mx
import threading
import signal
cancel_event = threading.Event()
signal.signal(signal.SIGINT, (lambda _sig, _frm: cancel_event.set()))
# Create a stream with a total capacity of 10MB
stream = mx.Producer('my_stream', buffer_size=int(1e6), buffer_count=10, sync=True) # NOTE: sync set to True
min_subscribers = 1
while stream.subscriber_count < min_subscribers:
print("waiting for subscriber(s)")
if cancel_event.wait(0.5):
break
print("All expected subscribers are ready")
# Write the series 0-999 to a consumer
for n in range(0, 1000):
if stream.subscriber_count == 0:
cancel_event.wait(0.5)
# Note: sending strings directly is possible via the send_string call
elif stream.send_string(str(n)):
print(f"Sent: {n}")
# Consumer Process(es)
import momentumx as mx
stream = mx.Consumer('my_stream')
while stream.is_alive:
# Note: receiving strings is possible as well via the receive_string call
print(f"Received: {stream.receive_string()}")
Numpy Integration
import momentumx as mx
import numpy as np
# Create a stream
stream = mx.Consumer('numpy_stream')
# Receive the next buffer (or if a producer, obtain the next_to_send buffer)
buffer = stream.receive()
# Create a numpy array directly from the memory without any copying
np_buff = np.frombuffer(buffer, dtype=uint8)
License
Captivation Software, LLC offers MomentumX under an Unlimited Use License to the United States Government, with all other parties subject to the GPL-3.0 License.
Inquiries / Requests
All inquiries and requests may be sent to opensource@captivation.us.
Copyright © 2022-2023 - Captivation Software, LLC.
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 MomentumX-2.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5e52b43065f1e86d934b528ab2291b54a317769a4941d8a155141f67bc8c0b3 |
|
MD5 | de002573597ee980f26cf7c877250636 |
|
BLAKE2b-256 | dbc1fcfe0afc6f458d42c7a815e626fffbc1bb6e72a0b8a4657f3816ae5da42a |
Hashes for MomentumX-2.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b249a38537fb01c39fe8f5737a3e9bf307c5f3985b2ffa71fc025cd7c182eefa |
|
MD5 | 4d7fae301fa97866cce355f8704e2641 |
|
BLAKE2b-256 | 4fe852e0979b0b87a60bf34e01bef813337bcad1e010e2fae113b8c21aa559de |
Hashes for MomentumX-2.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8914947014d1696e5d42d442dd728e06bbe99a677656e3ed1eebc37cf024356 |
|
MD5 | 2ed7907becf44a07603d3306f1957d7d |
|
BLAKE2b-256 | dd22f84acf8a3e534451e1870c2bdcd894dd5a3985715e085d2881396f7bd802 |
Hashes for MomentumX-2.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40f99c5b3ac2695f97804c291ac90afc4f0a733349e69ee10e2e026a8a19c390 |
|
MD5 | 16a676ecc48afc61792d6944fb331827 |
|
BLAKE2b-256 | ed4a72ff9bb463e20dfa08182dfd9a91db1518cc94c4a6be3a5ebed5b56e06e5 |
Hashes for MomentumX-2.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1004b46657fe3050d9e8d12c967d24d38cfd1c05a32d1cc816997f3ac2c657ab |
|
MD5 | ba5e5527876dfe52b7be013d8468789c |
|
BLAKE2b-256 | a4f161c0faf69dd8b419c1a2895a949f2403bbbde1c110475d88df1c258a7802 |
Hashes for MomentumX-2.2.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2843088e792c3029f3cdea977a72ea0b745b2a9bbfc25316f66b58700b1e5cdd |
|
MD5 | c5c0daa39a9b24fafcb025b206252ef0 |
|
BLAKE2b-256 | f63f1706034afbd98a287a0801764d00d0912d8ae525ec8da2caa224d8bf3079 |