Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MomentumX-2.4.3.tar.gz (46.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

MomentumX-2.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

MomentumX-2.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

MomentumX-2.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

MomentumX-2.4.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

MomentumX-2.4.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (203.7 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

MomentumX-2.4.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (203.7 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

Details for the file MomentumX-2.4.3.tar.gz.

File metadata

  • Download URL: MomentumX-2.4.3.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for MomentumX-2.4.3.tar.gz
Algorithm Hash digest
SHA256 ef952ff94fd32d0c4a4ea6ece6abb17aca61c6b302a68c46bf548ab5a131cae3
MD5 922721daccd59fc595416b79124904ce
BLAKE2b-256 dd19471bcd74ec0c5ceba723c3f0e8ec4971b659be85d31ae8fe83e21e3fc5d0

See more details on using hashes here.

File details

Details for the file MomentumX-2.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for MomentumX-2.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71df515d73f69c1229b29c5259a680e64214647240eb19398b2d5979ad8bffb2
MD5 7157e3fd6a42b34722e567a569f87150
BLAKE2b-256 e6cb3e2afb5a00e55d5145dc82e7af32e010b3dedae66bf95a049c55d186e231

See more details on using hashes here.

File details

Details for the file MomentumX-2.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for MomentumX-2.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55abf689c1ed18c001e95f1d927c2846c7aa99f17f7f1c9ddd132a25bdcf8afd
MD5 0d0a5004cd5631486469e33a274a2b16
BLAKE2b-256 5981058d5a9eca2a7da87fff951e34ecfb1daae6f1f273374a0c93d8e32dc128

See more details on using hashes here.

File details

Details for the file MomentumX-2.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for MomentumX-2.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8fa80552072458fab11b0cacd855b49e32a05dac20efaca7aceb961ad449f4ad
MD5 135f6faf28e4c8ee674152ac15a2b424
BLAKE2b-256 27251143cf9333f73456acc950dbd0072c073d6b906cb7f0f0734bf21d36f669

See more details on using hashes here.

File details

Details for the file MomentumX-2.4.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for MomentumX-2.4.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da7a98c8d991de0362f6d0d052acd6d23aadba7ee586760babb0c4e4bd1554ff
MD5 66f24e912a98bd2ebe5eea29c6911430
BLAKE2b-256 e4cd0e4c5a811a7bf7ac0bd0bcf7dea9e9fe97ab054159ab3d3053711dafc9a3

See more details on using hashes here.

File details

Details for the file MomentumX-2.4.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for MomentumX-2.4.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18b870d749a649c95f23623ac45225920e866c009bdcde3813218ccce6176bc5
MD5 f7f49f0de6d824e5f39a6d340f22952c
BLAKE2b-256 3af07a9c571b4e015cf6ddaa07f1233d15b0298831db7933b5dffbbf63ebf2ec

See more details on using hashes here.

File details

Details for the file MomentumX-2.4.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for MomentumX-2.4.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ce534bd9035e373a5e1458cb097cc2b4aeab6ec91f0045ec7c6cfdf1684a4a6
MD5 5b44fe17227873f56fd7e972701fbfbb
BLAKE2b-256 704fb1829872a8374205dfb08a0ca9f07f63b730aab761daaa54ea88aa8c619d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page