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.4: Fixed cibuildwheel configuration for proper multi-platform wheel builds; added architecture-specific settings for Linux (x86_64/i686) and macOS (x86_64/arm64);
  • 0.0.3: Fixed cibuildwheel configuration for proper linux wheel build;
  • 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.4.tar.gz (102.4 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.4-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.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (183.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

hyperq-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

hyperq-0.0.4-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.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

hyperq-0.0.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (183.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686

File details

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

File metadata

  • Download URL: hyperq-0.0.4.tar.gz
  • Upload date:
  • Size: 102.4 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.4.tar.gz
Algorithm Hash digest
SHA256 0149f85a06f038683cd89b0542f455cc0817a6a67400cfb74daf5203e3656df7
MD5 691ca03bc0115f180d0522491d9a4c21
BLAKE2b-256 17276f7085bd00663ef5c39c097937618da6e0358c779e48968233ba733d8cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4.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.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperq-0.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b55d16a42106fbc2ddf566569c35f8331cff9d9af18d6cf1e80802c5b6c004f8
MD5 183d83963f31a24aed277de64f6fe0ba
BLAKE2b-256 a4b12276608dace91d60e8e242294a83856c6502e07ab487e3ced2b13c433031

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4-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.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperq-0.0.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4accb1e34f4d43bdf4572840fe0152f58c4bedbed487c7a3d34f855b5161cffe
MD5 37e14db63ebeb3915c23a2bc81f475b4
BLAKE2b-256 1134e09978131e61de3e3f0757b2551ce605eba4494098a934fc7576ae652523

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4-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.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperq-0.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 276d9b35bf69f6678d2bca059d1e5463ae23deb8c7b5cf8149765146b6e080b5
MD5 3b4e73e6b8b427b3bf27f5ecbb755422
BLAKE2b-256 c2862eb478032f2c3d846491c8088bc8e4555ef1a5449194c029456809a1ffb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4-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.4-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperq-0.0.4-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 82b1a51821ee081bf5c8504b1e7a61e787c42f3fc10e46e7861d84dab71c2d18
MD5 01cf26075636bc48b8728b024b705357
BLAKE2b-256 360c02f4b83573bdffa686e75ff5518e91c67fefede51fe10ac95a89d2eb7db8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4-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.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperq-0.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bd5e688a4bb7160f4719324001cb05af851eb6b17d166dbd47acb1d30373eb97
MD5 483b94150d86a45b6a2fe4a42f175637
BLAKE2b-256 ef1277b5d82bff587ccec4be44155c56b89413096530b14b7aeec0c78aef0b58

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4-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.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for hyperq-0.0.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4ebc268a47d939a7eda694fbdb359bb5d81c8fb1fc5d16a5d544cdd47a15756e
MD5 8b5ea8e16de23f29d274cf6baf469e4d
BLAKE2b-256 475b711fd8f8f32e3cdae0756c0a0cba2592591169606e1e6d8a89323f3326c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperq-0.0.4-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