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.0.tar.gz (46.5 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.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

MomentumX-2.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

MomentumX-2.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

MomentumX-2.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

MomentumX-2.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.7 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

MomentumX-2.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.6 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: MomentumX-2.4.0.tar.gz
  • Upload date:
  • Size: 46.5 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.0.tar.gz
Algorithm Hash digest
SHA256 95741c14cb97ff8a2a4c1ebf018e54606d6ed9ca9819e421067004195a91d04b
MD5 cedd366b5d7b54e819ab046a7a528f8c
BLAKE2b-256 b78918d6eb5bb73d03a7cb61834cc01e1803ec1d7a167c79c9f1aafdf8f60044

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c231bc0409e86c174c38a23cd5ec72817156f753d89a26bd051357feda7b4bb
MD5 958d2c4c5d4e56b426d8bbf787aee1e9
BLAKE2b-256 a214e414ce41cfb241c6a0623d6b2474fa65c8cf31ec09653a0b78da26c89618

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 201cc4202a46c4c74fda64091b641eb895d131803f1ac506322203236dfd742b
MD5 6aa134a00fec077d1b7b6dc622e8bee7
BLAKE2b-256 5d61c0f81a11cd5e18e5e68d2796a3ed843fff22f7dc38015e959893fdc93d14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b97e495957299a5a5b2908e0c435de1025d1c853681bdfa8dabb39e66023602
MD5 3696c65021127b51065c313213e6232c
BLAKE2b-256 3885e66f01d0cb68da358d11f018b52ffde399e649f64774ea05ed2034c5020b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 48b74f1b662597deea9f59edc738d8d8a9ec3125aa3b8589e176c92e9cb9341e
MD5 aa2836825a8d20e329c22f9d126c89a7
BLAKE2b-256 6da4ec8640dc48a69d834b25f9fc029db8a052b4c1448dacdd5346bffcafec5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd97cf8a0b1c11626e17c6badcf919df14880993ec77dc2d01f6e09fec83d1bd
MD5 94884fdabe4f58e17172ba793795d85b
BLAKE2b-256 e97e3edf57d362d95d3990eb5e5c15ffcd41548b43469ec14b8bafdb1381d739

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffd4048032b73a9a53562f0d064f6219f1da69f717a7b2b01fed7c9524b637d2
MD5 b6d26069f36d727f4d049946767c8061
BLAKE2b-256 2140316379261dd4652dacb6c76bc4b4ccf5a2deb3adaaf7da440e49bcb96738

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