Skip to main content

Hyper-fast queue for Python

Project description

HyperQ

Python 3.10+ License: MIT PyPI version

Hyper-fast queue for Python - A high-performance queue implementation using Cython and C++ for inter-process communication.

🚀 Features

  • Lightning Fast: Optimized C++ implementation with Python bindings
  • Inter-Process Communication: Shared memory-based queues for high-performance IPC
  • Ring Buffer Architecture: Uses a ring buffer with double virtual memory mapping to the same physical memory.
  • Two Queue Types:
    • HyperQ: General-purpose queue for Python objects
    • BytesHyperQ: Specialized queue for bytes data (even faster)
  • Thread-Safe: Safe for concurrent access
  • Unix-like Systems: Works on Linux and macOS (POSIX-compliant systems)
  • Python 3.10+: Modern Python support

⚠️ Platform Support

Currently supported:

  • ✅ Linux
  • ✅ macOS

Not supported:

  • ❌ Windows (uses POSIX-specific APIs)
  • ❌ PyPy (uses POSIX-specific APIs and C++ extensions)

🔧 Technical Details

Ring Buffer Implementation

HyperQ uses a ring buffer with double virtual memory mapping to the same physical memory. This eliminates the need for 2 memcpy operations when data wraps around the buffer boundaries.

Shared Memory Architecture

  • Header segment: Contains queue metadata, synchronization primitives, and buffer information
  • Buffer segment: The actual data storage with double virtual memory mapping
  • POSIX shared memory: Uses shm_open() and mmap() for cross-process memory sharing
  • Synchronization: Uses POSIX mutexes and condition variables for thread/process safety

📦 Installation

From PyPI (Coming Soon)

⚠️ Not yet available on PyPI - Package is still in development

# This will be available once the project is ready for release
pip install hyperq

From Source

git clone https://github.com/martinmkhitaryan/hyperq.git
cd hyperq
pip install -e .

Development Installation

git clone https://github.com/martinmkhitaryan/hyperq.git
cd hyperq
pip install -e ".[test]"

🎯 Quick Start

Basic Usage

import multiprocessing as mp
from hyperq import HyperQ, BytesHyperQ

# Create a queue with 1MB capacity
queue = HyperQ(1024 * 1024, name="/my_queue")

# Put data
queue.put("Hello, World!")
queue.put(42)
queue.put({"key": "value"})

# Get data
data = queue.get()  # "Hello, World!"
number = queue.get()  # 42
obj = queue.get()  # {"key": "value"}

Inter-Process Communication

import multiprocessing as mp
from hyperq import HyperQ

def producer(queue_name):
    queue = HyperQ(queue_name)
    for i in range(1000):
        queue.put(f"Message {i}")

def consumer(queue_name):
    queue = HyperQ(queue_name)
    for _ in range(1000):
        message = queue.get()
        print(f"Received: {message}")

if __name__ == "__main__":
    # Create queue in main process
    queue = HyperQ(1024 * 1024, name="/shared_queue")
    queue_name = queue.shm_name

    # Start producer and consumer processes
    p1 = mp.Process(target=producer, args=(queue_name,))
    p2 = mp.Process(target=consumer, args=(queue_name,))

    p1.start()
    p2.start()
    p1.join()
    p2.join()

Bytes-Specific Queue (Faster)

from hyperq import BytesHyperQ

# For bytes data, use BytesHyperQ for better performance
queue = BytesHyperQ(1024 * 1024, name="/bytes_queue")

# Put bytes data
queue.put(b"Hello, World!")
queue.put(b"Binary data")

# Get bytes data
data = queue.get()  # b"Hello, World!"

📊 Performance Benchmarks

HyperQ is designed for high-performance scenarios. Here are some benchmark results:

Hardware:

  • CPU: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  • Memory: 16GB
  • OS: macOS 15.3.1
  • Python: 3.10

1 Producer, 1 Consumer

Running bytes performance benchmarks...
================================================================

Results for 100000 messages of 32 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.119976      0.00119976                  833499
HyperQ                         0.421588      0.00421588                  237198
multiprocessing.Queue          2.09399       0.0209399                    47755
faster-fifo                    2.36328       0.0236328                    42314
🏆 Fastest: BytesHyperQ with 833,499 items/s
   3.5x faster than HyperQ
   17.5x faster than multiprocessing.Queue
   19.7x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 64 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.124732      0.00124732                  801717
HyperQ                         0.474716      0.00474716                  210652
faster-fifo                    1.67101       0.0167101                    59843
multiprocessing.Queue          2.20561       0.0220561                    45338
🏆 Fastest: BytesHyperQ with 801,717 items/s
   3.8x faster than HyperQ
   13.4x faster than faster-fifo
   17.7x faster than multiprocessing.Queue

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 128 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.116276      0.00116276                  860024
HyperQ                         0.499545      0.00499545                  200182
multiprocessing.Queue          1.99662       0.0199662                    50084
faster-fifo                    2.65151       0.0265151                    37714
🏆 Fastest: BytesHyperQ with 860,024 items/s
   4.3x faster than HyperQ
   17.2x faster than multiprocessing.Queue
   22.8x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 256 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.235679      0.00235679                  424305
HyperQ                         0.837711      0.00837711                  119372
multiprocessing.Queue          2.32011       0.0232011                    43101
faster-fifo                    2.68104       0.0268104                    37298
🏆 Fastest: BytesHyperQ with 424,305 items/s
   3.6x faster than HyperQ
   9.8x faster than multiprocessing.Queue
   11.4x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 512 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.251292      0.00251292                  397943
HyperQ                         0.770943      0.00770943                  129711
multiprocessing.Queue          2.08766       0.0208766                    47900
faster-fifo                    2.16858       0.0216858                    46113
🏆 Fastest: BytesHyperQ with 397,943 items/s
   3.1x faster than HyperQ
   8.3x faster than multiprocessing.Queue
   8.6x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 1024 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.209373      0.00209373                  477616
HyperQ                         0.664122      0.00664122                  150574
multiprocessing.Queue          2.28728       0.0228728                    43720
faster-fifo                    2.30807       0.0230807                    43326
🏆 Fastest: BytesHyperQ with 477,616 items/s
   3.2x faster than HyperQ
   10.9x faster than multiprocessing.Queue
   11.0x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 4096 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.419936      0.00419936                  238131
HyperQ                         1.0191        0.010191                     98126
multiprocessing.Queue          2.18819       0.0218819                    45699
faster-fifo                    3.13527       0.0313527                    31895
🏆 Fastest: BytesHyperQ with 238,131 items/s
   2.4x faster than HyperQ
   5.2x faster than multiprocessing.Queue
   7.5x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 8192 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                    0.701695      0.00701695                  142512
HyperQ                         1.34373       0.0134373                    74419
multiprocessing.Queue          2.95495       0.0295495                    33841
faster-fifo                    3.40265       0.0340265                    29388
🏆 Fastest: BytesHyperQ with 142,512 items/s
   1.9x faster than HyperQ
   4.2x faster than multiprocessing.Queue
   4.8x faster than faster-fifo

================================================================
Sleeping 2 seconds before next test configuration...

Results for 100000 messages of 16384 bytes:
Queue Type               Total Time (s)    Latency (ms)    Throughput (items/s)
---------------------  ----------------  --------------  ----------------------
BytesHyperQ                     1.22369       0.0122369                   81720
HyperQ                          1.62568       0.0162568                   61512
faster-fifo                     3.81159       0.0381159                   26235
multiprocessing.Queue           5.12029       0.0512029                   19530
🏆 Fastest: BytesHyperQ with 81,720 items/s
   1.3x faster than HyperQ
   3.1x faster than faster-fifo
   4.2x faster than multiprocessing.Queue

Results may vary depending on hardware and system configuration.

🔧 API Reference

HyperQ

class HyperQ:
    def __init__(self, capacity: int, name: str = None)

    def put(self, item) -> bool
    def get(self)  # Blocks until data is available
    def empty(self) -> bool
    def full(self) -> bool
    def size(self) -> int
    def clear(self)

BytesHyperQ

class BytesHyperQ:
    def __init__(self, capacity: int, name: str = None)

    def put(self, data: bytes) -> bool
    def get(self) -> bytes  # Blocks until data is available
    def empty(self) -> bool
    def full(self) -> bool
    def size(self) -> int
    def clear(self)

Parameters

  • capacity: Maximum size of the queue in bytes
  • name: Optional name for the shared memory segment (max 28 characters)

Important Notes

  • Blocking operations: get() blocks indefinitely until data is available
  • No timeout support: Currently no timeout functionality is implemented
  • Queue names: Must be 28 characters or less
  • Platform limitation: Only works on Unix-like systems (Linux/macOS)

🧪 Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=hyperq

📈 Running Benchmarks

# 1 producer, 1 consumer benchmark
python benchmarks/benchmark_bytes_transfering_1p_1c.py

# 10 producers, 10 consumers benchmark
python benchmarks/benchmark_bytes_transfering_10p_10c.py

🏗️ Building from Source

Prerequisites

  • Python 3.10+
  • Cython >= 0.29.0
  • C++ compiler with C++20 support (GCC 8+, Clang 10+)
  • Unix-like system (Linux or macOS)

Build Steps

# Clone the repository
git clone https://github.com/martinmkhitaryan/hyperq.git
cd hyperq

# Install build dependencies
pip install -e ".[test]"

# Build the extension
python setup.py build_ext --inplace

🤝 Contributing

Development Setup

  1. Fork the repository
  2. Create a virtual environment: python -m venv .venv
  3. Activate it: source .venv/bin/activate (Linux/macOS)
  4. Install development dependencies: pip install -e ".[test]"
  5. Run tests: pytest
  6. Make your changes and submit a pull request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with Cython for high-performance Python extensions
  • Uses POSIX shared memory and threading primitives
  • Inspired by the need for faster inter-process communication in Python

📞 Support

🔄 Version History

  • 0.0.2: Added proper PyPI wheel support for Linux and macOS using cibuildwheel; improved release workflow for multi-platform builds and C++20 compatibility
  • 0.0.1: Initial release with HyperQ and BytesHyperQ implementations

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

hyperq-0.0.3.tar.gz (102.3 kB view details)

Uploaded Source

Built Distributions

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

hyperq-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

hyperq-0.0.3-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (183.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

hyperq-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (177.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

hyperq-0.0.3-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (183.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

hyperq-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

hyperq-0.0.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (183.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686

File details

Details for the file hyperq-0.0.3.tar.gz.

File metadata

  • Download URL: hyperq-0.0.3.tar.gz
  • Upload date:
  • Size: 102.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hyperq-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c3768aac0c109d1c70b7c66fca123446d4e8308a98d2a4f663ed7e8db83e4f5c
MD5 7d997a38527798d7fcb27d457a24833c
BLAKE2b-256 4a3268ec86680f7c560624a0f5e1fa191f418cc67b9866ace072407d279ddfc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3.tar.gz:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperq-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperq-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9b9700a34c0e9b2c18b38446a6c12e4fb10ae2f06f22dded7d02ca6468cd04c
MD5 bc61ff1778d9362946a64f0ba2280617
BLAKE2b-256 ba8854628f14baa4611374a77191bc4a7c4483b5af0ede88386f4dd93628d42e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperq-0.0.3-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperq-0.0.3-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 117f00b11f8484b6e8804906ba497027999d75b3987d530fd5eaf23fa0994cbe
MD5 9d15403830fa4e218e95f93441582003
BLAKE2b-256 c23517d17750e12a50f7eb98d8264d339491f67c2f081696efc42ca1f6d97f62

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperq-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperq-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16ba5f453a1e8caf757551b0817944eaa706ff3e0ec0821490e58a2309697eb8
MD5 b96738e5f276b95810210a993e86fe47
BLAKE2b-256 64baef8f3442a66d3b2f847ecc508e54a5a5f48efd042beb38ed7566ad20deb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperq-0.0.3-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperq-0.0.3-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1d6df355b5836d2f945125f6a1a7395078dead4f302298d59a18363bc7695620
MD5 0cd035ef95f3299a052daf3e0b543352
BLAKE2b-256 e98191c387e4b35e28669eb0bcf8e0899cf0691883bd49ce5796275c085a8177

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperq-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperq-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e105f29598da086c74fec5f5002fc3816180bc5ad67c57fe903b0334984407a
MD5 f1f1ead1e16c8539ed2216fa2494fb8e
BLAKE2b-256 1f942beecbaeea3cbc2c9353b477066153b84c90066e81ae0bb2eadb201732c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyperq-0.0.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperq-0.0.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b5dfc88ab26190b0c76372bfe73d158ee6f3e798f1874c617fb784a64ec085b2
MD5 ebff6c669cbadd95149354b2076cc8a6
BLAKE2b-256 9389d6881c9e88c790b26952a90def51b223a4fc4f3c7f28c2df7e414a88759f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: release.yml on martinmkhitaryan/hyperq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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