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.
  • 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
buffer = stream.next_to_send()
buffer.write(b'1') 
# buffer data == b'1'

# alternatively, set via array indexing...
buffer[1] = b'2'
# buffer data == b'12'

# or also set via python slice operator
buffer[2:3] = b'34'
# buffer data == b'1234'

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')

while True:
    # Receive from the stream as long as the stream is available 
    buffer = stream.receive()
    print(buffer[:buffer.data_size])
    
    # Calling `buffer.release()` not required. 
    # See "Implicit versus Explicit Buffer Release" section below.

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.has_next:
    # 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)

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


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.6.0.tar.gz (49.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.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (232.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

MomentumX-2.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (232.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

MomentumX-2.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (232.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

MomentumX-2.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (231.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

MomentumX-2.6.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236.6 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

MomentumX-2.6.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236.5 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: MomentumX-2.6.0.tar.gz
  • Upload date:
  • Size: 49.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.6.0.tar.gz
Algorithm Hash digest
SHA256 6cac59cee253254f7de4c0f1291512f7d23fa422e9aed8aa3c8ffde567042775
MD5 478ff3c698e73d707295cc64f638de2a
BLAKE2b-256 b8caa80b10b7527a6de0d4bb6b047e0ae073efd16afa95d27bb49bc52207b075

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 036a24c8051a775a3b7eaaf5bf65999eea24baff35c651ac20c98549099698a2
MD5 8fb0da42dcfc2c367f132bd90d963f5b
BLAKE2b-256 b8956d511472bb6f416639a8d8a6502286f8d62f9012988bf1fa32a87f1edf6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cfb247287c650694f50f3201b8509c929f590a5c0dcb8208b4160c935e04eccd
MD5 1d58289622656cc534b62c5dc12417df
BLAKE2b-256 538e5311d0bf872be5acc24538a4261813f60c85adf5192880161db7b99253c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6f8b8ff54a8b20d0e335c3249315fe035d61c32782412f1a5f70e633dc4a60c
MD5 975f762683b73c2b605a44f420ea7729
BLAKE2b-256 dce6fc27da36fd47b421e7046090eb5d1d00bc4761856a4840fa129a4d893790

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d1a5fe70aa90ad7ac53c6559003e8e5b1942b5bbf3a767bff8862de8f17583aa
MD5 28e28b0bb3e9b02bbaf5a9b6afc45195
BLAKE2b-256 4b540621dd084d25a493f7e479ae05fa5a6f913208ec5472249875fefc78b565

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.6.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2083e526430a223af0655d47b60b7705455cec3f3fa29d2aa043be8ea454b5d
MD5 6d68d6c03104c9a77b6763d4e233f622
BLAKE2b-256 637bce094f491295d752ffd9cf74421a63d4082cfe69ba7c0e9f8db9c32cbf86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.6.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f6f98389d0ec92ff987205926db7c607d6d12a092067220da8eedad3b0de186
MD5 2eb3b5ac1796ad1116c2d431bd75efd6
BLAKE2b-256 85567751f8790edbd9291e88feb69008f51b1727b9f91b10c483b232e7996d92

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