blob: e6126870eb79336bed4c38dd7c6a9664b58405d6 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="" >
<head>
<title>Persistence ยท ActiveMQ Artemis Documentation</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
<meta name="generator" content="GitBook 3.1.1">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="configuring-transports.html" />
<link rel="prev" href="filter-expressions.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="notice.html">
<a href="notice.html">
Legal Notice
</a>
</li>
<li class="chapter " data-level="1.3" data-path="preface.html">
<a href="preface.html">
Preface
</a>
</li>
<li class="chapter " data-level="1.4" data-path="project-info.html">
<a href="project-info.html">
Project Info
</a>
</li>
<li class="chapter " data-level="1.5" data-path="versions.html">
<a href="versions.html">
Versions
</a>
</li>
<li class="chapter " data-level="1.6" data-path="messaging-concepts.html">
<a href="messaging-concepts.html">
Messaging Concepts
</a>
</li>
<li class="chapter " data-level="1.7" data-path="architecture.html">
<a href="architecture.html">
Architecture
</a>
</li>
<li class="chapter " data-level="1.8" data-path="using-server.html">
<a href="using-server.html">
Using the Server
</a>
</li>
<li class="chapter " data-level="1.9" data-path="upgrading.html">
<a href="upgrading.html">
Upgrading
</a>
</li>
<li class="chapter " data-level="1.10" data-path="address-model.html">
<a href="address-model.html">
Address Model
</a>
</li>
<li class="chapter " data-level="1.11" data-path="protocols-interoperability.html">
<a href="protocols-interoperability.html">
Protocols and Interoperability
</a>
</li>
<li class="chapter " data-level="1.12" data-path="amqp.html">
<a href="amqp.html">
AMQP
</a>
</li>
<li class="chapter " data-level="1.13" data-path="mqtt.html">
<a href="mqtt.html">
MQTT
</a>
</li>
<li class="chapter " data-level="1.14" data-path="stomp.html">
<a href="stomp.html">
STOMP
</a>
</li>
<li class="chapter " data-level="1.15" data-path="openwire.html">
<a href="openwire.html">
OpenWire
</a>
</li>
<li class="chapter " data-level="1.16" data-path="core.html">
<a href="core.html">
Core
</a>
</li>
<li class="chapter " data-level="1.17" data-path="jms-core-mapping.html">
<a href="jms-core-mapping.html">
Mapping JMS Concepts to the Core API
</a>
</li>
<li class="chapter " data-level="1.18" data-path="using-jms.html">
<a href="using-jms.html">
Using JMS
</a>
</li>
<li class="chapter " data-level="1.19" data-path="client-classpath.html">
<a href="client-classpath.html">
The Client Classpath
</a>
</li>
<li class="chapter " data-level="1.20" data-path="examples.html">
<a href="examples.html">
Examples
</a>
</li>
<li class="chapter " data-level="1.21" data-path="wildcard-routing.html">
<a href="wildcard-routing.html">
Routing Messages With Wild Cards
</a>
</li>
<li class="chapter " data-level="1.22" data-path="wildcard-syntax.html">
<a href="wildcard-syntax.html">
Wildcard Syntax
</a>
</li>
<li class="chapter " data-level="1.23" data-path="filter-expressions.html">
<a href="filter-expressions.html">
Filter Expressions
</a>
</li>
<li class="chapter active" data-level="1.24" data-path="persistence.html">
<a href="persistence.html">
Persistence
</a>
</li>
<li class="chapter " data-level="1.25" data-path="configuring-transports.html">
<a href="configuring-transports.html">
Configuring Transports
</a>
</li>
<li class="chapter " data-level="1.26" data-path="config-reload.html">
<a href="config-reload.html">
Configuration Reload
</a>
</li>
<li class="chapter " data-level="1.27" data-path="connection-ttl.html">
<a href="connection-ttl.html">
Detecting Dead Connections
</a>
</li>
<li class="chapter " data-level="1.28" data-path="slow-consumers.html">
<a href="slow-consumers.html">
Detecting Slow Consumers
</a>
</li>
<li class="chapter " data-level="1.29" data-path="network-isolation.html">
<a href="network-isolation.html">
Avoiding Network Isolation
</a>
</li>
<li class="chapter " data-level="1.30" data-path="critical-analysis.html">
<a href="critical-analysis.html">
Detecting Broker Issues (Critical Analysis)
</a>
</li>
<li class="chapter " data-level="1.31" data-path="transaction-config.html">
<a href="transaction-config.html">
Resource Manager Configuration
</a>
</li>
<li class="chapter " data-level="1.32" data-path="flow-control.html">
<a href="flow-control.html">
Flow Control
</a>
</li>
<li class="chapter " data-level="1.33" data-path="send-guarantees.html">
<a href="send-guarantees.html">
Guarantees of sends and commits
</a>
</li>
<li class="chapter " data-level="1.34" data-path="undelivered-messages.html">
<a href="undelivered-messages.html">
Message Redelivery and Undelivered Messages
</a>
</li>
<li class="chapter " data-level="1.35" data-path="message-expiry.html">
<a href="message-expiry.html">
Message Expiry
</a>
</li>
<li class="chapter " data-level="1.36" data-path="large-messages.html">
<a href="large-messages.html">
Large Messages
</a>
</li>
<li class="chapter " data-level="1.37" data-path="paging.html">
<a href="paging.html">
Paging
</a>
</li>
<li class="chapter " data-level="1.38" data-path="scheduled-messages.html">
<a href="scheduled-messages.html">
Scheduled Messages
</a>
</li>
<li class="chapter " data-level="1.39" data-path="last-value-queues.html">
<a href="last-value-queues.html">
Last-Value Queues
</a>
</li>
<li class="chapter " data-level="1.40" data-path="ring-queues.html">
<a href="ring-queues.html">
Ring Queues
</a>
</li>
<li class="chapter " data-level="1.41" data-path="retroactive-addresses.html">
<a href="retroactive-addresses.html">
Retroactive Addresses
</a>
</li>
<li class="chapter " data-level="1.42" data-path="exclusive-queues.html">
<a href="exclusive-queues.html">
Exclusive Queues
</a>
</li>
<li class="chapter " data-level="1.43" data-path="message-grouping.html">
<a href="message-grouping.html">
Message Grouping
</a>
</li>
<li class="chapter " data-level="1.44" data-path="consumer-priority.html">
<a href="consumer-priority.html">
Consumer Priority
</a>
</li>
<li class="chapter " data-level="1.45" data-path="pre-acknowledge.html">
<a href="pre-acknowledge.html">
Extra Acknowledge Modes
</a>
</li>
<li class="chapter " data-level="1.46" data-path="management.html">
<a href="management.html">
Management
</a>
</li>
<li class="chapter " data-level="1.47" data-path="management-console.html">
<a href="management-console.html">
Management Console
</a>
</li>
<li class="chapter " data-level="1.48" data-path="metrics.html">
<a href="metrics.html">
Metrics
</a>
</li>
<li class="chapter " data-level="1.49" data-path="security.html">
<a href="security.html">
Security
</a>
</li>
<li class="chapter " data-level="1.50" data-path="masking-passwords.html">
<a href="masking-passwords.html">
Masking Passwords
</a>
</li>
<li class="chapter " data-level="1.51" data-path="broker-plugins.html">
<a href="broker-plugins.html">
Broker Plugins
</a>
</li>
<li class="chapter " data-level="1.52" data-path="resource-limits.html">
<a href="resource-limits.html">
Resource Limits
</a>
</li>
<li class="chapter " data-level="1.53" data-path="jms-bridge.html">
<a href="jms-bridge.html">
The JMS Bridge
</a>
</li>
<li class="chapter " data-level="1.54" data-path="client-reconnection.html">
<a href="client-reconnection.html">
Client Reconnection and Session Reattachment
</a>
</li>
<li class="chapter " data-level="1.55" data-path="diverts.html">
<a href="diverts.html">
Diverting and Splitting Message Flows
</a>
</li>
<li class="chapter " data-level="1.56" data-path="core-bridges.html">
<a href="core-bridges.html">
Core Bridges
</a>
</li>
<li class="chapter " data-level="1.57" data-path="transformers.html">
<a href="transformers.html">
Transformers
</a>
</li>
<li class="chapter " data-level="1.58" data-path="duplicate-detection.html">
<a href="duplicate-detection.html">
Duplicate Message Detection
</a>
</li>
<li class="chapter " data-level="1.59" data-path="clusters.html">
<a href="clusters.html">
Clusters
</a>
</li>
<li class="chapter " data-level="1.60" data-path="federation.html">
<a href="federation.html">
Federation
</a>
<ul class="articles">
<li class="chapter " data-level="1.60.1" data-path="federation-address.html">
<a href="federation-address.html">
Address Federation
</a>
</li>
<li class="chapter " data-level="1.60.2" data-path="federation-queue.html">
<a href="federation-queue.html">
Queue Federation
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.61" data-path="ha.html">
<a href="ha.html">
High Availability and Failover
</a>
</li>
<li class="chapter " data-level="1.62" data-path="graceful-shutdown.html">
<a href="graceful-shutdown.html">
Graceful Server Shutdown
</a>
</li>
<li class="chapter " data-level="1.63" data-path="libaio.html">
<a href="libaio.html">
Libaio Native Libraries
</a>
</li>
<li class="chapter " data-level="1.64" data-path="thread-pooling.html">
<a href="thread-pooling.html">
Thread management
</a>
</li>
<li class="chapter " data-level="1.65" data-path="web-server.html">
<a href="web-server.html">
Embedded Web Server
</a>
</li>
<li class="chapter " data-level="1.66" data-path="logging.html">
<a href="logging.html">
Logging
</a>
</li>
<li class="chapter " data-level="1.67" data-path="rest.html">
<a href="rest.html">
REST Interface
</a>
</li>
<li class="chapter " data-level="1.68" data-path="embedding-activemq.html">
<a href="embedding-activemq.html">
Embedding the Broker
</a>
</li>
<li class="chapter " data-level="1.69" data-path="karaf.html">
<a href="karaf.html">
Apache Karaf
</a>
</li>
<li class="chapter " data-level="1.70" data-path="tomcat.html">
<a href="tomcat.html">
Apache Tomcat
</a>
</li>
<li class="chapter " data-level="1.71" data-path="spring-integration.html">
<a href="spring-integration.html">
Spring Integration
</a>
</li>
<li class="chapter " data-level="1.72" data-path="cdi-integration.html">
<a href="cdi-integration.html">
CDI Integration
</a>
</li>
<li class="chapter " data-level="1.73" data-path="intercepting-operations.html">
<a href="intercepting-operations.html">
Intercepting Operations
</a>
</li>
<li class="chapter " data-level="1.74" data-path="data-tools.html">
<a href="data-tools.html">
Data Tools
</a>
</li>
<li class="chapter " data-level="1.75" data-path="maven-plugin.html">
<a href="maven-plugin.html">
Maven Plugin
</a>
</li>
<li class="chapter " data-level="1.76" data-path="unit-testing.html">
<a href="unit-testing.html">
Unit Testing
</a>
</li>
<li class="chapter " data-level="1.77" data-path="perf-tuning.html">
<a href="perf-tuning.html">
Troubleshooting and Performance Tuning
</a>
</li>
<li class="chapter " data-level="1.78" data-path="configuration-index.html">
<a href="configuration-index.html">
Configuration Reference
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >Persistence</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="persistence">Persistence</h1>
<p>Apache ActiveMQ Artemis ships with two persistence options. The file journal which is
highly optimized for the messaging use case and gives great performance, and also the
JDBC Store, which uses JDBC to connect to a database of your choice. The JDBC Store is
still under development, but it is possible to use its journal features, (essentially
everything except for paging and large messages).</p>
<h2 id="file-journal-default">File Journal (Default)</h2>
<p>The file journal is an <em>append only</em> journal. It consists of a set of
files on disk. Each file is pre-created to a fixed size and initially
filled with padding. As operations are performed on the server, e.g. add
message, update message, delete message, records are appended to the
journal. When one journal file is full we move to the next one.</p>
<p>Because records are only appended, i.e. added to the end of the journal
we minimise disk head movement, i.e. we minimise random access
operations which is typically the slowest operation on a disk.</p>
<p>Making the file size configurable means that an optimal size can be
chosen, i.e. making each file fit on a disk cylinder. Modern disk
topologies are complex and we are not in control over which cylinder(s)
the file is mapped onto so this is not an exact science. But by
minimising the number of disk cylinders the file is using, we can
minimise the amount of disk head movement, since an entire disk cylinder
is accessible simply by the disk rotating - the head does not have to
move.</p>
<p>As delete records are added to the journal, Apache ActiveMQ Artemis has a sophisticated
file garbage collection algorithm which can determine if a particular
journal file is needed any more - i.e. has all its data been deleted in
the same or other files. If so, the file can be reclaimed and re-used.</p>
<p>Apache ActiveMQ Artemis also has a compaction algorithm which removes dead space from
the journal and compresses up the data so it takes up less files on
disk.</p>
<p>The journal also fully supports transactional operation if required,
supporting both local and XA transactions.</p>
<p>The majority of the journal is written in Java, however we abstract out
the interaction with the actual file system to allow different pluggable
implementations. Apache ActiveMQ Artemis ships with two implementations:</p>
<h3 id="java-nio">Java <a href="https://en.wikipedia.org/wiki/New_I/O" target="_blank">NIO</a></h3>
<p>The first implementation uses standard Java NIO to interface with
the file system. This provides extremely good performance and runs
on any platform where there&apos;s a Java 6+ runtime.</p>
<h3 id="linux-asynchronous-io">Linux Asynchronous IO</h3>
<p>The second implementation uses a thin native code wrapper to talk to
the Linux asynchronous IO library (AIO). With AIO, Apache ActiveMQ Artemis will be
called back when the data has made it to disk, allowing us to avoid
explicit syncs altogether and simply send back confirmation of
completion when AIO informs us that the data has been persisted.</p>
<p>Using AIO will typically provide even better performance than using Java NIO.</p>
<p>This journal option is only available when running Linux kernel 2.6 or
later and after having installed libaio (if it&apos;s not already
installed). For instructions on how to install libaio please see Installing AIO section.</p>
<p>Also, please note that AIO will only work with the following file
systems: ext2, ext3, ext4, jfs, xfs and NFSV4.</p>
<p>For more information on libaio please see <a href="libaio.html">lib AIO</a>.</p>
<p>libaio is part of the kernel project.</p>
<h3 id="memory-mapped"><a href="https://en.wikipedia.org/wiki/Memory-mapped_file" target="_blank">Memory mapped</a></h3>
<p>The third implementation uses a file-backed <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.MapMode.html#READ_WRITE" target="_blank">READ_WRITE</a>
memory mapping against the OS page cache to interface with the file system.</p>
<p>This provides extremely good performance (especially under strictly process failure durability requirements),
almost zero copy (actually <em>is</em> the kernel page cache) and zero garbage (from the Java HEAP perspective) operations and runs
on any platform where there&apos;s a Java 4+ runtime.</p>
<p>Under power failure durability requirements it will perform at least on par with the NIO journal with the only
exception of Linux OS with kernel less or equals 2.6, in which the <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/MappedByteBuffer.html#force%28%29" target="_blank"><em>msync</em></a>) implementation necessary to ensure
durable writes was different (and slower) from the <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.html#force%28boolean%29" target="_blank"><em>fsync</em></a> used is case of NIO journal.</p>
<p>It benefits by the configuration of OS <a href="https://en.wikipedia.org/wiki/Page_%28computer_memory%29" target="_blank">huge pages</a>,
in particular when is used a big number of journal files and sizing them as multiple of the OS page size in bytes. </p>
<h3 id="standard-files">Standard Files</h3>
<p>The standard Apache ActiveMQ Artemis core server uses two instances of the journal:</p>
<ul>
<li><p>Bindings journal.</p>
<p>This journal is used to store bindings related data. That includes
the set of queues that are deployed on the server and their
attributes. It also stores data such as id sequence counters.</p>
<p>The bindings journal is always a NIO journal as it is typically low
throughput compared to the message journal.</p>
<p>The files on this journal are prefixed as <code>activemq-bindings</code>. Each
file has a <code>bindings</code> extension. File size is <code>1048576</code>, and it is
located at the bindings folder.</p>
</li>
<li><p>Message journal.</p>
<p>This journal instance stores all message related data, including the
message themselves and also duplicate-id caches.</p>
<p>By default Apache ActiveMQ Artemis will try and use an AIO journal. If AIO is not
available, e.g. the platform is not Linux with the correct kernel
version or AIO has not been installed then it will automatically
fall back to using Java NIO which is available on any Java platform.</p>
<p>The files on this journal are prefixed as <code>activemq-data</code>. Each file
has an <code>amq</code> extension. File size is by the default <code>10485760</code>
(configurable), and it is located at the journal folder.</p>
</li>
</ul>
<p>For large messages, Apache ActiveMQ Artemis persists them outside the message journal.
This is discussed in <a href="large-messages.html">Large Messages</a>.</p>
<p>Apache ActiveMQ Artemis can also be configured to page messages to disk in low memory
situations. This is discussed in <a href="paging.html">Paging</a>.</p>
<p>If no persistence is required at all, Apache ActiveMQ Artemis can also be configured
not to persist any data at all to storage as discussed in the Configuring
the broker for Zero Persistence section.</p>
<h4 id="configuring-the-bindings-journal">Configuring the bindings journal</h4>
<p>The bindings journal is configured using the following attributes in
<code>broker.xml</code></p>
<ul>
<li><p><code>bindings-directory</code></p>
<p>This is the directory in which the bindings journal lives. The
default value is <code>data/bindings</code>.</p>
</li>
<li><p><code>create-bindings-dir</code></p>
<p>If this is set to <code>true</code> then the bindings directory will be
automatically created at the location specified in
<code>bindings-directory</code> if it does not already exist. The default value
is <code>true</code></p>
</li>
</ul>
<h4 id="configuring-the-jms-journal">Configuring the jms journal</h4>
<p>The jms config shares its configuration with the bindings journal.</p>
<h4 id="configuring-the-message-journal">Configuring the message journal</h4>
<p>The message journal is configured using the following attributes in
<code>broker.xml</code></p>
<ul>
<li><p><code>journal-directory</code></p>
<p>This is the directory in which the message journal lives. The
default value is <code>data/journal</code>.</p>
<p>For the best performance, we recommend the journal is located on its
own physical volume in order to minimise disk head movement. If the
journal is on a volume which is shared with other processes which
might be writing other files (e.g. bindings journal, database, or
transaction coordinator) then the disk head may well be moving
rapidly between these files as it writes them, thus drastically
reducing performance.</p>
<p>When the message journal is stored on a SAN we recommend each
journal instance that is stored on the SAN is given its own LUN
(logical unit).</p>
</li>
<li><p><code>node-manager-lock-directory</code></p>
<p> This is the directory in which the node manager file lock lives. By default
has the same value of <code>journal-directory</code>.</p>
<p> This is useful when the message journal is on a SAN and is being used a <a href="ha.html#shared-store">Shared Store HA</a>
policy with the broker instances on the same physical machine.</p>
</li>
<li><p><code>create-journal-dir</code></p>
<p>If this is set to <code>true</code> then the journal directory will be
automatically created at the location specified in
<code>journal-directory</code> if it does not already exist. The default value
is <code>true</code></p>
</li>
<li><p><code>journal-type</code></p>
<p>Valid values are <code>NIO</code>, <code>ASYNCIO</code> or <code>MAPPED</code>.</p>
<p>Choosing <code>NIO</code> chooses the Java NIO journal. Choosing <code>ASYNCIO</code> chooses
the Linux asynchronous IO journal. If you choose <code>ASYNCIO</code> but are not
running Linux or you do not have libaio installed then Apache ActiveMQ Artemis will
detect this and automatically fall back to using <code>NIO</code>.
Choosing <code>MAPPED</code> chooses the Java Memory Mapped journal.</p>
</li>
<li><p><code>journal-sync-transactional</code></p>
<p>If this is set to true then Apache ActiveMQ Artemis will make sure all transaction
data is flushed to disk on transaction boundaries (commit, prepare
and rollback). The default value is <code>true</code>.</p>
</li>
<li><p><code>journal-sync-non-transactional</code></p>
<p>If this is set to true then Apache ActiveMQ Artemis will make sure non
transactional message data (sends and acknowledgements) are flushed
to disk each time. The default value for this is <code>true</code>.</p>
</li>
<li><p><code>journal-file-size</code></p>
<p>The size of each journal file in bytes. The default value for this
is <code>10485760</code> bytes (10MiB).</p>
</li>
<li><p><code>journal-min-files</code></p>
<p>The minimum number of files the journal will maintain. When Apache ActiveMQ Artemis
starts and there is no initial message data, Apache ActiveMQ Artemis will
pre-create <code>journal-min-files</code> number of files.</p>
<p>Creating journal files and filling them with padding is a fairly
expensive operation and we want to minimise doing this at run-time
as files get filled. By pre-creating files, as one is filled the
journal can immediately resume with the next one without pausing to
create it.</p>
<p>Depending on how much data you expect your queues to contain at
steady state you should tune this number of files to match that
total amount of data.</p>
</li>
<li><p><code>journal-pool-files</code></p>
<p>The system will create as many files as needed however when reclaiming files
it will shrink back to the <code>journal-pool-files</code>.</p>
<p>The default to this parameter is -1, meaning it will never delete files on the journal once created.</p>
<p>Notice that the system can&apos;t grow infinitely as you are still required to use paging for destinations that can
grow indefinitely.</p>
<p>Notice: in case you get too many files you can use <a href="data-tools.html">compacting</a>.</p>
</li>
<li><p><code>journal-max-io</code></p>
<p>Write requests are queued up before being submitted to the system
for execution. This parameter controls the maximum number of write
requests that can be in the IO queue at any one time. If the queue
becomes full then writes will block until space is freed up.</p>
<p>When using NIO, this value should always be equal to <code>1</code></p>
<p>When using ASYNCIO, the default should be <code>500</code>.</p>
<p>The system maintains different defaults for this parameter depending
on whether it&apos;s NIO or ASYNCIO (default for NIO is 1, default for ASYNCIO is
500)</p>
<p>There is a limit and the total max ASYNCIO can&apos;t be higher than what is
configured at the OS level (/proc/sys/fs/aio-max-nr) usually at
65536.</p>
</li>
<li><p><code>journal-buffer-timeout</code></p>
<p>Instead of flushing on every write that requires a flush, we
maintain an internal buffer, and flush the entire buffer either when
it is full, or when a timeout expires, whichever is sooner. This is
used for both NIO and ASYNCIO and allows the system to scale better with
many concurrent writes that require flushing.</p>
<p>This parameter controls the timeout at which the buffer will be
flushed if it hasn&apos;t filled already. ASYNCIO can typically cope with a
higher flush rate than NIO, so the system maintains different
defaults for both NIO and ASYNCIO (default for NIO is 3333333
nanoseconds - 300 times per second, default for ASYNCIO is 500000
nanoseconds - ie. 2000 times per second).</p>
<p>Setting this property to 0 will disable the internal buffer and writes will
be directly written to the journal file immediately.</p>
<blockquote>
<p><strong>Note:</strong></p>
<p>By increasing the timeout, you may be able to increase system
throughput at the expense of latency, the default parameters are
chosen to give a reasonable balance between throughput and
latency.</p>
</blockquote>
</li>
<li><p><code>journal-buffer-size</code></p>
<p>The size of the timed buffer on ASYNCIO. The default value is <code>490KiB</code>.</p>
</li>
<li><p><code>journal-compact-min-files</code></p>
<p>The minimal number of files before we can consider compacting the
journal. The compacting algorithm won&apos;t start until you have at
least <code>journal-compact-min-files</code></p>
<p>Setting this to 0 will disable the feature to compact completely.
This could be dangerous though as the journal could grow indefinitely.
Use it wisely!</p>
<p>The default for this parameter is <code>10</code></p>
</li>
<li><p><code>journal-compact-percentage</code></p>
<p>The threshold to start compacting. When less than this percentage is
considered live data, we start compacting. Note also that compacting
won&apos;t kick in until you have at least <code>journal-compact-min-files</code>
data files on the journal</p>
<p>The default for this parameter is <code>30</code></p>
</li>
<li><p><code>journal-datasync</code> (default: true)</p>
<p>This will disable the use of fdatasync on journal writes.
When enabled it ensures full power failure durability, otherwise
process failure durability on journal writes (OS guaranteed).
This is particular effective for <code>NIO</code> and <code>MAPPED</code> journals, which rely on
<em>fsync</em>/<em>msync</em> to force write changes to disk.</p>
</li>
</ul>
<h4 id="note-on-disabling-journal-datasync">Note on disabling <code>journal-datasync</code></h4>
<blockquote>
<p>Any modern OS guarantees that on process failures (i.e. crash) all the uncommitted changes
to the page cache will be flushed to the file system, maintaining coherence between
subsequent operations against the same pages and ensuring that no data will be lost.
The predictability of the timing of such flushes, in case of a disabled <em>journal-datasync</em>,
depends on the OS configuration, but without compromising (or relaxing) the process
failure durability semantics as described above.
Rely on the OS page cache sacrifice the power failure protection, while increasing the
effectiveness of the journal operations, capable of exploiting
the read caching and write combining features provided by the OS&apos;s kernel page cache subsystem.</p>
</blockquote>
<h3 id="note-on-disabling-disk-write-cache">Note on disabling disk write cache</h3>
<blockquote>
<p><strong>Warning</strong></p>
<p>Most disks contain hardware write caches. A write cache can increase
the apparent performance of the disk because writes just go into the
cache and are then lazily written to the disk later.</p>
<p>This happens irrespective of whether you have executed a fsync() from
the operating system or correctly synced data from inside a Java
program!</p>
<p>By default many systems ship with disk write cache enabled. This means
that even after syncing from the operating system there is no
guarantee the data has actually made it to disk, so if a failure
occurs, critical data can be lost.</p>
<p>Some more expensive disks have non volatile or battery backed write
caches which won&apos;t necessarily lose data on event of failure, but you
need to test them!</p>
<p>If your disk does not have an expensive non volatile or battery backed
cache and it&apos;s not part of some kind of redundant array (e.g. RAID),
and you value your data integrity you need to make sure disk write
cache is disabled.</p>
<p>Be aware that disabling disk write cache can give you a nasty shock
performance wise. If you&apos;ve been used to using disks with write cache
enabled in their default setting, unaware that your data integrity
could be compromised, then disabling it will give you an idea of how
fast your disk can perform when acting really reliably.</p>
<p>On Linux you can inspect and/or change your disk&apos;s write cache
settings using the tools <code>hdparm</code> (for IDE disks) or <code>sdparm</code> or
<code>sginfo</code> (for SDSI/SATA disks)</p>
<p>On Windows you can check / change the setting by right clicking on the
disk and clicking properties.</p>
</blockquote>
<h3 id="installing-aio">Installing AIO</h3>
<p>The Java NIO journal gives great performance, but If you are running
Apache ActiveMQ Artemis using Linux Kernel 2.6 or later, we highly recommend you use
the <code>ASYNCIO</code> journal for the very best persistence performance.</p>
<p>It&apos;s not possible to use the ASYNCIO journal under other operating systems
or earlier versions of the Linux kernel.</p>
<p>If you are running Linux kernel 2.6 or later and don&apos;t already have
<code>libaio</code> installed, you can easily install it using the following steps:</p>
<p>Using yum, (e.g. on Fedora or Red Hat Enterprise Linux):</p>
<pre><code class="lang-sh">yum install libaio
</code></pre>
<p>Using aptitude, (e.g. on Ubuntu or Debian system):</p>
<pre><code class="lang-sh">apt-get install libaio
</code></pre>
<h2 id="jdbc-persistence">JDBC Persistence</h2>
<p>WARNING: The Apache ActiveMQ Artemis JDBC persistence store is under development and is included for evaluation purposes.</p>
<p>The Apache ActiveMQ Artemis JDBC persistence layer offers the ability to store broker state (Messages, Addresses and other
application state) using a database. N.B. Address full policy Paging (See: <a href="paging.html">The section on Paging</a>) is currently not
supported with the JDBC persistence layer.</p>
<p>Using the ActiveMQ Artemis File Journal is the recommended configuration as it offers higher levels of performance and is
more mature. The JDBC persistence layer is targeted to those users who must use a database e.g. due to internal company
policy.</p>
<p>ActiveMQ Artemis currently has support for a limited number of database vendors (older versions may work but mileage may
vary):</p>
<ol>
<li>PostgreSQL 9.4.x</li>
<li>MySQL 5.7.x</li>
<li>Apache Derby 10.11.1.1</li>
</ol>
<p>The JDBC store uses a JDBC connection to store messages and bindings data in records in database tables. The data stored
in the database tables is encoded using Apache ActiveMQ Artemis internal encodings.</p>
<h3 id="configuring-jdbc-persistence">Configuring JDBC Persistence</h3>
<p>To configure Apache ActiveMQ Artemis to use a database for persisting messages and bindings data you must do two things.</p>
<ol>
<li><p>See the documentation on <a href="using-server.html">adding runtime dependencies</a> to
understand how to make the JDBC driver available to the broker.</p>
</li>
<li><p>Create a store element in your broker.xml config file under the <code>&lt;core&gt;</code> element. For example:</p>
</li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">store</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">database-store</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">jdbc-connection-url</span>&gt;</span>jdbc:derby:data/derby/database-store;create=true<span class="hljs-tag">&lt;/<span class="hljs-name">jdbc-connection-url</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">bindings-table-name</span>&gt;</span>BINDINGS_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">bindings-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">message-table-name</span>&gt;</span>MESSAGE_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">message-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">page-store-table-name</span>&gt;</span>MESSAGE_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">page-store-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">large-message-table-name</span>&gt;</span>LARGE_MESSAGES_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">large-message-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">node-manager-store-table-name</span>&gt;</span>NODE_MANAGER_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">node-manager-store-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">jdbc-driver-class-name</span>&gt;</span>org.apache.derby.jdbc.EmbeddedDriver<span class="hljs-tag">&lt;/<span class="hljs-name">jdbc-driver-class-name</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">database-store</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">store</span>&gt;</span>
</code></pre>
<ul>
<li><p><code>jdbc-connection-url</code></p>
<p>The full JDBC connection URL for your database server. The connection url should include all configuration parameters and database name. <strong>Note:</strong> When configuring the server using the XML configuration files please ensure to escape any illegal chars; &quot;&amp;&quot; for example, is typical in JDBC connection url and should be escaped to &quot;&amp;&quot;.</p>
</li>
<li><p><code>bindings-table-name</code></p>
<p>The name of the table in which bindings data will be persisted for the ActiveMQ Artemis server. Specifying table names allows users to share single database amongst multiple servers, without interference.</p>
</li>
<li><p><code>message-table-name</code></p>
<p>The name of the table in which bindings data will be persisted for the ActiveMQ Artemis server. Specifying table names allows users to share single database amongst multiple servers, without interference.</p>
</li>
<li><p><code>large-message-table-name</code></p>
<p>The name of the table in which messages and related data will be persisted for the ActiveMQ Artemis server. Specifying table names allows users to share single database amongst multiple servers, without interference.</p>
</li>
<li><p><code>page-store-table-name</code></p>
<p>The name of the table to house the page store directory information. Note that each address will have its own page table which will use this name appended with a unique id of up to 20 characters.</p>
</li>
<li><p><code>node-manager-store-table-name</code></p>
<p>The name of the table in which the HA Shared Store locks (ie live and backup) and HA related data will be persisted for the ActiveMQ Artemis server. Specifying table names allows users to share single database amongst multiple servers, without interference.
Each Shared Store live/backup pairs must use the same table name and isn&apos;t supported to share the same table between multiple (and unrelated) live/backup pairs.</p>
</li>
<li><p><code>jdbc-driver-class-name</code></p>
<p>The fully qualified class name of the desired database Driver.</p>
</li>
<li><p><code>jdbc-network-timeout</code></p>
<p>The JDBC network connection timeout in milliseconds. The default value
is 20000 milliseconds (ie 20 seconds).
When using a shared store it is recommended to set it less then or equal to <code>jdbc-lock-expiration</code>.</p>
</li>
<li><p><code>jdbc-lock-renew-period</code></p>
<p>The period in milliseconds of the keep alive service of a JDBC lock. The default value
is 2000 milliseconds (ie 2 seconds).</p>
</li>
<li><p><code>jdbc-lock-expiration</code></p>
<p>The time in milliseconds a JDBC lock is considered valid without keeping it alive. The default value
is 20000 milliseconds (ie 20 seconds).</p>
</li>
<li><p><code>jdbc-journal-sync-period</code></p>
<p>The time in milliseconds the journal will be synced with JDBC. The default value is 5 milliseconds.</p>
</li>
</ul>
<p>Note that some DBMS (e.g. Oracle, 30 chars) have restrictions on the size of table names, this should be taken into consideration when configuring table names for the Artemis database store, pay particular attention to the page store table name, which can be appended with a unique ID of up to 20 characters. (for Oracle this would mean configuring a page-store-table-name of max size of 10 chars).</p>
<p>It is also possible to explicitly add the user and password rather than in the JDBC url if you need to encode it, this would look like:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">store</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">database-store</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">jdbc-connection-url</span>&gt;</span>jdbc:derby:data/derby/database-store;create=true<span class="hljs-tag">&lt;/<span class="hljs-name">jdbc-connection-url</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">jdbc-user</span>&gt;</span>ENC(dasfn353cewc)<span class="hljs-tag">&lt;/<span class="hljs-name">jdbc-user</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">jdbc-password</span>&gt;</span>ENC(ucwiurfjtew345)<span class="hljs-tag">&lt;/<span class="hljs-name">jdbc-password</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">bindings-table-name</span>&gt;</span>BINDINGS_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">bindings-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">message-table-name</span>&gt;</span>MESSAGE_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">message-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">page-store-table-name</span>&gt;</span>MESSAGE_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">page-store-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">large-message-table-name</span>&gt;</span>LARGE_MESSAGES_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">large-message-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">node-manager-store-table-name</span>&gt;</span>NODE_MANAGER_TABLE<span class="hljs-tag">&lt;/<span class="hljs-name">node-manager-store-table-name</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">jdbc-driver-class-name</span>&gt;</span>org.apache.derby.jdbc.EmbeddedDriver<span class="hljs-tag">&lt;/<span class="hljs-name">jdbc-driver-class-name</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">database-store</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">store</span>&gt;</span>
</code></pre>
<h2 id="zero-persistence">Zero Persistence</h2>
<p>In some situations, zero persistence is sometimes required for a
messaging system. Configuring Apache ActiveMQ Artemis to perform zero persistence is
straightforward. Simply set the parameter <code>persistence-enabled</code> in
<code>broker.xml</code> to <code>false</code>.</p>
<p>Please note that if you set this parameter to false, then <em>zero</em>
persistence will occur. That means no bindings data, message data, large
message data, duplicate id caches or paging data will be persisted.</p>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="filter-expressions.html" class="navigation navigation-prev " aria-label="Previous page: Filter Expressions">
<i class="fa fa-angle-left"></i>
</a>
<a href="configuring-transports.html" class="navigation navigation-next " aria-label="Next page: Configuring Transports">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Persistence","level":"1.24","depth":1,"next":{"title":"Configuring Transports","level":"1.25","depth":1,"path":"configuring-transports.md","ref":"configuring-transports.md","articles":[]},"previous":{"title":"Filter Expressions","level":"1.23","depth":1,"path":"filter-expressions.md","ref":"filter-expressions.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"github":"apache/activemq-artemis","theme":"default","githubHost":"https://github.com/","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"ActiveMQ Artemis Documentation","links":{"home":"http://activemq.apache.org/artemis","issues":"https://issues.apache.org/jira/browse/ARTEMIS","contribute":"http://activemq.apache.org/contributing.html"},"gitbook":"3.x.x","description":"ActiveMQ Artemis User Guide and Reference Documentation"},"file":{"path":"persistence.md","mtime":"2020-03-31T18:40:48.000Z","type":"markdown"},"gitbook":{"version":"3.1.1","time":"2020-04-29T20:47:49.444Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="gitbook/gitbook-plugin-search/search.js"></script>
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>