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.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dff68cec9fe2e37a136f4f6a7673f027d61fda3133ec3ac95abffa5f6de73d5 |
|
MD5 | 9220c607bda9214dff345c963d38c574 |
|
BLAKE2b-256 | 3d23382a2e8a2d12070628c3969b505811ddaeb76a2c547535e7e3433161819c |
Hashes for MomentumX-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 126349eebdd04d8c510411bd61e0b04ebf0ff43dc9581cb68329415052119895 |
|
MD5 | caeb357dfee854ac9778aee609d09358 |
|
BLAKE2b-256 | d4d6720a569d28dc1f2b97ce9b50388b710591f618a3751b474a5b4b223ea988 |
Hashes for MomentumX-2.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84480f2e67334fd314c092caf200afd80c92998c5f5fc5889053d9dfd998af70 |
|
MD5 | 23184c1964bd6272038a9e21562f3a6a |
|
BLAKE2b-256 | d1e2e2be5801cd039224aef816ff35403a8737667929b38c8d408c7d9d931742 |
Hashes for MomentumX-2.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b453e359c4815d0f06d8976405dbcf87c085b5590f93d6376eea40d09fae839 |
|
MD5 | a12c4a74815ecc5e587009f13bfeb39d |
|
BLAKE2b-256 | e036ae29aea63b15e93ae6a60fd170ca8fa1e15ec4e7653847519ecdba8a77ac |
Hashes for MomentumX-2.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e23408e2785ca4b1374fd3ae54ed69128b490c198a4de4426fabd61073ebc3fc |
|
MD5 | 8be77bcb40f7160ce2083c01f2846dc9 |
|
BLAKE2b-256 | ed44c6cba8369d12dd00a8835de9563d6cb5527dc0458d78ef86fbd961b2f7ef |
Hashes for MomentumX-2.2.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6863c7874b9947f6ae0442add9dc77f936988ea646d694d3330d2480d8236256 |
|
MD5 | cb264a7e3eaf6036ba7341b2336a3d0a |
|
BLAKE2b-256 | 294e1a11b27b5e0f64f0c1394c8bdd00c0ce634e1ce047980c4a7ca5005dd65e |