[1/2] activemq-artemis git commit: This closes #2456

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] activemq-artemis git commit: This closes #2456

jbertram
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 3feba1ece -> cc4aaa46c


This closes #2456


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

Branch: refs/heads/master
Commit: cc4aaa46c52b756275d7ea2065cbfe0ff921118b
Parents: 3feba1e 2716a7b
Author: Justin Bertram <[hidden email]>
Authored: Fri Dec 14 15:04:05 2018 -0600
Committer: Justin Bertram <[hidden email]>
Committed: Fri Dec 14 15:04:05 2018 -0600

----------------------------------------------------------------------
 .../impl/journal/OperationContextImpl.java      | 36 ++++++++++++--------
 .../core/transaction/impl/TransactionImpl.java  | 29 +++++++++++-----
 2 files changed, 42 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

[2/2] activemq-artemis git commit: ARTEMIS-2198 Reduce GC pressure on TransactionImpl and OperationContextImpl

jbertram
ARTEMIS-2198 Reduce GC pressure on TransactionImpl and OperationContextImpl

TransactionImpl::properties are often not used and could be
avoided to be allocated.
OperationContextImpl.TaskHolders instances are turned into static
classes to avoid refecencing back the context, making the life
easier for the GC.
OperationContexImpl volatile loads can be reduced to make the
code faster on the hot path.


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

Branch: refs/heads/master
Commit: 2716a7be88d314bb71b620dc981a1609f680e7bb
Parents: 3feba1e
Author: Francesco Nigro <[hidden email]>
Authored: Fri Dec 7 10:36:29 2018 +0100
Committer: Justin Bertram <[hidden email]>
Committed: Fri Dec 14 15:04:05 2018 -0600

----------------------------------------------------------------------
 .../impl/journal/OperationContextImpl.java      | 36 ++++++++++++--------
 .../core/transaction/impl/TransactionImpl.java  | 29 +++++++++++-----
 2 files changed, 42 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2716a7be/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/OperationContextImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/OperationContextImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/OperationContextImpl.java
index ea96ce1..82c381c 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/OperationContextImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/OperationContextImpl.java
@@ -140,6 +140,10 @@ public class OperationContextImpl implements OperationContext {
       boolean executeNow = false;
 
       synchronized (this) {
+         final int UNDEFINED = Integer.MIN_VALUE;
+         int storeLined = UNDEFINED;
+         int pageLined = UNDEFINED;
+         int replicationLined = UNDEFINED;
          if (storeOnly) {
             if (storeOnlyTasks == null) {
                storeOnlyTasks = new LinkedList<>();
@@ -147,16 +151,20 @@ public class OperationContextImpl implements OperationContext {
          } else {
             if (tasks == null) {
                tasks = new LinkedList<>();
-               minimalReplicated = replicationLineUp.intValue();
-               minimalStore = storeLineUp.intValue();
-               minimalPage = pageLineUp.intValue();
+               minimalReplicated = (replicationLined = replicationLineUp.intValue());
+               minimalStore = (storeLined = storeLineUp.intValue());
+               minimalPage = (pageLined = pageLineUp.intValue());
             }
          }
-
+         //On the next branches each of them is been used
+         if (replicationLined == UNDEFINED) {
+            replicationLined = replicationLineUp.intValue();
+            storeLined = storeLineUp.intValue();
+            pageLined = pageLineUp.intValue();
+         }
          // On this case, we can just execute the context directly
 
-         if (replicationLineUp.intValue() == replicated && storeLineUp.intValue() == stored &&
-            pageLineUp.intValue() == paged) {
+         if (replicationLined == replicated && storeLined == stored && pageLined == paged) {
             // We want to avoid the executor if everything is complete...
             // However, we can't execute the context if there are executions pending
             // We need to use the executor on this case
@@ -169,9 +177,9 @@ public class OperationContextImpl implements OperationContext {
             }
          } else {
             if (storeOnly) {
-               storeOnlyTasks.add(new TaskHolder(completion));
+               storeOnlyTasks.add(new TaskHolder(completion, storeLined, replicationLined, pageLined));
             } else {
-               tasks.add(new TaskHolder(completion));
+               tasks.add(new TaskHolder(completion, storeLined, replicationLined, pageLined));
             }
          }
       }
@@ -268,7 +276,7 @@ public class OperationContextImpl implements OperationContext {
       }
    }
 
-   final class TaskHolder {
+   static final class TaskHolder {
 
       @Override
       public String toString() {
@@ -288,10 +296,10 @@ public class OperationContextImpl implements OperationContext {
 
       final IOCallback task;
 
-      TaskHolder(final IOCallback task) {
-         storeLined = storeLineUp.intValue();
-         replicationLined = replicationLineUp.intValue();
-         pageLined = pageLineUp.intValue();
+      TaskHolder(final IOCallback task, int storeLined, int replicationLined, int pageLined) {
+         this.storeLined = storeLined;
+         this.replicationLined = replicationLined;
+         this.pageLined = pageLined;
          this.task = task;
       }
    }
@@ -349,4 +357,4 @@ public class OperationContextImpl implements OperationContext {
          ", executor=" + this.executor +
          "]" + buffer.toString();
    }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2716a7be/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
index e925c3b..ba731e7 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/transaction/impl/TransactionImpl.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.transaction.impl;
 
 import javax.transaction.xa.Xid;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
@@ -45,7 +46,7 @@ public class TransactionImpl implements Transaction {
 
    private static final int INITIAL_NUM_PROPERTIES = 10;
 
-   private Object[] properties = new Object[TransactionImpl.INITIAL_NUM_PROPERTIES];
+   private Object[] properties = null;
 
    protected final StorageManager storageManager;
 
@@ -67,6 +68,22 @@ public class TransactionImpl implements Transaction {
 
    private Object protocolData;
 
+   private void ensurePropertiesCapacity(int capacity) {
+      if (properties != null && properties.length >= capacity) {
+         return;
+      }
+      createOrEnlargeProperties(capacity);
+   }
+
+   private void createOrEnlargeProperties(int capacity) {
+      if (properties == null) {
+         properties = new Object[Math.min(TransactionImpl.INITIAL_NUM_PROPERTIES, capacity)];
+      } else {
+         assert properties.length < capacity;
+         properties = Arrays.copyOf(properties, capacity);
+      }
+   }
+
    @Override
    public Object getProtocolData() {
       return protocolData;
@@ -509,20 +526,14 @@ public class TransactionImpl implements Transaction {
 
    @Override
    public void putProperty(final int index, final Object property) {
-      if (index >= properties.length) {
-         Object[] newProperties = new Object[index];
-
-         System.arraycopy(properties, 0, newProperties, 0, properties.length);
-
-         properties = newProperties;
-      }
+      ensurePropertiesCapacity(index + 1);
 
       properties[index] = property;
    }
 
    @Override
    public Object getProperty(final int index) {
-      return properties[index];
+      return properties == null ? null : (index < properties.length ? properties[index] : null);
    }
 
    // Private