You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2022/03/30 16:57:40 UTC

[activemq-artemis] branch main updated (abfabfc -> c3e6ce0)

This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git.


    from abfabfc  This closes #4002
     new 3ec88c5  ARTEMIS-3740 Upgrade Johnzon
     new 5d97057  ARTEMIS-3741 Cache MBeanInfoHelper results
     new c3e6ce0  This closes #3996

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/activemq/cli/test/ArtemisTest.java  | 29 ++++++++
 .../core/management/impl/MBeanInfoHelper.java      | 81 ++++++++++++++--------
 .../core/management/impl/MBeanInfoHelperTest.java  | 46 ++++++++++++
 pom.xml                                            |  2 +-
 4 files changed, 129 insertions(+), 29 deletions(-)
 create mode 100644 artemis-server/src/test/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelperTest.java

[activemq-artemis] 02/03: ARTEMIS-3741 Cache MBeanInfoHelper results

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 5d970576da13b14b7b1cb48ebd9e7f3c731b44c4
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Wed Mar 23 15:50:19 2022 -0500

    ARTEMIS-3741 Cache MBeanInfoHelper results
    
    The utility methods in
    `org.apache.activemq.artemis.core.management.impl.MBeanInfoHelper` are
    executed *a lot* - especially for Jolokia which is used by the web
    console. The `MBeanOperationInfo` and `MBeanAttributeInfo` results are
    static and reflection is slow therefore they should not be calculated
    over and over again. Rather they should be calculated once and cached
    for later use.
    
    Caching these results significantly improves performance. Over the
    course of 1,000,000 invocations the difference is several orders of
    magnitude. This improves usability substantially when dealing with,
    for example, tens of thousands of addresses and/or queues.
---
 .../core/management/impl/MBeanInfoHelper.java      | 81 ++++++++++++++--------
 .../core/management/impl/MBeanInfoHelperTest.java  | 46 ++++++++++++
 2 files changed, 99 insertions(+), 28 deletions(-)

diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelper.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelper.java
index 900951e..2895325 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelper.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelper.java
@@ -23,6 +23,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.activemq.artemis.api.core.management.Attribute;
 import org.apache.activemq.artemis.api.core.management.Operation;
@@ -30,52 +31,76 @@ import org.apache.activemq.artemis.api.core.management.Parameter;
 
 public class MBeanInfoHelper {
 
-
+   private static ConcurrentHashMap<Class, MBeanAttributeInfo[]> attributesInfoCache = new ConcurrentHashMap<>();
+   private static ConcurrentHashMap<Class, MBeanOperationInfo[]> operationsInfoCache = new ConcurrentHashMap<>();
 
    public static MBeanOperationInfo[] getMBeanOperationsInfo(final Class mbeanInterface) {
-      List<MBeanOperationInfo> operations = new ArrayList<>();
+      if (operationsInfoCache.containsKey(mbeanInterface)) {
+         return operationsInfoCache.get(mbeanInterface);
+      } else {
+         List<MBeanOperationInfo> operations = new ArrayList<>();
 
-      for (Method method : mbeanInterface.getMethods()) {
-         if (!MBeanInfoHelper.isGetterMethod(method) && !MBeanInfoHelper.isSetterMethod(method) &&
-            !MBeanInfoHelper.isIsBooleanMethod(method)) {
-            operations.add(MBeanInfoHelper.getOperationInfo(method));
+         for (Method method : mbeanInterface.getMethods()) {
+            if (!MBeanInfoHelper.isGetterMethod(method) && !MBeanInfoHelper.isSetterMethod(method) &&
+               !MBeanInfoHelper.isIsBooleanMethod(method)) {
+               operations.add(MBeanInfoHelper.getOperationInfo(method));
+            }
          }
+         MBeanOperationInfo[] result = operations.toArray(new MBeanOperationInfo[operations.size()]);
+         operationsInfoCache.put(mbeanInterface, result);
+         return result;
       }
-
-      return operations.toArray(new MBeanOperationInfo[operations.size()]);
    }
 
    public static MBeanAttributeInfo[] getMBeanAttributesInfo(final Class mbeanInterface) {
-      List<MBeanAttributeInfo> tempAttributes = new ArrayList<>();
-      List<MBeanAttributeInfo> finalAttributes = new ArrayList<>();
-      List<String> alreadyAdded = new ArrayList<>();
-
-      for (Method method : mbeanInterface.getMethods()) {
-         if (MBeanInfoHelper.isGetterMethod(method) || MBeanInfoHelper.isSetterMethod(method) ||
-            MBeanInfoHelper.isIsBooleanMethod(method)) {
-            tempAttributes.add(MBeanInfoHelper.getAttributeInfo(method));
+      if (attributesInfoCache.containsKey(mbeanInterface)) {
+         return attributesInfoCache.get(mbeanInterface);
+      } else {
+         List<MBeanAttributeInfo> tempAttributes = new ArrayList<>();
+         List<MBeanAttributeInfo> finalAttributes = new ArrayList<>();
+         List<String> alreadyAdded = new ArrayList<>();
+
+         for (Method method : mbeanInterface.getMethods()) {
+            if (MBeanInfoHelper.isGetterMethod(method) || MBeanInfoHelper.isSetterMethod(method) ||
+               MBeanInfoHelper.isIsBooleanMethod(method)) {
+               tempAttributes.add(MBeanInfoHelper.getAttributeInfo(method));
+            }
          }
-      }
 
-      // since getters and setters will each have an MBeanAttributeInfo we need to de-duplicate
-      for (MBeanAttributeInfo info1 : tempAttributes) {
-         MBeanAttributeInfo infoToCopy = info1;
-         for (MBeanAttributeInfo info2 : tempAttributes) {
-            if (info1.getName().equals(info2.getName()) && !info1.equals(info2)) {
-               infoToCopy = new MBeanAttributeInfo(info1.getName(), info1.getType().equals("void") ? info2.getType() : info1.getType(), info1.getDescription(), (info1.isReadable() || info2.isReadable()), (info1.isWritable() || info2.isWritable()), (info1.isIs() || info2.isIs()));
+         // since getters and setters will each have an MBeanAttributeInfo we need to de-duplicate
+         for (MBeanAttributeInfo info1 : tempAttributes) {
+            MBeanAttributeInfo infoToCopy = info1;
+            for (MBeanAttributeInfo info2 : tempAttributes) {
+               if (info1.getName().equals(info2.getName()) && !info1.equals(info2)) {
+                  infoToCopy = new MBeanAttributeInfo(info1.getName(), info1.getType().equals("void") ? info2.getType() : info1.getType(), info1.getDescription(), (info1.isReadable() || info2.isReadable()), (info1.isWritable() || info2.isWritable()), (info1.isIs() || info2.isIs()));
+               }
+            }
+            if (!alreadyAdded.contains(infoToCopy.getName())) {
+               finalAttributes.add(infoToCopy);
+               alreadyAdded.add(infoToCopy.getName());
             }
          }
-         if (!alreadyAdded.contains(infoToCopy.getName())) {
-            finalAttributes.add(infoToCopy);
-            alreadyAdded.add(infoToCopy.getName());
-         }
+         MBeanAttributeInfo[] result = finalAttributes.toArray(new MBeanAttributeInfo[finalAttributes.size()]);
+         attributesInfoCache.put(mbeanInterface, result);
+         return result;
       }
+   }
 
-      return finalAttributes.toArray(new MBeanAttributeInfo[finalAttributes.size()]);
+   public static int getAttributesInfoCacheSize() {
+      return attributesInfoCache.size();
    }
 
+   public static int getOperationsInfoCacheSize() {
+      return operationsInfoCache.size();
+   }
 
+   public static void clearAttributesInfoCache() {
+      attributesInfoCache.clear();
+   }
 
+   public static void clearOperationsInfoCache() {
+      operationsInfoCache.clear();
+   }
 
    private static boolean isGetterMethod(final Method method) {
       if (!method.getName().equals("get") && method.getName().startsWith("get") &&
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelperTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelperTest.java
new file mode 100644
index 0000000..113a827
--- /dev/null
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/management/impl/MBeanInfoHelperTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.core.management.impl;
+
+import org.apache.activemq.artemis.api.core.management.AddressControl;
+import org.apache.activemq.artemis.api.core.management.QueueControl;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MBeanInfoHelperTest extends Assert {
+
+   @Test
+   public void testOperationsInfosCache() {
+      MBeanInfoHelper.clearOperationsInfoCache();
+      for (int i = 0; i < 10; i++) {
+         MBeanInfoHelper.getMBeanOperationsInfo(QueueControl.class);
+         MBeanInfoHelper.getMBeanOperationsInfo(AddressControl.class);
+      }
+      assertEquals(2, MBeanInfoHelper.getOperationsInfoCacheSize());
+   }
+
+   @Test
+   public void testAttributesInfosCache() {
+      MBeanInfoHelper.clearAttributesInfoCache();
+      for (int i = 0; i < 10; i++) {
+         MBeanInfoHelper.getMBeanAttributesInfo(QueueControl.class);
+         MBeanInfoHelper.getMBeanAttributesInfo(AddressControl.class);
+      }
+      assertEquals(2, MBeanInfoHelper.getAttributesInfoCacheSize());
+   }
+}

[activemq-artemis] 03/03: This closes #3996

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit c3e6ce075c400fa7ad448f166f6bceb905588e17
Merge: abfabfc 5d97057
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Wed Mar 30 11:57:28 2022 -0500

    This closes #3996

 .../org/apache/activemq/cli/test/ArtemisTest.java  | 29 ++++++++
 .../core/management/impl/MBeanInfoHelper.java      | 81 ++++++++++++++--------
 .../core/management/impl/MBeanInfoHelperTest.java  | 46 ++++++++++++
 pom.xml                                            |  2 +-
 4 files changed, 129 insertions(+), 29 deletions(-)

[activemq-artemis] 01/03: ARTEMIS-3740 Upgrade Johnzon

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 3ec88c5ea49bb91bd2f3ea3fbc808449a8be538f
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Wed Mar 23 15:37:58 2022 -0500

    ARTEMIS-3740 Upgrade Johnzon
---
 .../org/apache/activemq/cli/test/ArtemisTest.java  | 29 ++++++++++++++++++++++
 pom.xml                                            |  2 +-
 2 files changed, 30 insertions(+), 1 deletion(-)

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 de08be6..745dce0 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
@@ -24,6 +24,8 @@ import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
 import org.apache.activemq.artemis.json.JsonArray;
 import org.apache.activemq.artemis.json.JsonObject;
 import javax.xml.parsers.DocumentBuilder;
@@ -1738,6 +1740,33 @@ public class ArtemisTest extends CliTestBase {
    }
 
    @Test
+   public void testHugeQstat() throws Exception {
+
+      File instanceQstat = new File(temporaryFolder.getRoot(), "instanceQStat");
+      setupAuth(instanceQstat);
+      Run.setEmbedded(true);
+      Artemis.main("create", instanceQstat.getAbsolutePath(), "--silent", "--no-fsync", "--no-autotune", "--no-web", "--require-login");
+      System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
+      Object result = Artemis.internalExecute("run");
+      ActiveMQServer activeMQServer = ((Pair<ManagementContext, ActiveMQServer>)result).getB();
+
+      try {
+         final int COUNT = 20_000;
+         for (int i = 0; i < COUNT; i++) {
+            activeMQServer.createQueue(new QueueConfiguration("" + i));
+         }
+         TestActionContext context = new TestActionContext();
+         StatQueue statQueue = new StatQueue();
+         statQueue.setUser("admin");
+         statQueue.setPassword("admin");
+         statQueue.setMaxRows(COUNT);
+         statQueue.execute(context);
+      } finally {
+         stopServer();
+      }
+   }
+
+   @Test
    public void testQstatColumnWidth() throws Exception {
 
       File instanceQstat = new File(temporaryFolder.getRoot(), "instanceQStat");
diff --git a/pom.xml b/pom.xml
index 2ae1b30..6682c9f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -129,7 +129,7 @@
       <resteasy.version>3.15.0.Final</resteasy.version>
       <slf4j.version>1.7.36</slf4j.version>
       <qpid.jms.version>1.5.0</qpid.jms.version>
-      <johnzon.version>0.9.5</johnzon.version>
+      <johnzon.version>1.2.16</johnzon.version>
       <hawtbuff.version>1.11</hawtbuff.version>
       <jb.logmanager.version>2.1.10.Final</jb.logmanager.version>
       <jb.slf4j-jboss-logmanager.version>1.0.4.GA</jb.slf4j-jboss-logmanager.version>