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)
Isolated Contexts
MomentumX allows for the usage of streams outside of /dev/shm
(the default location). Pass the context
kwarg pointing to a directory on the filesystem for both the Producer
and all Consumer
instances to create isolated contexts.
This option is useful if access to /dev/shm
is unsuitable.
import momentumx as mx
# Create a producer attached to the context path /my/path
stream = mx.Producer('my_stream', ..., context='/my/path/')
...
# Create Consumer elsewhere attached to the same context of /my/path
stream = mx.Consumer('my_stream', context='/my/path/')
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.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85a8daac29993dbc21fe26c4363ed8b3c0063640f79652ff21b1e5d5a11c1df2 |
|
MD5 | fd583f98693c5bc7d4ba1d11093242ef |
|
BLAKE2b-256 | 0a5430fc769aa814482e4d53de477bd8a58377bdf22d6ec742c4524bb5028596 |
Hashes for MomentumX-2.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31c116bf4fdaf4bc923769eb4a4b6863ab09bd075ab4d490e3e42b652f0ecd9a |
|
MD5 | bbe8b1d9cb3f2327b9eaff2c98e0dd18 |
|
BLAKE2b-256 | 96d33c99a653e531f6f49f8a7e96c6ffc4ee8c41fe6db585399426f8bd702e40 |
Hashes for MomentumX-2.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39f153685d955fdadca5ad759bcbdf1c3d93c8d3eaf546fde4e3b045544c9d34 |
|
MD5 | b7dae7bce67558f06f1fa40b4736157a |
|
BLAKE2b-256 | 3a22b40c384921b6f2dd87cc7bfeb3fa2795be399d89283c5909031daf205fb4 |
Hashes for MomentumX-2.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5929161b863f62960e2b63377dc5feda6342a79122162fe14b355e4e27c43d44 |
|
MD5 | 9416e933147aa3c9cbda534aa7ab9bd2 |
|
BLAKE2b-256 | 4e1c356cab86b504c799bae2cce3c2e2a87776240ed2729d0fedfa75a964d9bf |
Hashes for MomentumX-2.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36c1fdf251aece27d30e1029ef32ee82a501e354c365c11efa5c055ce838ba38 |
|
MD5 | 72c63dc7b18f23161ba7af48adf5d5e3 |
|
BLAKE2b-256 | 7aa08b65fe3f49e6808f2b10d4b89bda6f8d7e53fd601dd8a60d027d9e6cdc92 |
Hashes for MomentumX-2.3.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0707ece45fd2f49fafd961a3f8ea9a449c9d81472bb26b1780eaadc2df7b390 |
|
MD5 | 069e4e37393e3513cbef1afddfcc986d |
|
BLAKE2b-256 | 04f1723c42efae81668cb341eb0140bc95a89428ab9b0b11f27018b6e7b5e5eb |