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.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 594794f6b3f77155bae6b655b31dcfe36af91670d4f44a1abb1e4020daf79a6b |
|
MD5 | 2914ebf9493d70cd641d7d2afffd2b20 |
|
BLAKE2b-256 | f98566d423c1b0d6ee8aab8fc329d7c0c661e09d8344328b58325c996e1628e3 |
Hashes for MomentumX-2.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c5d842cde654e765bb8ffaf48d0fa62a38a3fec15cd2ec83175bf13ab33e51 |
|
MD5 | fc13f74ee395687c0821b2f4d497259f |
|
BLAKE2b-256 | 0c2a1edbee8b5979f265be21164ac427a8d00be10a2541bec065fa060344b9a7 |
Hashes for MomentumX-2.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4790f4797ee41462c98ee4332bd4b17ba274fbce403b95d1e26a92b7e0185b41 |
|
MD5 | 41448d9cacfcbe0cd52a372250854669 |
|
BLAKE2b-256 | 793d824a92a589bb5233b669fb2cf781d3a1ab9e66a6455738413101188a8e92 |
Hashes for MomentumX-2.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ee40fa379a5a2eb675887b55af046fab437c2c241ccc30c3cfd0672ba87b01 |
|
MD5 | feda9c21807662796514f75f3d7814b5 |
|
BLAKE2b-256 | 3b441cd43247187eb8788825a1bcb97a4374b47b4ddfe8b68cd5d997f47f843b |
Hashes for MomentumX-2.5.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 939292fecff1a9a3315fd8c71e87f036831a6dcb29e374539ba0be86fd9c91b1 |
|
MD5 | 4139832ceb6dc9ef63cd14f27d99b720 |
|
BLAKE2b-256 | 6e70a0eb58f9320ea50992bc5c9fa24d8d875755d5122a72a4eec63fd3525d15 |
Hashes for MomentumX-2.5.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 960331df892113d1f23920c79912cd5b7e511dfef3fd207585eb660fa98297bb |
|
MD5 | 288e54bc7705d9cf984ec825e3a7208c |
|
BLAKE2b-256 | 7e7cbeb657bb1dd8ccdbac3519e7f5f118efe57d21464d5cff3e74c6825a2acb |