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.9.0.tar.gz (61.6 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.9.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.3 kB view details)

Uploaded CPython 3.15manylinux: glibc 2.17+ x86-64

momentumx-2.9.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

momentumx-2.9.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

momentumx-2.9.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

momentumx-2.9.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

momentumx-2.9.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

momentumx-2.9.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (220.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file momentumx-2.9.0.tar.gz.

File metadata

  • Download URL: momentumx-2.9.0.tar.gz
  • Upload date:
  • Size: 61.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for momentumx-2.9.0.tar.gz
Algorithm Hash digest
SHA256 bf85ecd31bac7360a556b71492f2b59555cd9da98e7911c1a5dd4f8a3ac14c6a
MD5 b7f259a0c410cc3e2d51315f99f75e49
BLAKE2b-256 b5b85d3c4d94c7494a66fed21db18f5d73c6a988a35de96bd9ce0e91a9d176ab

See more details on using hashes here.

File details

Details for the file momentumx-2.9.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.9.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1d88f542f7c3c5bea6a4f67b833ef5597e2522e77e0f38388f674dc459c9c681
MD5 bcd99815657c57e95e5b5cc5816f3fcd
BLAKE2b-256 eae031baf9735c81ea5fd7fb7758910daae3a2a836431f8c05bfb72daf7a8c85

See more details on using hashes here.

File details

Details for the file momentumx-2.9.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for momentumx-2.9.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 dbd740530442cab62c2e7fd9c155d6f1034d754d639dee6fb8b74dc46bbc7c91
MD5 cb565d844fc1c7c6c0fc90fc11c13602
BLAKE2b-256 a4a1dd51aa618a560f9071de068c4efe663cb42944924c816b2ce1fae0b52874

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for momentumx-2.9.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 537b3e0b28b2d261909999c3297aa012e0515660bb8eabe548d279cdbaf7d014
MD5 b90352532dbe1bd00f97655fd4de41a0
BLAKE2b-256 48a731f1a3e1b29b0ba7beb7d6b846d1639b20f68503d403409c8a858d111a4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for momentumx-2.9.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1750273af2f812d85ff164a6938f4ca9cb0fb31c965dc99ebdd218ced181eec5
MD5 15bb0e47b912f0b287dc42e062b9d7e5
BLAKE2b-256 0f36553f7a374fb5b4fa34969cf23fdb0e79146b842b2e4a68daeb91750f75fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for momentumx-2.9.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 fc0bd88d987f2fd1ac51d4cf9ebb01c2f36810848f46368290f3d1b24a252c1f
MD5 4c4e35ea9fba8c10f92bd117d704cf9a
BLAKE2b-256 42875abbdbd8655e616a1bb95b23ef9618e4a9c13776ca588a06e369faad268f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for momentumx-2.9.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5a6234356a3b3f5a79b69cc1e1fada9908932120d7430b8648f3731bcaefbe6d
MD5 6059248787e4155d3af574acd8306c50
BLAKE2b-256 b2910484022eab7e5e04242b5cd1b7c9910ff68f54bda8a0c1356a366185c11c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for momentumx-2.9.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c399edfecfd379690a98f7e84f4d7de99968994103f3d2cc8f9b0d38b956bcf1
MD5 160d05aecdaa16d13ea129e1468ae968
BLAKE2b-256 0df9800a51f2cb4fade22d3c59a1d7612dd05c465a24e576fc63b9b4f634abee

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