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:17:06 UTC

[activemq-artemis] branch main updated: ARTEMIS-3733 - Destination cache size too small for OpenWire clients

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


The following commit(s) were added to refs/heads/main by this push:
     new bb44e37  ARTEMIS-3733 - Destination cache size too small for OpenWire clients
     new dfb9878  This closes #3998
bb44e37 is described below

commit bb44e37e8491e690c61bfdf75511f3f1c1357631
Author: AntonRoskvist <an...@volvo.com>
AuthorDate: Fri Mar 25 11:09:24 2022 +0100

    ARTEMIS-3733 - Destination cache size too small for OpenWire clients
---
 .../core/protocol/openwire/OpenWireProtocolManager.java      | 10 ++++++++++
 .../artemis/core/protocol/openwire/amq/AMQSession.java       |  4 ++--
 docs/user-manual/en/openwire.md                              | 12 ++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java
index e5c37e8..afa7086 100644
--- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java
+++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java
@@ -136,6 +136,8 @@ public class OpenWireProtocolManager  extends AbstractProtocolManager<Command, O
    //to management service
    private boolean suppressInternalManagementObjects = true;
 
+   private int openWireDestinationCacheSize = 16;
+
    private final OpenWireFormat wireFormat;
 
    private final Map<SimpleString, RoutingType> prefixes = new HashMap<>();
@@ -718,6 +720,14 @@ public class OpenWireProtocolManager  extends AbstractProtocolManager<Command, O
       this.suppressInternalManagementObjects = suppressInternalManagementObjects;
    }
 
+   public int getOpenWireDestinationCacheSize() {
+      return this.openWireDestinationCacheSize;
+   }
+
+   public void setOpenWireDestinationCacheSize(int openWireDestinationCacheSize) {
+      this.openWireDestinationCacheSize = openWireDestinationCacheSize;
+   }
+
    public void setVirtualTopicConsumerWildcards(String virtualTopicConsumerWildcards) {
       for (String filter : virtualTopicConsumerWildcards.split(",")) {
          String[] configuration = filter.split(";");
diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java
index d02dffb..1c96519 100644
--- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java
+++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java
@@ -200,8 +200,8 @@ public class AMQSession implements SessionCallback {
       //lazy allocation of the cache
       if (existingQueuesCache == null) {
          //16 means 64 bytes with 32 bit references or 128 bytes with 64 bit references -> 1 or 2 cache lines with common archs
-         existingQueuesCache = new String[16];
-         assert (Integer.bitCount(existingQueuesCache.length) == 1) : "existingQueuesCache.length must be power of 2";
+         existingQueuesCache = new String[protocolManager.getOpenWireDestinationCacheSize()];
+         assert (Integer.bitCount(existingQueuesCache.length) == 1) : "openWireDestinationCacheSize must be a power of 2";
          this.existingQueuesCache = existingQueuesCache;
       }
       final int hashCode = physicalName.hashCode();
diff --git a/docs/user-manual/en/openwire.md b/docs/user-manual/en/openwire.md
index b522284..bce5064 100644
--- a/docs/user-manual/en/openwire.md
+++ b/docs/user-manual/en/openwire.md
@@ -81,6 +81,18 @@ The two parameters are configured on an OpenWire `acceptor`, e.g.:
 <acceptor name="artemis">tcp://localhost:61616?protocols=OPENWIRE;supportAdvisory=true;suppressInternalManagementObjects=false</acceptor>
 ```
 
+## OpenWire Destination Cache
+For improved performance of the broker we keep a cache of recently used destinations, so that when new messages are dispatched to them,
+we do not have to do a lookup every time. By default, this cache holds up to `16` destinations. If additional destinations are added 
+they will overwrite older records.
+If you are dealing with a large amount of queues you might want to increase this value, which is done via configuration option:
+`openWireDestinationCacheSize` set on the OpenWire `acceptor` like this:
+```xml
+<acceptor name="artemis">tcp://localhost:61616?protocols=OPENWIRE;openWireDestinationCacheSize=64</acceptor>
+```
+
+This cache has to be set to a power of 2, i.e.: `2`, `16`, `128` and so on.
+
 ## Virtual Topic Consumer Destination Translation
 
 For existing OpenWire consumers of virtual topic destinations it is possible to