HornetQ Persistence Concepts: Difference between revisions
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
This article provides a high level overview of the HornetQ persistence concepts. It | This article provides a high level overview of the HornetQ persistence concepts. It describes what kind of data is persisted, as well as where and when. It will also discuss paging, which is a protection mechanism against running out of memory; persistence is relevant in this context because messages that do not fit in memory go to the filesystem, even if the messages themselves are marked as non-persistent. | ||
=There is No Database= | =There is No Database= |
Revision as of 23:47, 11 March 2016
Internal
Overview
This article provides a high level overview of the HornetQ persistence concepts. It describes what kind of data is persisted, as well as where and when. It will also discuss paging, which is a protection mechanism against running out of memory; persistence is relevant in this context because messages that do not fit in memory go to the filesystem, even if the messages themselves are marked as non-persistent.
There is No Database
Unlike other messaging systems, which do offer the option of storing message data in a relational database, HornetQ does not. For reasons that led to this decision see https://developer.jboss.org/thread/153581. More details in "Messaging persistence in EAP 6.x" https://access.redhat.com/solutions/226743.
What Does HornetQ Persist?
Naturally, HornetQ persists persistent messages, as required by the JMS specification. It also persists some topology information (bindings and JMS information). HornetQ allows sending large messages - a message can be larger than the total amount of memory available to a broker - by fragmenting the messages and storing the fragments on the filesystem, so large message storage is another type of persistence managed by HornetQ. Finally, HornetQ is capable of storing any message, including the non-persistent messages, on the filesystem, when the amount of memory available to the broker is not sufficient to allow handling all messages for a specific address in memory. This mechanism is known as paging and it is describe here.
Persistent Message Journal
All persistent messages must be stored on persistent storage, as mandated by the JMS specification. This is necessary to protect against messaging system failure: a persistent message can be presumably recovered from the persistent storage and re-sent.
HornetQ stores messages in an append-only file system journal, optimized for message-specific use cases. The journal consists of a set of fixed-size files. Initially, the files are filled with padding, which is progressively replaced with message data or deletes and transactional information. Duplicate ID caches are also stored here. When a journal file is full, the next one is used and so on. A garbage collection algorithm determines whether a specific file is needed or it can be re-used. HornetQ can also compact the space in the journal files.
$JBOSS_HOME/standalone/data/messagingjournal -rw-r--r--. 1 root root 10485760 Mar 7 03:11 hornetq-data-33.hq -rw-r--r--. 1 root root 10485760 Mar 7 03:25 hornetq-data-34.hq -rw-r--r--. 1 root root 10485760 Mar 7 03:09 hornetq-data-35.hq -rw-r--r--. 1 root root 10485760 Mar 11 16:43 hornetq-data-36.hq -rw-r--r--. 1 root root 19 Mar 11 16:43 server.lock
Disk Write Cache
- If disk write cache is enabled, and the cache memory is volatile (depending on the disk type), data can be lost on power failure even if HornetQ correctly synced data to disk.
Spinning Disks
A great deal of effort has been spent to optimize the journal for spinning hard drives. It's too bad that more and more of these are in process to be replaced with solid state drives, for which the head mechanics is irrelevant.
Journal Implementations
HornetQ ships with two journal implementations: pure Java, NIO-based and native Linux Asynchronous IO (AIO), available with Linux kernel 2.6 and higher. With AIO, HornetQ is called back when the data was written on disk, thus allowing it to avoid explicit syncs.
More details are available here:
Node ID
When a node is started for the first time it persists a unique identifier into its journal directory. This ID is needed for proper formation of clusters.
Message Journal Configuration
Bindings Journal
This is a relatively low-throughput journal (if compared to the message journal) used to store core queue data and id sequence counters:
$JBOSS_HOME/standalone/data/messagingbindings: -rw-r--r--. 1 root root 1048576 Mar 11 16:43 hornetq-bindings-1.bindings -rw-r--r--. 1 root root 1048576 Mar 11 16:43 hornetq-bindings-2.bindings
The implementation is always NIO.
Bindings Journal Configuration
JMS Journal
This is also a low-throughput journal used to store JMS-related data: JMS queues and topics, JMS ConnectionFactories, JNDI bindings:
$JBOSS_HOME/standalone/data/messagingbindings: -rw-r--r--. 1 root root 1048576 Mar 11 16:43 hornetq-jms-1.jms -rw-r--r--. 1 root root 1048576 Mar 11 16:43 hornetq-jms-2.jms
- Note that only the JMS resources created via the management interface will be persisted in this journal. The resources specified in configuration will not be persisted here.
JMS Journal Configuration
Large Messages
Non Persistent Messages
Even non-persistent messages will be written to storage when a specific address is configured for paging. For more details see:
Zero Persistence
No message data, bindings, etc. will be persisted.
... <persistence-enable>false</persistence-enabled> ...