Chronicle Queue Documentation

repository·ea·Indexed 25 days ago

https://github.com/openhft/chronicle-queue

A high-performance, broker-less, off-heap Java library for ultra-low-latency, persisted messaging. Designed for applications requiring millions of events per second with microsecond latencies, such as High-Frequency Trading. Features include an append-only data structure using memory-mapped files, support for self-describing messages, MethodWriter/MethodReader proxies, and an Async Mode to reduce latency outliers.

Tokens
35.4K
Snippets
91
Records
195
Agent score
87%

What's inside Chronicle Queue

  1. Overview of Chronicle Queue

    ea

    Chronicle Queue is a broker-less, off-heap Java library designed for ultra-low-latency, persisted messaging. It allows for millions of events per second with microsecond latencies. Key features include:

    • Off-heap storage: Minimizes Garbage Collection (GC) impact.
    • Persistence: Uses memory-mapped files to store data on disk, allowing for unbounded queues limited only by disk space.
    • Concurrency: Supports multiple writers via locking and multiple lock-less concurrent readers.
    • Messaging Patterns: Supports appending messages, tailing (reading) messages, and random-access seeking.
    • Low Latency: Achieves sub-microsecond latencies for same-machine IPC and under 10 microseconds for replicated machine-to-machine communication (Enterprise Edition).
  2. Overview of Chronicle Queue features

    ea

    Chronicle Queue documentation is divided into a User Guide and a collection of Runnable Demos. The User Guide covers the following core topics:

    • Getting started: Introduction and hands-on instructions.
    • Configuration: Fine-tuning options for various use cases.
    • Appending: How to write messages to a queue.
    • Tailing: How to read messages from a queue.
    • Performance tuning: Key factors for optimizing performance in different environments.
    • Enterprise Features (★): Includes Replication (automatic replication across machines/cores) and Encryption (protecting queue contents).
  3. Use Chronicle Async Mode to reduce latency outliers

    ea

    Chronicle Async Mode provides a high-performance, multi-writer, multi-reader, buffered queue implementation. By using an asynchronous buffer, you can mitigate OS-induced pauses that occur when using standard ChronicleQueue under heavy load. Configuring readBufferMode and writeBufferMode can reduce latency outlier events by up to 98% on loaded systems.

    Key characteristics:

    • Multi-writer/Multi-reader: Supports concurrent access.
    • Zero-garbage collection: Designed for high-performance environments.
    • Flexible Backing: Can be backed by an in-memory BytesStore (for single-process use) or a memory-mapped BytesStore (for multi-process use).
  4. Understand Chronicle Queue core concepts

    ea

    To use Chronicle Queue effectively, familiarize yourself with these fundamental components:

    • Appender: The message source used to add data. Writes are sequential and performed by appending to the end of the queue. Note that you cannot insert or delete excerpts once written.
    • Tailer: An excerpt reader optimized for sequential reads. It supports both sequential and random reads, in both forward and backward directions. Calling a tailer reads the next available message.
    • Document: The unit of read/write operations. Each document consists of a 4-byte header followed by the data excerpt.
    • Excerpt: The specific part of a document that contains the actual data.
    • Topic: A directory containing queue files (e.g., .cq4 files). A topic organizes data by timestamped files.
    • Marshallable: A data structure type that supports reading from and writing to external formats like binary or JSON.
  5. Understand the Chronicle Queue data structure

    ea

    Chronicle Queue is an append-only data structure designed for high-performance sequential writes and reads. While primarily append-only, it supports random access and in-place updates (though entry sizes cannot be changed, they can be padded).

    Key characteristics:

    • Efficiency: Optimized for CPU L2 cache coherence and sequential disk access (HDD/SSD).
    • Memory Mapping: Built on MappedBytes, it uses memory-mapped files to treat files as unbounded byte arrays. This allows the queue to exceed JVM heap limits, constrained only by available disk space.
    • Thread Safety: Supports atomic operations like compareAndSet and atomic add on off-heap memory, enabling fast sharing between threads or processes (latency as low as 25 nanoseconds).
  6. Compare Chronicle Queue vs Chronicle Queue Zero performance

    ea

    Chronicle Queue Zero (Queue Zero) is a high-performance variant of Chronicle Queue designed for applications that require significantly higher performance and better scaling at high percentiles, at the cost of some standard Chronicle Queue functionality.

    Performance characteristics:

    • Latency: Queue Zero typically provides approximately 10x lower latency compared to standard Chronicle Queue.
    • Outliers: Queue Zero demonstrates a significant reduction in outliers at higher percentiles.

    For implementation details or access to Queue Zero, contact sales@chronicle.software.

  7. Understand Chronicle Queue Use Cases

    ea

    Chronicle Queue is a producer-centric messaging solution designed for high-throughput, low-latency data retention. Unlike consumer-centric systems that implement flow control to prevent consumer overload, Chronicle Queue focuses on never pushing back on the producer, acting as a massive buffer for upstream data.

    Key use cases include:

    • Producer-Centric Systems: Buffering data from upstream producers where you have little or no control over their speed.
    • Market Data: Capturing high-frequency UDP packets (e.g., CME OPRA) at rates of millions of events per minute without packet loss.
    • Compliance Systems: Decoupling monitored systems from compliance recording to ensure compliance overhead does not impact system performance.
    • Latency-Sensitive Microservices: Providing low-latency Inter-Process Communication (IPC) between JVMs on the same machine (~1 microsecond) or between machines (~10 microseconds).
    • Log Replacement & State Machines: Building reproducible state machines by recording all component state changes. This allows for detailed DEBUG logging in production with minimal overhead (< 10 microseconds).
    • Lambda Stream Processing: Implementing deterministic, non-batching streaming components that allow for bug reproduction by replaying events in a specific order.
  8. Core Concepts: Appender, Tailer, and Excerpt

    ea

    To use Chronicle Queue, you must understand its primary components:

    • Excerpt: The fundamental data container. A message is written by starting, writing to, and finishing an excerpt.
    • Appender: The source of messages. It appends data to the end of the queue. It does not support insertion or deletion.
    • Tailer: An excerpt reader optimized for sequential reads. It can perform sequential and random reads (forwards and backwards). Unlike traditional queues, reading a message does not destroy it; every reader sees every message.
    • Topics: A directory of queue files (e.g., mytopic/20160710.cq4).
  9. Understand Chronicle Queue terminology: Appending and Tailing

    ea

    Chronicle Queue uses specific terminology for its core operations:

    • Appending: The act of writing data to the queue. This is performed using an appender.
    • Tailing: The act of reading data from the queue. This is performed using a tailer.

    Data is stored as a series of bytes, regardless of whether the original type was text, numbers, or serialized blobs.

  10. Understand Chronicle Queue Enterprise features

    ea

    Chronicle Queue Enterprise is a commercially supported version of the Open Source Software (OSS) version. While the documentation covers OSS functionality, Enterprise-specific features are marked with a star symbol (★) in the guide.

    Enterprise features include:

    • Encryption: Protecting the contents of message queues and individual messages.
    • TCP/IP Replication: Automatically replicating queues between hosts for real-time data backup.
    • Timezone adapted rollover schedule: Managing queue file rollovers based on specific timezones.
    • Async Mode: Improved performance for high throughput on slower filesystems.
  11. Explore Chronicle Queue Operations

    ea

    The Queue Operations guide provides documentation for the core functional areas of Chronicle Queue. You can find detailed guides on the following operations:

    • Appending: How to write data to the queue.
    • Tailing: How to read data from the queue (typically following the tail).
    • Indexing: How to index data for efficient retrieval.
    • Read/Write Proxies: How to use proxies to manage read and write access.