[ 
https://issues.apache.org/jira/browse/ARTEMIS-5121?focusedWorklogId=972470&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-972470
 ]

ASF GitHub Bot logged work on ARTEMIS-5121:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Jun/25 18:37
            Start Date: 10/Jun/25 18:37
    Worklog Time Spent: 10m 
      Work Description: jbertram commented on code in PR #5757:
URL: https://github.com/apache/activemq-artemis/pull/5757#discussion_r2138551748


##########
artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionState.java:
##########
@@ -587,8 +588,8 @@ public Integer getMatchingId(String topic) {
 
       private void update(MqttTopicSubscription newSub, Integer newId) {
          if (newId != null && !newId.equals(id)) {
-            if (this.topicFilterPattern == null || 
!subscription.topicFilter().equals(newSub.topicFilter())) {
-               topicFilterPattern = Match.createPattern(newSub.topicFilter(), 
MQTTUtil.MQTT_WILDCARD, true);
+            if (this.address == null || 
!subscription.topicFilter().equals(newSub.topicFilter())) {
+               address = new 
AddressImpl(SimpleString.of(newSub.topicFilter()), MQTTUtil.MQTT_WILDCARD);

Review Comment:
   This particular `AddressImpl` _is_ re-used between multiple invocations of 
`matches`. Were you referring to this line in `getMatchingId`:
   ```java
   if (id != null && new AddressImpl(SimpleString.of(topic), 
MQTTUtil.MQTT_WILDCARD).matches(address)) {
   ```
   I wasn't keen on creating a new instance of `AddressImpl` here for every 
invocation of `matches`, but the constructor performs a `split` that would be 
necessary either way so I thought it made some sense to just re-use that. Is 
your concern here GC pressure or something else?
   
   In any case, I'll look at creating a `static` version of `matches` that will 
fit with this as well as the existing use-cases.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 972470)
    Time Spent: 2h 50m  (was: 2h 40m)

> Improve performance of MQTT subscription ID matching
> ----------------------------------------------------
>
>                 Key: ARTEMIS-5121
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-5121
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>          Components: MQTT
>    Affects Versions: 2.37.0
>            Reporter: Adam Zyzak
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 2.42.0
>
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> Recently I performed stress test of a system using Artemis as a message 
> broker for MQTT and STOMP protocols. I noticed huge difference in performance 
> and CPU usage between these protocols.
> I made some jstacks and it shown that majority of time is spent in method 
> {{o.a.a.a.c.p.m.MQTTSessionState#getMatchingSubscriptionIdentifiers}} 
> compiling regular expressions. 
> It would be helpful if performance of this method was improved, especially 
> since it is executed on every publish, either by caching compiled patterns, 
> adding special cases for simpler topic names (topic names without special 
> characters may be compared using equality, {{#}} subscriptions can be always 
> added and topic names having {{#}} at the end can be compared using 
> {{startsWith()}}) or just adding option to configuration allowing to skip 
> adding SUBSCRIPTION_IDENTIFIER to publish message.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to