activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/2] activemq-artemis git commit: ARTEMIS-937 Implementing proper alignment and adding perf-journal tool to validate the journal syncs
Date Fri, 03 Feb 2017 20:17:17 GMT
ARTEMIS-937 Implementing proper alignment and adding perf-journal tool to validate the journal syncs

(cherry picked from commit ce035a8084874da3004cded844221629a9a3bc2e)


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/6018b2d7
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/6018b2d7
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/6018b2d7

Branch: refs/heads/1.x
Commit: 6018b2d74cdc998013d918f0453c917ca00a855d
Parents: 53ef820
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Wed Feb 1 22:51:51 2017 -0500
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Fri Feb 3 15:15:58 2017 -0500

----------------------------------------------------------------------
 .../apache/activemq/artemis/cli/Artemis.java    |  4 +-
 .../activemq/artemis/cli/commands/Create.java   | 68 ++++++++++-----
 .../artemis/cli/commands/tools/PerfJournal.java | 92 ++++++++++++++++++++
 .../artemis/cli/commands/tools/SyncRecalc.java  | 55 ------------
 .../cli/commands/util/SyncCalculation.java      | 41 ++++++---
 .../apache/activemq/cli/test/ArtemisTest.java   | 37 +++++++-
 .../jdbc/store/file/JDBCSequentialFile.java     |  5 --
 .../store/file/JDBCSequentialFileFactory.java   |  6 ++
 .../journal/JMSJournalStorageManagerImpl.java   |  6 +-
 .../core/io/AbstractSequentialFileFactory.java  | 16 ++++
 .../artemis/core/io/SequentialFile.java         |  2 -
 .../artemis/core/io/SequentialFileFactory.java  |  2 +
 .../artemis/core/io/aio/AIOSequentialFile.java  | 10 +--
 .../core/io/aio/AIOSequentialFileFactory.java   | 37 ++++++--
 .../core/io/mapped/MappedSequentialFile.java    |  5 --
 .../io/mapped/MappedSequentialFileFactory.java  |  6 ++
 .../artemis/core/io/nio/NIOSequentialFile.java  |  5 --
 .../activemq/artemis/jlibaio/LibaioFile.java    |  4 +-
 .../artemis/core/config/Configuration.java      |  2 +-
 .../artemis/core/config/impl/Validators.java    |  4 +-
 .../deployers/impl/FileConfigurationParser.java | 11 +--
 .../impl/journal/JournalStorageManager.java     | 25 +++---
 .../artemis/core/server/JournalType.java        | 28 +++++-
 .../journal/AIOSequentialFileFactoryTest.java   |  2 +-
 .../journal/NIOImportExportTest.java            |  6 +-
 .../journal/NIOJournalCompactTest.java          |  2 +-
 .../unit/core/journal/impl/CleanBufferTest.java |  2 +-
 .../core/journal/impl/JournalImplTestUnit.java  |  3 +
 .../impl/SequentialFileFactoryTestBase.java     | 32 +++----
 .../impl/fakes/FakeSequentialFileFactory.java   | 13 +--
 30 files changed, 348 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
index 7bbb643..24e86f5 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
@@ -41,7 +41,7 @@ import org.apache.activemq.artemis.cli.commands.tools.DecodeJournal;
 import org.apache.activemq.artemis.cli.commands.tools.EncodeJournal;
 import org.apache.activemq.artemis.cli.commands.tools.HelpData;
 import org.apache.activemq.artemis.cli.commands.tools.PrintData;
-import org.apache.activemq.artemis.cli.commands.tools.SyncRecalc;
+import org.apache.activemq.artemis.cli.commands.tools.PerfJournal;
 import org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter;
 import org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter;
 import org.apache.activemq.artemis.cli.commands.user.AddUser;
@@ -137,7 +137,7 @@ public class Artemis {
             withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class);
          builder.withGroup("user").withDescription("default file-based user management (add|rm|list|reset) (example ./artemis user list)").
                  withDefaultCommand(HelpUser.class).withCommands(ListUser.class, AddUser.class, RemoveUser.class, ResetUser.class);
-         builder = builder.withCommands(Run.class, Stop.class, Kill.class, SyncRecalc.class);
+         builder = builder.withCommands(Run.class, Stop.class, Kill.class, PerfJournal.class);
       } else {
          builder.withGroup("data").withDescription("data tools group (print) (example ./artemis data print)").
             withDefaultCommand(HelpData.class).withCommands(PrintData.class);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
index 5de46e9..412626a 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
@@ -40,6 +40,7 @@ import io.airlift.airline.Option;
 import org.apache.activemq.artemis.cli.CLIException;
 import org.apache.activemq.artemis.cli.commands.util.HashUtil;
 import org.apache.activemq.artemis.cli.commands.util.SyncCalculation;
+import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
 import org.apache.activemq.artemis.jlibaio.LibaioContext;
 import org.apache.activemq.artemis.jlibaio.LibaioFile;
@@ -203,11 +204,14 @@ public class Create extends InputAbstract {
    @Option(name = "--topics", description = "comma separated list of jms topics ")
    String topics;
 
-   @Option(name = "--aio", description = "Force aio journal on the configuration regardless of the library being available or not.")
-   boolean forceLibaio;
+   @Option(name = "--aio", description = "sets the journal as asyncio.")
+   boolean aio;
 
-   @Option(name = "--nio", description = "Force nio journal on the configuration regardless of the library being available or not.")
-   boolean forceNIO;
+   @Option(name = "--nio", description = "sets the journal as nio.")
+   boolean nio;
+
+   // this is used by the setupJournalType method
+   private JournalType journalType;
 
    @Option(name = "--disable-persistence", description = "Disable message persistence to the journal")
    boolean disablePersistence;
@@ -520,15 +524,13 @@ public class Create extends InputAbstract {
          throw new RuntimeException(String.format("The path '%s' is not writable.", directory));
       }
    }
-
    public Object run(ActionContext context) throws Exception {
-      if (forceLibaio && forceNIO) {
-         throw new RuntimeException("You can't specify --nio and --aio in the same execution.");
-      }
 
       IS_WINDOWS = System.getProperty("os.name").toLowerCase().trim().startsWith("win");
       IS_CYGWIN = IS_WINDOWS && "cygwin".equals(System.getenv("OSTYPE"));
 
+      setupJournalType();
+
       // requireLogin should set alloAnonymous=false, to avoid user's questions
       if (requireLogin != null && requireLogin.booleanValue()) {
          allowAnonymous = Boolean.FALSE;
@@ -565,15 +567,7 @@ public class Create extends InputAbstract {
          filters.put("${shared-store.settings}", "");
       }
 
-      boolean aio;
-
-      if (IS_WINDOWS || !supportsLibaio()) {
-         aio = false;
-         filters.put("${journal.settings}", "NIO");
-      } else {
-         aio = true;
-         filters.put("${journal.settings}", "ASYNCIO");
-      }
+      filters.put("${journal.settings}", journalType.name());
 
       if (sslKey != null) {
          filters.put("${web.protocol}", "https");
@@ -761,6 +755,38 @@ public class Create extends InputAbstract {
       return null;
    }
 
+   private void setupJournalType() {
+      int countJournalTypes = countBoolean(aio, nio);
+      if (countJournalTypes > 1) {
+         throw new RuntimeException("You can only select one journal type (--nio | --aio | --mapped).");
+      }
+
+      if (countJournalTypes == 0) {
+         if (supportsLibaio()) {
+            aio = true;
+         } else {
+            nio = true;
+         }
+      }
+
+      if (aio) {
+         journalType = JournalType.ASYNCIO;
+      } else if (nio) {
+         journalType = JournalType.NIO;
+      }
+   }
+
+
+   private static int countBoolean(boolean...b) {
+      int count = 0;
+
+      for (boolean itemB : b) {
+         if (itemB) count++;
+      }
+
+      return count;
+   }
+
    private String getLogManager() throws IOException {
       String logManager = "";
       File dir = new File(path(getHome().toString(), false) + "/lib");
@@ -805,7 +831,7 @@ public class Create extends InputAbstract {
             System.out.println("");
             System.out.println("Auto tuning journal ...");
 
-            long time = SyncCalculation.syncTest(dataFolder, 4096, writes, 5, verbose, !noJournalSync, aio);
+            long time = SyncCalculation.syncTest(dataFolder, 4096, writes, 5, verbose, !noJournalSync, journalType);
             long nanoseconds = SyncCalculation.toNanos(time, writes, verbose);
             double writesPerMillisecond = (double) writes / (double) time;
 
@@ -829,11 +855,7 @@ public class Create extends InputAbstract {
    }
 
    public boolean supportsLibaio() {
-      if (forceLibaio) {
-         // forcing libaio
-         return true;
-      } else if (forceNIO) {
-         // forcing NIO
+      if (IS_WINDOWS) {
          return false;
       } else if (LibaioContext.isLoaded()) {
          try (LibaioContext context = new LibaioContext(1, true, true)) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PerfJournal.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PerfJournal.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PerfJournal.java
new file mode 100644
index 0000000..f7d89ec
--- /dev/null
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PerfJournal.java
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.cli.commands.tools;
+
+import java.text.DecimalFormat;
+
+import io.airlift.airline.Command;
+import io.airlift.airline.Option;
+import org.apache.activemq.artemis.cli.commands.ActionContext;
+import org.apache.activemq.artemis.cli.commands.util.SyncCalculation;
+import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
+import org.apache.activemq.artemis.core.server.JournalType;
+
+@Command(name = "perf-journal", description = "Calculates the journal-buffer-timeout you should use with the current data folder")
+public class PerfJournal extends LockAbstract {
+
+
+   @Option(name = "--block-size", description = "The block size for each write (default 4096)")
+   public int size = 4 * 1024;
+
+
+   @Option(name = "--writes", description = "The number of writes to be performed (default 250)")
+   public int writes = 250;
+
+   @Option(name = "--tries", description = "The number of tries for the test (default 5)")
+   public int tries = 5;
+
+   @Option(name = "--no-sync", description = "Disable sync")
+   public boolean nosyncs = false;
+
+   @Option(name = "--sync", description = "Enable syncs")
+   public boolean syncs = false;
+
+   @Option(name = "--journal-type", description = "Journal Type to be used (default from broker.xml)")
+   public String journalType = null;
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      super.execute(context);
+
+      FileConfiguration fileConfiguration = getFileConfiguration();
+
+      if (nosyncs) {
+         fileConfiguration.setJournalDatasync(false);
+      } else if (syncs) {
+         fileConfiguration.setJournalDatasync(true);
+      }
+
+
+      if (journalType != null) {
+         fileConfiguration.setJournalType(JournalType.getType(journalType));
+      }
+
+      System.out.println("");
+      System.out.println("Auto tuning journal ...");
+
+      System.out.println("Performing " + tries + " tests writing " + writes + " blocks of " + size + " on each test, sync=" + fileConfiguration.isJournalDatasync() + " with journalType = " + fileConfiguration.getJournalType());
+
+      fileConfiguration.getJournalLocation().mkdirs();
+
+      long time = SyncCalculation.syncTest(fileConfiguration.getJournalLocation(), size, writes, tries, verbose, fileConfiguration.isJournalDatasync(), fileConfiguration.getJournalType());
+
+      long nanosecondsWait = SyncCalculation.toNanos(time, writes, verbose);
+      double writesPerMillisecond = (double) writes / (double) time;
+
+      String writesPerMillisecondStr = new DecimalFormat("###.##").format(writesPerMillisecond);
+
+      context.out.println("Your system can execute " + writesPerMillisecondStr + " syncs per millisecond");
+      context.out.println("Your journal-buffer-timeout should be:" + nanosecondsWait);
+      context.out.println("You should use this following configuration:");
+      context.out.println();
+      context.out.println("<journal-buffer-timeout>" + nanosecondsWait + "</journal-buffer-timeout>");
+
+      return null;
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/SyncRecalc.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/SyncRecalc.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/SyncRecalc.java
deleted file mode 100644
index 3b0bc3d..0000000
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/SyncRecalc.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.activemq.artemis.cli.commands.tools;
-
-import java.text.DecimalFormat;
-
-import io.airlift.airline.Command;
-import org.apache.activemq.artemis.cli.commands.ActionContext;
-import org.apache.activemq.artemis.cli.commands.util.SyncCalculation;
-import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
-import org.apache.activemq.artemis.core.server.JournalType;
-
-@Command(name = "sync", description = "Calculates the journal-buffer-timeout you should use with the current data folder")
-public class SyncRecalc extends LockAbstract {
-
-   @Override
-   public Object execute(ActionContext context) throws Exception {
-      super.execute(context);
-
-      FileConfiguration fileConfiguration = getFileConfiguration();
-
-      int writes = 250;
-      System.out.println("");
-      System.out.println("Auto tuning journal ...");
-
-      long time = SyncCalculation.syncTest(fileConfiguration.getJournalLocation(), 4096, writes, 5, verbose, fileConfiguration.isJournalDatasync(), fileConfiguration.getJournalType() == JournalType.ASYNCIO);
-      long nanosecondsWait = SyncCalculation.toNanos(time, writes, verbose);
-      double writesPerMillisecond = (double) writes / (double) time;
-
-      String writesPerMillisecondStr = new DecimalFormat("###.##").format(writesPerMillisecond);
-
-      context.out.println("Your system can execute " + writesPerMillisecondStr + " syncs per millisecond");
-      context.out.println("Your journal-buffer-timeout should be:" + nanosecondsWait);
-      context.out.println("You should use this following configuration:");
-      context.out.println();
-      context.out.println("<journal-buffer-timeout>" + nanosecondsWait + "</journal-buffer-timeout>");
-
-      return null;
-   }
-}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/util/SyncCalculation.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/util/SyncCalculation.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/util/SyncCalculation.java
index 52ef87b..ae7a8ca 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/util/SyncCalculation.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/util/SyncCalculation.java
@@ -28,6 +28,8 @@ import org.apache.activemq.artemis.core.io.SequentialFile;
 import org.apache.activemq.artemis.core.io.SequentialFileFactory;
 import org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory;
 import org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory;
+import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
+import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.jlibaio.LibaioContext;
 import org.apache.activemq.artemis.utils.ReusableLatch;
 
@@ -47,8 +49,8 @@ public class SyncCalculation {
                                int tries,
                                boolean verbose,
                                boolean fsync,
-                               boolean aio) throws Exception {
-      SequentialFileFactory factory = newFactory(datafolder, fsync, aio);
+                               JournalType journalType) throws Exception {
+      SequentialFileFactory factory = newFactory(datafolder, fsync, journalType, blockSize * blocks);
 
       if (verbose) {
          System.out.println("Using " + factory.getClass().getName() + " to calculate sync times");
@@ -61,6 +63,8 @@ public class SyncCalculation {
 
          file.fill(blockSize * blocks);
 
+         file.close();
+
          long[] result = new long[tries];
 
          byte[] block = new byte[blockSize];
@@ -94,6 +98,7 @@ public class SyncCalculation {
                System.out.println("**************************************************");
                System.out.println(ntry + " of " + tries + " calculation");
             }
+            file.open();
             file.position(0);
             long start = System.currentTimeMillis();
             for (int i = 0; i < blocks; i++) {
@@ -115,6 +120,7 @@ public class SyncCalculation {
                System.out.println("bufferTimeout = " + toNanos(result[ntry], blocks, verbose));
                System.out.println("**************************************************");
             }
+            file.close();
          }
 
          factory.releaseDirectBuffer(bufferBlock);
@@ -162,17 +168,26 @@ public class SyncCalculation {
       return timeWait;
    }
 
-   private static SequentialFileFactory newFactory(File datafolder, boolean datasync, boolean aio) {
-      if (aio && LibaioContext.isLoaded()) {
-         SequentialFileFactory factory = new AIOSequentialFileFactory(datafolder, 1).setDatasync(datasync);
-         factory.start();
-         ((AIOSequentialFileFactory) factory).disableBufferReuse();
-
-         return factory;
-      } else {
-         SequentialFileFactory factory = new NIOSequentialFileFactory(datafolder, 1);
-         factory.start();
-         return factory;
+   private static SequentialFileFactory newFactory(File datafolder, boolean datasync, JournalType journalType, int fileSize) {
+      SequentialFileFactory factory;
+
+      if (journalType == JournalType.ASYNCIO && !LibaioContext.isLoaded()) {
+         journalType = JournalType.NIO;
+      }
+
+      switch (journalType) {
+
+         case NIO:
+            factory = new NIOSequentialFileFactory(datafolder, 1);
+            factory.start();
+            return factory;
+         case ASYNCIO:
+            factory = new AIOSequentialFileFactory(datafolder, 1).setDatasync(datasync);
+            factory.start();
+            ((AIOSequentialFileFactory) factory).disableBufferReuse();
+            return factory;
+         default:
+            throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(journalType);
       }
    }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
index 7303dd8..7cd20be 100644
--- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
+++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
@@ -49,6 +49,7 @@ import org.apache.activemq.artemis.cli.commands.util.SyncCalculation;
 import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
 import org.apache.activemq.artemis.core.config.FileDeploymentManager;
 import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
+import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.jlibaio.LibaioContext;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
@@ -150,7 +151,7 @@ public class ArtemisTest {
    public void testSync() throws Exception {
       int writes = 20;
       int tries = 10;
-      long totalAvg = SyncCalculation.syncTest(temporaryFolder.getRoot(), 4096, writes, tries, true, true, true);
+      long totalAvg = SyncCalculation.syncTest(temporaryFolder.getRoot(), 4096, writes, tries, true, true, JournalType.NIO);
       System.out.println();
       System.out.println("TotalAvg = " + totalAvg);
       long nanoTime = SyncCalculation.toNanos(totalAvg, writes, false);
@@ -160,6 +161,26 @@ public class ArtemisTest {
    }
 
    @Test
+   public void testSimpleCreate() throws Exception {
+      //instance1: default using http
+      File instance1 = new File(temporaryFolder.getRoot(), "instance1");
+      Artemis.main("create", instance1.getAbsolutePath(), "--silent", "--no-fsync");
+   }
+
+
+   @Test
+   public void testSimpleCreateMapped() throws Throwable {
+      try {
+         //instance1: default using http
+         File instance1 = new File(temporaryFolder.getRoot(), "instance1");
+         Artemis.main("create", instance1.getAbsolutePath(), "--silent", "--mapped");
+      } catch (Throwable e) {
+         e.printStackTrace();
+         throw e;
+      }
+   }
+
+   @Test
    public void testWebConfig() throws Exception {
       setupAuth();
       Run.setEmbedded(true);
@@ -529,6 +550,20 @@ public class ArtemisTest {
    }
 
 
+   @Test
+   public void testPerfJournal() throws Exception {
+      File instanceFolder = temporaryFolder.newFolder("server1");
+      setupAuth(instanceFolder);
+
+      Run.setEmbedded(true);
+      Artemis.main("create", instanceFolder.getAbsolutePath(), "--force", "--silent", "--no-web", "--no-autotune", "--require-login");
+      System.setProperty("artemis.instance", instanceFolder.getAbsolutePath());
+
+      Artemis.main("perf-journal", "--journal-type", "NIO", "--writes", "5000", "--tries", "50", "--verbose");
+
+   }
+
+
    public void testSimpleRun(String folderName) throws Exception {
       File instanceFolder = temporaryFolder.newFolder(folderName);
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFile.java
----------------------------------------------------------------------
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFile.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFile.java
index 69ff11a..85c4877 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFile.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFile.java
@@ -119,11 +119,6 @@ public class JDBCSequentialFile implements SequentialFile {
    }
 
    @Override
-   public int getAlignment() throws Exception {
-      return 0;
-   }
-
-   @Override
    public int calculateBlockStart(int position) throws Exception {
       return 0;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFileFactory.java
----------------------------------------------------------------------
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFileFactory.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFileFactory.java
index 4b92c71..fa88a85 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFileFactory.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/JDBCSequentialFileFactory.java
@@ -177,6 +177,12 @@ public class JDBCSequentialFileFactory implements SequentialFileFactory, ActiveM
    }
 
    @Override
+   public JDBCSequentialFileFactory setAlignment(int alignment) {
+      // no op
+      return this;
+   }
+
+   @Override
    public int calculateBlockSize(final int bytes) {
       return bytes;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java
index 0aaa1a6..bc288db 100644
--- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java
+++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.jms.persistence.impl.journal;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -78,8 +79,9 @@ public final class JMSJournalStorageManagerImpl implements JMSStorageManager {
                                        final IDGenerator idGenerator,
                                        final Configuration config,
                                        final ReplicationManager replicator) {
-      if (config.getJournalType() != JournalType.NIO && config.getJournalType() != JournalType.ASYNCIO) {
-         throw new IllegalArgumentException("Only NIO and AsyncIO are supported journals");
+      final EnumSet<JournalType> supportedJournalTypes = EnumSet.allOf(JournalType.class);
+      if (!supportedJournalTypes.contains(config.getJournalType())) {
+         throw new IllegalArgumentException("Only " + supportedJournalTypes + " are supported Journal types");
       }
 
       this.config = config;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java
index 5aa723d..4310e84 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java
@@ -54,6 +54,8 @@ public abstract class AbstractSequentialFileFactory implements SequentialFileFac
 
    protected boolean dataSync = true;
 
+   protected volatile int alignment = -1;
+
    private final IOCriticalErrorListener critialErrorListener;
 
    /**
@@ -83,6 +85,20 @@ public abstract class AbstractSequentialFileFactory implements SequentialFileFac
       this.maxIO = maxIO;
    }
 
+   @Override
+   public int getAlignment() {
+      if (alignment < 0) {
+         alignment = 1;
+      }
+      return alignment;
+   }
+
+   @Override
+   public AbstractSequentialFileFactory setAlignment(int alignment) {
+      this.alignment = alignment;
+      return this;
+   }
+
 
    @Override
    public SequentialFileFactory setDatasync(boolean enabled) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java
index 8f7cfb5..53c9890 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java
@@ -43,8 +43,6 @@ public interface SequentialFile {
 
    boolean fits(int size);
 
-   int getAlignment() throws Exception;
-
    int calculateBlockStart(int position) throws Exception;
 
    String getFileName();

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFileFactory.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFileFactory.java
index 2229edf..c8277e3 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFileFactory.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFileFactory.java
@@ -79,6 +79,8 @@ public interface SequentialFileFactory {
 
    int getAlignment();
 
+   SequentialFileFactory setAlignment(int alignment);
+
    int calculateBlockSize(int bytes);
 
    File getDirectory();

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java
index 874e411..21f5e0d 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java
@@ -79,16 +79,8 @@ public class AIOSequentialFile extends AbstractSequentialFile {
    }
 
    @Override
-   public int getAlignment() {
-      // TODO: get the alignment from the file system, but we have to cache this, we can't call it every time
-      /* checkOpened();
-      return aioFile.getBlockSize(); */
-      return 512;
-   }
-
-   @Override
    public int calculateBlockStart(final int position) {
-      int alignment = getAlignment();
+      int alignment = factory.getAlignment();
 
       int pos = (position / alignment + (position % alignment != 0 ? 1 : 0)) * alignment;
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java
index 57d18f5..e7b0dfa 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java
@@ -143,13 +143,13 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
    @Override
    public ByteBuffer allocateDirectBuffer(final int size) {
 
-      int blocks = size / 512;
-      if (size % 512 != 0) {
+      int blocks = size / getAlignment();
+      if (size % getAlignment() != 0) {
          blocks++;
       }
 
-      // The buffer on AIO has to be a multiple of 512
-      ByteBuffer buffer = LibaioContext.newAlignedBuffer(blocks * 512, 512);
+      // The buffer on AIO has to be a multiple of getAlignment()
+      ByteBuffer buffer = LibaioContext.newAlignedBuffer(blocks * getAlignment(), getAlignment());
 
       buffer.limit(size);
 
@@ -163,8 +163,8 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
 
    @Override
    public ByteBuffer newBuffer(int size) {
-      if (size % 512 != 0) {
-         size = (size / 512 + 1) * 512;
+      if (size % getAlignment() != 0) {
+         size = (size / getAlignment() + 1) * getAlignment();
       }
 
       return buffersControl.newBuffer(size);
@@ -178,7 +178,26 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
 
    @Override
    public int getAlignment() {
-      return 512;
+      if (alignment < 0) {
+
+         File checkFile = null;
+
+         try {
+            journalDir.mkdirs();
+            checkFile = File.createTempFile("journalCheck", ".tmp", journalDir);
+            checkFile.mkdirs();
+            checkFile.createNewFile();
+            alignment = LibaioContext.getBlockSize(checkFile);
+         } catch (Throwable e) {
+            logger.warn(e.getMessage(), e);
+            alignment = 512;
+         } finally {
+            if (checkFile != null) {
+               checkFile.delete();
+            }
+         }
+      }
+      return alignment;
    }
 
    // For tests only
@@ -399,7 +418,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
          // if a buffer is bigger than the configured-bufferSize, we just create a new
          // buffer.
          if (size > bufferSize) {
-            return LibaioContext.newAlignedBuffer(size, 512);
+            return LibaioContext.newAlignedBuffer(size, getAlignment());
          } else {
             // We need to allocate buffers following the rules of the storage
             // being used (AIO/NIO)
@@ -410,7 +429,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
 
             if (buffer == null) {
                // if empty create a new one.
-               buffer = LibaioContext.newAlignedBuffer(size, 512);
+               buffer = LibaioContext.newAlignedBuffer(size, getAlignment());
 
                buffer.limit(alignedSize);
             } else {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
index 017948b..a959113 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
@@ -114,11 +114,6 @@ final class MappedSequentialFile implements SequentialFile {
    }
 
    @Override
-   public int getAlignment() {
-      return 0;
-   }
-
-   @Override
    public int calculateBlockStart(int position) {
       return position;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java
index 8ccef74..55bb2bf 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java
@@ -162,6 +162,12 @@ public final class MappedSequentialFileFactory implements SequentialFileFactory
    }
 
    @Override
+   public SequentialFileFactory setAlignment(int alignment) {
+      // no op
+      return this;
+   }
+
+   @Override
    public int calculateBlockSize(int bytes) {
       return bytes;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java
index 2887d25..29e5b81 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java
@@ -54,11 +54,6 @@ public final class NIOSequentialFile extends AbstractSequentialFile {
    }
 
    @Override
-   public int getAlignment() {
-      return 1;
-   }
-
-   @Override
    public int calculateBlockStart(final int position) {
       return position;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-native/src/main/java/org/apache/activemq/artemis/jlibaio/LibaioFile.java
----------------------------------------------------------------------
diff --git a/artemis-native/src/main/java/org/apache/activemq/artemis/jlibaio/LibaioFile.java b/artemis-native/src/main/java/org/apache/activemq/artemis/jlibaio/LibaioFile.java
index 43d80ea..dc86449 100644
--- a/artemis-native/src/main/java/org/apache/activemq/artemis/jlibaio/LibaioFile.java
+++ b/artemis-native/src/main/java/org/apache/activemq/artemis/jlibaio/LibaioFile.java
@@ -39,9 +39,7 @@ public final class LibaioFile<Callback extends SubmitInfo> implements AutoClosea
    }
 
    public int getBlockSize() {
-      return 512;
-      // FIXME
-      //return LibaioContext.getBlockSizeFD(fd);
+      return LibaioContext.getBlockSizeFD(fd);
    }
 
    public boolean lock() {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
index e2bedd1..28f3623 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java
@@ -548,7 +548,7 @@ public interface Configuration {
    Configuration setJournalDirectory(String dir);
 
    /**
-    * Returns the type of journal used by this server (either {@code NIO} or {@code ASYNCIO}).
+    * Returns the type of journal used by this server ({@code NIO}, {@code ASYNCIO} or {@code MAPPED}).
     * <br>
     * Default value is ASYNCIO.
     */

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/Validators.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/Validators.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/Validators.java
index 98bced3..c1196a3 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/Validators.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/Validators.java
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.artemis.core.config.impl;
 
+import java.util.EnumSet;
+
 import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
 import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
@@ -123,7 +125,7 @@ public final class Validators {
       @Override
       public void validate(final String name, final Object value) {
          String val = (String) value;
-         if (val == null || !val.equals(JournalType.NIO.toString()) && !val.equals(JournalType.ASYNCIO.toString())) {
+         if (val == null || !EnumSet.allOf(JournalType.class).contains(JournalType.valueOf(val))) {
             throw ActiveMQMessageBundle.BUNDLE.invalidJournalType(val);
          }
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
index e82eb23..bfb9f84 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
@@ -469,22 +469,19 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
 
       String s = getString(e, "journal-type", config.getJournalType().toString(), Validators.JOURNAL_TYPE);
 
-      if (s.equals(JournalType.NIO.toString())) {
-         config.setJournalType(JournalType.NIO);
-      } else if (s.equals(JournalType.ASYNCIO.toString())) {
+      config.setJournalType(JournalType.getType(s));
+
+      if (config.getJournalType() == JournalType.ASYNCIO) {
          // https://jira.jboss.org/jira/browse/HORNETQ-295
          // We do the check here to see if AIO is supported so we can use the correct defaults and/or use
          // correct settings in xml
          // If we fall back later on these settings can be ignored
          boolean supportsAIO = AIOSequentialFileFactory.isSupported();
 
-         if (supportsAIO) {
-            config.setJournalType(JournalType.ASYNCIO);
-         } else {
+         if (!supportsAIO) {
             if (validateAIO) {
                ActiveMQServerLogger.LOGGER.AIONotFound();
             }
-
             config.setJournalType(JournalType.NIO);
          }
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java
index a1346ec..7c0a651 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -113,7 +114,7 @@ public class JournalStorageManager extends AbstractJournalStorageManager {
    @Override
    protected void init(Configuration config, IOCriticalErrorListener criticalErrorListener) {
 
-      if (config.getJournalType() != JournalType.NIO && config.getJournalType() != JournalType.ASYNCIO) {
+      if (!EnumSet.allOf(JournalType.class).contains(config.getJournalType())) {
          throw ActiveMQMessageBundle.BUNDLE.invalidJournal();
       }
 
@@ -125,21 +126,23 @@ public class JournalStorageManager extends AbstractJournalStorageManager {
       bindingsJournal = localBindings;
       originalBindingsJournal = localBindings;
 
-      if (config.getJournalType() == JournalType.ASYNCIO) {
-         ActiveMQServerLogger.LOGGER.journalUseAIO();
+      switch (config.getJournalType()) {
 
-         journalFF = new AIOSequentialFileFactory(config.getJournalLocation(), config.getJournalBufferSize_AIO(), config.getJournalBufferTimeout_AIO(), config.getJournalMaxIO_AIO(), config.isLogJournalWriteRate(), criticalErrorListener);
-      } else if (config.getJournalType() == JournalType.NIO) {
-         ActiveMQServerLogger.LOGGER.journalUseNIO();
-         journalFF = new NIOSequentialFileFactory(config.getJournalLocation(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), config.getJournalMaxIO_NIO(), config.isLogJournalWriteRate(), criticalErrorListener);
-      } else {
-         throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(config.getJournalType());
+         case NIO:
+            ActiveMQServerLogger.LOGGER.journalUseNIO();
+            journalFF = new NIOSequentialFileFactory(config.getJournalLocation(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), config.getJournalMaxIO_NIO(), config.isLogJournalWriteRate(), criticalErrorListener);
+            break;
+         case ASYNCIO:
+            ActiveMQServerLogger.LOGGER.journalUseAIO();
+            journalFF = new AIOSequentialFileFactory(config.getJournalLocation(), config.getJournalBufferSize_AIO(), config.getJournalBufferTimeout_AIO(), config.getJournalMaxIO_AIO(), config.isLogJournalWriteRate(), criticalErrorListener);
+            break;
+         default:
+            throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(config.getJournalType());
       }
 
       journalFF.setDatasync(config.isJournalDatasync());
 
-
-      Journal localMessage = new JournalImpl(ioExecutors, config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactMinFiles(), config.getJournalCompactPercentage(), journalFF, "activemq-data", "amq", config.getJournalType() == JournalType.ASYNCIO ? config.getJournalMaxIO_AIO() : config.getJournalMaxIO_NIO(), 0);
+      Journal localMessage = new JournalImpl(ioExecutors, config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactMinFiles(), config.getJournalCompactPercentage(), journalFF, "activemq-data", "amq", journalFF.getMaxIO(), 0);
 
       messageJournal = localMessage;
       originalMessageJournal = localMessage;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/JournalType.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/JournalType.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/JournalType.java
index ec5a964..2716a38 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/JournalType.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/JournalType.java
@@ -16,6 +16,32 @@
  */
 package org.apache.activemq.artemis.core.server;
 
+
 public enum JournalType {
-   NIO, ASYNCIO;
+   NIO, ASYNCIO, MAPPED;
+
+   public static final String validValues;
+
+   static {
+      StringBuffer stringBuffer = new StringBuffer();
+      for (JournalType type : JournalType.values()) {
+
+         if (stringBuffer.length() != 0) {
+            stringBuffer.append(",");
+         }
+
+         stringBuffer.append(type.name());
+      }
+
+      validValues = stringBuffer.toString();
+   }
+
+   public static JournalType getType(String type) {
+      switch (type) {
+         case "NIO": return NIO;
+         case "ASYNCIO" : return ASYNCIO;
+         default: throw new IllegalStateException("Invalid JournalType:" + type + " valid Types: " + validValues);
+      }
+   }
+
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java
index fd19727..4e7f315 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java
@@ -44,7 +44,7 @@ public class AIOSequentialFileFactoryTest extends SequentialFileFactoryTestBase
       SequentialFile file = factory.createSequentialFile("filtetmp.log");
       file.open();
       ByteBuffer buff = factory.newBuffer(10);
-      Assert.assertEquals(512, buff.limit());
+      Assert.assertEquals(factory.getAlignment(), buff.limit());
       file.close();
       factory.releaseBuffer(buff);
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java
index 4521d97..d108958 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java
@@ -45,7 +45,7 @@ public class NIOImportExportTest extends JournalImplTestBase {
 
    @Test
    public void testExportImport() throws Exception {
-      setup(10, 10 * 1024, true);
+      setup(10, 10 * 4096, true);
 
       createJournal();
 
@@ -99,7 +99,7 @@ public class NIOImportExportTest extends JournalImplTestBase {
 
    @Test
    public void testExportImport3() throws Exception {
-      setup(10, 10 * 1024, true);
+      setup(10, 10 * 4096, true);
 
       createJournal();
 
@@ -162,7 +162,7 @@ public class NIOImportExportTest extends JournalImplTestBase {
 
    @Test
    public void testExportImport2() throws Exception {
-      setup(10, 10 * 1024, true);
+      setup(10, 10 * 4096, true);
 
       createJournal();
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java
index 42c48f3..38cc126 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java
@@ -479,7 +479,7 @@ public class NIOJournalCompactTest extends JournalImplTestBase {
          performNonTransactionalDelete = false;
       }
 
-      setup(2, 60 * 1024, false);
+      setup(2, 60 * 4096, false);
 
       ArrayList<Long> liveIDs = new ArrayList<>();
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java
index 48cba76..b92240b 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java
@@ -50,7 +50,7 @@ public class CleanBufferTest extends ActiveMQTestBase {
    @Test
    public void testCleanOnAIO() {
       if (LibaioContext.isLoaded()) {
-         SequentialFileFactory factory = new AIOSequentialFileFactory(new File("Whatever"), 50);
+         SequentialFileFactory factory = new AIOSequentialFileFactory(new File("./target"), 50);
 
          testBuffer(factory);
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
index 3be030d..d1536d4 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
@@ -39,6 +39,9 @@ public abstract class JournalImplTestUnit extends JournalImplTestBase {
    @Override
    @After
    public void tearDown() throws Exception {
+      //stop journal first to let it manage its files
+      stopComponent(journal);
+
       List<String> files = fileFactory.listFiles(fileExtension);
 
       for (String file : files) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
index da7fc78..d27aa9b 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
@@ -132,11 +132,11 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
 
       try {
 
-         checkFill(sf, 2048);
+         checkFill(factory, sf, 2048);
 
-         checkFill(sf, 512);
+         checkFill(factory, sf, 512);
 
-         checkFill(sf, 512 * 4);
+         checkFill(factory, sf, 512 * 4);
       } finally {
          sf.close();
       }
@@ -226,19 +226,19 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
       sf.write(bb1, true);
       long bytesWritten = sf.position() - initialPos;
 
-      Assert.assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
+      Assert.assertEquals(calculateRecordSize(bytes1.length, factory.getAlignment()), bytesWritten);
 
       initialPos = sf.position();
       sf.write(bb2, true);
       bytesWritten = sf.position() - initialPos;
 
-      Assert.assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesWritten);
+      Assert.assertEquals(calculateRecordSize(bytes2.length, factory.getAlignment()), bytesWritten);
 
       initialPos = sf.position();
       sf.write(bb3, true);
       bytesWritten = sf.position() - initialPos;
 
-      Assert.assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesWritten);
+      Assert.assertEquals(calculateRecordSize(bytes3.length, factory.getAlignment()), bytesWritten);
 
       sf.position(0);
 
@@ -247,20 +247,20 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
       ByteBuffer rb3 = factory.newBuffer(bytes3.length);
 
       int bytesRead = sf.read(rb1);
-      Assert.assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesRead);
+      Assert.assertEquals(calculateRecordSize(bytes1.length, factory.getAlignment()), bytesRead);
 
       for (int i = 0; i < bytes1.length; i++) {
          Assert.assertEquals(bytes1[i], rb1.get(i));
       }
 
       bytesRead = sf.read(rb2);
-      Assert.assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesRead);
+      Assert.assertEquals(calculateRecordSize(bytes2.length, factory.getAlignment()), bytesRead);
       for (int i = 0; i < bytes2.length; i++) {
          Assert.assertEquals(bytes2[i], rb2.get(i));
       }
 
       bytesRead = sf.read(rb3);
-      Assert.assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesRead);
+      Assert.assertEquals(calculateRecordSize(bytes3.length, factory.getAlignment()), bytesRead);
       for (int i = 0; i < bytes3.length; i++) {
          Assert.assertEquals(bytes3[i], rb3.get(i));
       }
@@ -291,19 +291,19 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
          sf.write(wrapBuffer(bytes1), true);
          long bytesWritten = sf.position() - initialPos;
 
-         Assert.assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
+         Assert.assertEquals(calculateRecordSize(bytes1.length, factory.getAlignment()), bytesWritten);
 
          initialPos = sf.position();
          sf.write(wrapBuffer(bytes2), true);
          bytesWritten = sf.position() - initialPos;
 
-         Assert.assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesWritten);
+         Assert.assertEquals(calculateRecordSize(bytes2.length, factory.getAlignment()), bytesWritten);
 
          initialPos = sf.position();
          sf.write(wrapBuffer(bytes3), true);
          bytesWritten = sf.position() - initialPos;
 
-         Assert.assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesWritten);
+         Assert.assertEquals(calculateRecordSize(bytes3.length, factory.getAlignment()), bytesWritten);
 
          byte[] rbytes1 = new byte[bytes1.length];
 
@@ -315,7 +315,7 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
          ByteBuffer rb2 = factory.newBuffer(rbytes2.length);
          ByteBuffer rb3 = factory.newBuffer(rbytes3.length);
 
-         sf.position(calculateRecordSize(bytes1.length, sf.getAlignment()) + calculateRecordSize(bytes2.length, sf.getAlignment()));
+         sf.position(calculateRecordSize(bytes1.length, factory.getAlignment()) + calculateRecordSize(bytes2.length, factory.getAlignment()));
 
          int bytesRead = sf.read(rb3);
          Assert.assertEquals(rb3.limit(), bytesRead);
@@ -361,7 +361,7 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
       sf.write(wrapBuffer(bytes1), true);
       long bytesWritten = sf.position() - initialPos;
 
-      Assert.assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
+      Assert.assertEquals(calculateRecordSize(bytes1.length, factory.getAlignment()), bytesWritten);
 
       sf.close();
 
@@ -386,7 +386,7 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
       return ActiveMQBuffers.wrappedBuffer(bytes);
    }
 
-   protected void checkFill(final SequentialFile file, final int size) throws Exception {
+   protected void checkFill(final SequentialFileFactory factory, final SequentialFile file, final int size) throws Exception {
       file.fill(size);
 
       file.close();
@@ -399,7 +399,7 @@ public abstract class SequentialFileFactoryTestBase extends ActiveMQTestBase {
 
       int bytesRead = file.read(bb);
 
-      Assert.assertEquals(calculateRecordSize(size, file.getAlignment()), bytesRead);
+      Assert.assertEquals(calculateRecordSize(size, factory.getAlignment()), bytesRead);
 
       for (int i = 0; i < size; i++) {
          // log.debug(" i is " + i);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6018b2d7/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
index 0316945..1f933fb 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
@@ -37,7 +37,7 @@ public class FakeSequentialFileFactory implements SequentialFileFactory {
 
    private final Map<String, FakeSequentialFile> fileMap = new ConcurrentHashMap<>();
 
-   private final int alignment;
+   private volatile int alignment;
 
    private final boolean supportsCallback;
 
@@ -198,6 +198,12 @@ public class FakeSequentialFileFactory implements SequentialFileFactory {
       return alignment;
    }
 
+   @Override
+   public FakeSequentialFileFactory setAlignment(int alignment) {
+      this.alignment = alignment;
+      return this;
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -463,11 +469,6 @@ public class FakeSequentialFileFactory implements SequentialFileFactory {
       }
 
       @Override
-      public int getAlignment() throws Exception {
-         return alignment;
-      }
-
-      @Override
       public int calculateBlockStart(final int position) throws Exception {
          int pos = (position / alignment + (position % alignment != 0 ? 1 : 0)) * alignment;
 


Mime
View raw message