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.

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


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.7.3.tar.gz (51.7 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.7.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (224.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

momentumx-2.7.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (224.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

momentumx-2.7.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (225.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

momentumx-2.7.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (225.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

momentumx-2.7.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (225.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

momentumx-2.7.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (225.0 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

MomentumX-2.7.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (230.5 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

MomentumX-2.7.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (230.5 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for MomentumX-2.7.3.tar.gz
Algorithm Hash digest
SHA256 816715024aaa4014aa7d80f2960ec73d306a6769727938a4c5e78506726af6fd
MD5 34785acbb3e77d058584de74722b32a8
BLAKE2b-256 80cf6e1bd2ed56418b9ddb0518d5f26bde7595a03e7d45370e6b7bf94a2a0b78

See more details on using hashes here.

File details

Details for the file momentumx-2.7.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.7.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d19fd0ec343e46aea3920571e4ee36a7ecf6eaae95bf7b1f0d7918fd02ecdaf1
MD5 b8ac2d032ebcf7b2cd866c0da4fe3b77
BLAKE2b-256 d98f7f1f64fb94e5bed65a6eb9e943f2e232a08cddef3da26cf59b7a62257eb7

See more details on using hashes here.

File details

Details for the file momentumx-2.7.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.7.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e96b4ceb7e26311d43535ea5f711eea5948f6603daf78ed3097b8f44a4aec8fb
MD5 128796d27a93f159e84e32190bb94487
BLAKE2b-256 8fc76208397d898dc70a900947221dac54b002c57e70c9d7e4792699744f4841

See more details on using hashes here.

File details

Details for the file momentumx-2.7.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.7.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7fedbd112c0abc5bbde6a39f29fa34ed02154008bb9207af079c4a0efd5d6cfc
MD5 fd65505806f20df5ce6eb6334e26be4e
BLAKE2b-256 f0d918b3e41217c108655c782e1160baa7ee45ac35a03590e4dad9ceae40c151

See more details on using hashes here.

File details

Details for the file momentumx-2.7.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.7.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49d1ced0c49e3cec5dfd853087560ef3c8e4ea05401293d6950e147f52fd79b2
MD5 1df58f2ff8edd5d8a98ea4e9f6125cbd
BLAKE2b-256 3b834f37b50bb010938fcb776367e7d67061072538340bafa63e2873665cc7d7

See more details on using hashes here.

File details

Details for the file momentumx-2.7.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.7.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 603b37e0298aa382aaf487de461f1e177617d6258f984dfbf9e402a26248077b
MD5 13090356192568c01195132142b8a7c1
BLAKE2b-256 9a15bd7ec58d61721a453f42e944e6406ea1841c1f230ba628e5d6bfa0d4ee7d

See more details on using hashes here.

File details

Details for the file momentumx-2.7.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.7.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 109dec7b3278a451b1c405a3cfd36ef560a814b1b3281252a50620f9273b58a2
MD5 308fce331fff958d19d730eb3744e613
BLAKE2b-256 b35f05c9a81f83cddf2ee542b2561da6ba9cbfca84a20bd3464b7911e18a5c5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.7.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0962d2f3fa35168df63208932e07410a15d920d11957517132671376b505a1c
MD5 059bd67720d8ddc189a708e03d1a93ae
BLAKE2b-256 25bc6ae1ffa051ac9779edce3fed28aa4eb8d309b987ca8140b1c3bbfdc6372f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MomentumX-2.7.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c8273e0a3aa9b658593afe5781419e7bac3a55f05ee316d1157c5b5d76c7744
MD5 01c0f22f43650ad50273dc2a9b5b561d
BLAKE2b-256 e6f2799a4a52f4cac0c38aebae7366344493c92c8fa8c92def9e678e55b4b801

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