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.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47fca6df8904fc43a0867eaf7d576b0b4cfc81d4d5844682432af0bb922d008e |
|
MD5 | fea50edff41ff83fadd73316c2c602c8 |
|
BLAKE2b-256 | 7b3b15ab65bbdabbad81270f870a7c5fce180bbd417d3f6a95ba3f541ddceb3c |
Hashes for MomentumX-2.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 425b885cb4f18082f294dd0294388eb37441a12318f66211e26e63fbc02a2bb8 |
|
MD5 | 5b5007f1257ceda543027280f10d18ca |
|
BLAKE2b-256 | ea3fe8742ef8a9b5ba56d2e0561f2ea0c34eeee51c4218332026fddf9ddded96 |
Hashes for MomentumX-2.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce41ec74bc0002de3aad1042a41ecf1513c576f3b4d3e0e34af7f51bfed5d520 |
|
MD5 | 1902887dbdfb470d6d80d8f3f826af81 |
|
BLAKE2b-256 | 5e0ee3c7d4e7cebb2c4c81f73a3410e5a6ff28c1e17dabd602cf961f8f3372b6 |
Hashes for MomentumX-2.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acdf1fd1f2394717e1626464c0ed503c8638734219f663ac2c44025931d3d943 |
|
MD5 | ce2173f23165f8e216f20a7ebc62fc87 |
|
BLAKE2b-256 | 4590b843b6144baa1417b01e840b0c60bdd8f8f72dd60f3c70b54a963d232528 |
Hashes for MomentumX-2.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de1b315a824448f2516a8f3ab6150a4156577b0b9099e28f9b11aee57a5ca54c |
|
MD5 | 798a1b97e2657bf7917efb2965b6d9ac |
|
BLAKE2b-256 | 7ef94b55d6c21faa297c89eeb2c5ac04dcf01eff8331637e7b9c33c214c8fb2f |
Hashes for MomentumX-2.4.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35837f77762d6315fa27f22a97df7a2d207bfe6750583a2be807cc845426660f |
|
MD5 | 4df3c5436616fa085e0d42e27f241c4c |
|
BLAKE2b-256 | 66f106446abed24999de9987e34220c8cc4bd951587406b0f2bcda2395e0ce6f |