[[Mesaging_AIO_-_NIO_for_messaging_journal]]
= AIO - NIO for messaging journal

ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]

Apache ActiveMQ Artemis (like HornetQ beforehand) ships with a *high
performance journal*. Since Apache ActiveMQ Artemis handles its own
persistence, rather than relying on a database or other 3rd party
persistence engine it is very highly optimised for the specific
messaging use cases. 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:

* *Java NIO.*

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's a Java 6+ runtime.

* *Linux Asynchronous IO*

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.

Using AIO will typically provide even better performance than using Java
NIO.

The AIO journal is only available when running Linux kernel 2.6 or later
and after having installed libaio (if it's not already installed). If AIO is
not supported on the system then Artemis will fallback to NIO. To know which
type of journal is effectively used you can execute the following command using jboss-cli:

[source,options="nowrap"]
----
/subsystem=messaging-activemq/server=default:read-attribute(name=runtime-journal-type)
----

Please note that AIO is represented by ASYNCIO in the WildFly model configuration.

Also, please note that AIO will only work with the following file
systems: ext2, ext3, ext4, jfs, xfs. With other file systems, e.g. NFS
it may appear to work, but it will fall back to a slower synchronous
behaviour. Don't put the journal on a NFS share!

*One point that should be added is that AIO doesn't work well with
encrypted partitions, thus you have to move to NIO on those.*

What are the symptoms of an AIO isssue ?

[[aio-issue-on-wildfly-10]]
== AIO issue on WildFly 10

If you see the following exception in your WildFly log file / console

....
[org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 64) AMQ222010: Critical IO Error, shutting down the server. file=AIOSequentialFile:/home/wildfly/wildfly-10.0.0.Final/standalone/data/activemq/journal/activemq-data-2.amq, message=Cannot open file:The Argument is invalid: java.io.IOException: Cannot open file:The Argument is invalid
 at org.apache.activemq.artemis.jlibaio.LibaioContext.open(Native Method)
....

that means that AIO isn't working properly on your system.

To use NIO instead execute the following command using jboss-cli:

[source,options="nowrap"]
----
/subsystem=messaging-activemq/server=default:write-attribute(name=journal-type, value=NIO)
----

You need to reload or restart your server and you should see the
following trace in your server console :

....
INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 64) AMQ221013: Using NIO Journal
....

[[aio-issue-on-wildfly-9]]
== AIO issue on WildFly 9

....
[org.hornetq.core.server] (ServerService Thread Pool -- 64) HQ222010: Critical IO Error, shutting down the server. file=AIOSequentialFile:/home/wildfly/wildfly-9.0.2.Final/standalone/data/messagingjournal/hornetq-data-1.hq, message=Can't open file: HornetQException[errorType=NATIVE_ERROR_CANT_OPEN_CLOSE_FILE message=Can't open file]
 at org.hornetq.core.libaio.Native.init(Native Method)
....

that means that AIO isn't working properly on your system.

To use NIO instead execute the following commnd using jboss-cli :

[source,options="nowrap"]
----
/subsystem=messaging/hornetq-server=default:write-attribute(name=journal-type,value=NIO)
----

You need to reload or restart your server and you see the following
trace in your server console :

....
INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 64) HQ221013: Using NIO Journal
....
