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.
- 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.
Stream Mode
# Producer Process
import momentumx as mx
# Create a stream with a total capacity of 10MB (1MB x 10)
stream = mx.Producer('my_stream', buffer_size=int(1e6), buffer_count=10, sync=False)
# Obtain the next available buffer for writing
buffer = stream.next_to_send()
buffer.write(b'1')
buffer.send()
# NOTE: buffer.send() can also be passed an explicit number of bytes as well.
# Otherwise an internally managed cursor will be used.
# Consumer Process(es)
import momentumx as mx
stream = mx.Consumer('my_stream')
# Receive from my_stream as long as the stream has not ended OR there are unread buffers
while stream.has_next:
# Block while waiting to receive buffer
# NOTE: Non-blocking receive is possible using blocking=False keyword argument
buffer = stream.receive()
# If we are here, either the stream ended OR we have a buffer, so check...
if buffer is not None:
# We have buffer containing data, so print the entire contents
print(buffer.read(buffer.data_size))
# See also "Implicit versus Explicit Buffer Release" section below.
Sync Mode
# 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.has_next:
data = stream.receive_string()
if data is not None:
# Note: receiving strings is possible as well via the receive_string call
print(f"Received: {data}")
Iterator Syntax
Working with buffers is even easier using iter()
builtin:
import momentumx as mx
stream = mx.Consumer(STREAM)
# Iterate over buffers in the stream until stream.receive() returns None
for buffer in iter(stream.receive, None):
# Now, buffer is guaranteed to be valid, so no check required -
# go ahead and print all the contents again, this time using
# the index and slice operators!
print(buffer[0]) # print first byte
print(buffer[1:buffer.data_size]) # print remaining bytes
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)
Implicit versus Explicit Buffer Release
MomentumX Consumers will, by default, automatically release a buffer under the covers once all references are destroyed. This promotes both usability and data integrity. However, there may be cases where the developer wants to utilize a different strategy and explicity control when buffers are released to the pool of available buffers.
stream = mx.Consumer('my_stream')
buffer = stream.receive()
# Access to buffer is safe!
buffer.read(10)
# Buffer is being returned back to available buffer pool.
# Be sure you are truly done with your data!
buffer.release()
# DANGER: DO NOT DO THIS!
# All operations on a buffer after calling `release` are considered unsafe!
# All safeguards have been removed and the memory is volatile!
buffer.read(10)
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
File details
Details for the file MomentumX-2.7.1.tar.gz
.
File metadata
- Download URL: MomentumX-2.7.1.tar.gz
- Upload date:
- Size: 51.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2624cff8f640bc2892ee2a6432356ea39b9ac834afaf3dbc0f1c481bf9ed998f |
|
MD5 | 9c66b64299b68fbee9ecaaab3dfff104 |
|
BLAKE2b-256 | c2f68dc6b2eb0044359c492a9f625ae9c3bfb4da84464a08c0674c3a00dbf107 |
File details
Details for the file MomentumX-2.7.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 225.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d78cd6117fc3a92da3ab3f7f762f0be4feacc536d865c36d46efb8c7101e8e56 |
|
MD5 | f55698e0075703136deb8225edda42a5 |
|
BLAKE2b-256 | ef032d2a61bd1097e49dbfad6214586d39f78a996e746cc43c1aa05a677c6854 |
File details
Details for the file MomentumX-2.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 225.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f705d76b470d0afa66c6ce192685966bf6ac58efb929da6575daaaf6597bbd0c |
|
MD5 | 734207177ac52685134f37bd11d49439 |
|
BLAKE2b-256 | 1b02d7c348f3e7dfc4bd99ce8b7b6d7a3f827cbbf32368e52c45a91737dcf408 |
File details
Details for the file MomentumX-2.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 225.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3badfa54aa4b088ca7c57313d29af1d333866b8fbfae56fda061b842c11247b7 |
|
MD5 | 0772fac5b0d70a486e446719f6761fcb |
|
BLAKE2b-256 | bcd8faa73905ee801c30e6f0d885a244f5c4bee6db8e9b8e6bc1f7357d2475ef |
File details
Details for the file MomentumX-2.7.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 206.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b07a8b5685dfc8fc6c8d254cd5a4cca4c77909b52cfae70704daeff1403b0f19 |
|
MD5 | 070731e658737c21148401e0ba0339f9 |
|
BLAKE2b-256 | c6da48fde8511f43d60fe843b996008308f1b9a24a6402e008b091f5141d5013 |
File details
Details for the file MomentumX-2.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 225.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f40ace4c275160b07dbdb8e8eed9a2d8676ec8b1ce6ed510fe9baa0493e561f |
|
MD5 | 19c96650e7da0f9c8b7ae7086420ed20 |
|
BLAKE2b-256 | d7c8c3240b1d6c65bbbc8bad41dd1c922e5f6094173a3c04548ce4b016c44ec5 |
File details
Details for the file MomentumX-2.7.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 206.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a6ca7cc2423504d4456032a36afd48e525fdb0b69777782afb5f996e64766fe |
|
MD5 | 97127517746d60c3d6aff983c6f50e4c |
|
BLAKE2b-256 | e4951f2b6b73a1d1f2915d1b9f6751045a6397f699e8aff230e157aca2b90895 |
File details
Details for the file MomentumX-2.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 225.8 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eeb2e03264b9de6d8085691f2e83ab5ffe766dda555a92f554382607ed4011e |
|
MD5 | 8ffbcdfa582995bc1864dce25cb3c80c |
|
BLAKE2b-256 | 08ba593bc4ebce7c47a7516839d7802d35636f4cb7e47d124e756740f70a8476 |
File details
Details for the file MomentumX-2.7.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 206.8 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9302704d00effa0f1d0e7a97ac8a4d55d6682397ad1a7550dc2f9312522c2e3 |
|
MD5 | 52f539b2a56f334b8945bb80db54bc64 |
|
BLAKE2b-256 | 8b894142b474da633e563cc9f6b27a6da957a4dc4b661bd6fa389b22b54c8ed5 |
File details
Details for the file MomentumX-2.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 225.5 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f70efa74480761b5ff0534f0a9ff470f2ddb0c3b8053d640f2900ecf0ce2af |
|
MD5 | 9be917d0195a93aeb7a0ea9158a6f54d |
|
BLAKE2b-256 | 72a0997cc65999ab3770619594323b8b3d016ab6957aab1006c7fb8dee25b579 |
File details
Details for the file MomentumX-2.7.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 206.5 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53f4d92d908ade2530117052782a59c7d0b5e6d67a33ea0ff2320f8eba15c07e |
|
MD5 | e728d6fb98a0fb6e56bae04c26ddaa56 |
|
BLAKE2b-256 | 3345a7b51bb408804a400f1e986647784880c7c0500ecfe12807314f7751001a |
File details
Details for the file MomentumX-2.7.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 230.6 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d40b391e55a1afbe621d94facbe8eed4bf293c952bac45fed51c5f8b439dff1 |
|
MD5 | 5164f9f1ff24328b0409ab5584217dbc |
|
BLAKE2b-256 | 8248e490e029b55f20364de24fe0b11bcc4cd1477fbe4857be6bb2ffc75bbeaa |
File details
Details for the file MomentumX-2.7.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 214.6 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8121e12eb8958e60f3edfb10307b111ef34d1cfa5fb48f259af98369a3fd6787 |
|
MD5 | 1d1bda29625250be55d9b516dc74f8d1 |
|
BLAKE2b-256 | 49fa914bb2c1d47d64228293a099c4753c86f5cfb1cf936aa00f7e1ff2917929 |
File details
Details for the file MomentumX-2.7.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 230.6 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 795e5fa35e34e0a524692ed6b4eea049e694097e7d80d9720b921e5dc00947e8 |
|
MD5 | f0a7dfda67937a29c7ec0ace3a00e970 |
|
BLAKE2b-256 | d14b1fb52ccee75fb6c71ea16d0571d9542bf3f08521628df6f802e9f17b1913 |
File details
Details for the file MomentumX-2.7.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: MomentumX-2.7.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 214.4 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b68b8d4087e765fa8b51cb05e7a69978a12f44d24982ce93c5cb84a9c85337f4 |
|
MD5 | d08cf6821ce9ac3eead943f991688f5e |
|
BLAKE2b-256 | 55e4ecc301464c0adfa68d7f40603a9906d215c6e084958a9d4b291205b2a2a9 |