You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/03/11 06:06:45 UTC

[camel] branch opt-exchangekey created (now 7d44f59)

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

davsclaus pushed a change to branch opt-exchangekey
in repository https://gitbox.apache.org/repos/asf/camel.git.


      at 7d44f59  CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.

This branch includes the following new commits:

     new 8ffc458  CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.
     new 7d44f59  CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.

The 2 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.



[camel] 02/02: CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.

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

davsclaus pushed a commit to branch opt-exchangekey
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7d44f596d4f684ac7229b3bfa6c3167453d3dfa8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 11 07:06:02 2021 +0100

    CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.
---
 .../src/main/java/org/apache/camel/Exchange.java   | 16 +++++++++++++
 .../java/org/apache/camel/ExchangePropertyKey.java | 26 ++++++++++++++++++++++
 .../java/org/apache/camel/processor/Pipeline.java  |  1 +
 .../org/apache/camel/processor/SendProcessor.java  |  5 +++--
 .../org/apache/camel/support/AbstractExchange.java | 13 +++++++++++
 .../camel/support/DefaultPooledExchange.java       |  3 +++
 6 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Exchange.java b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
index af4e559..b69df8d 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Exchange.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
@@ -293,6 +293,22 @@ public interface Exchange {
     void setPattern(ExchangePattern pattern);
 
     /**
+     * Returns a property associated with this exchange by the key
+     *
+     * @param  key the exchange key
+     * @return     the value of the given property or <tt>null</tt> if there is no property for the given key
+     */
+    Object getProperty(ExchangePropertyKey key);
+
+    /**
+     * Sets a property on the exchange
+     *
+     * @param key   the exchange key
+     * @param value to associate with the name
+     */
+    void setProperty(ExchangePropertyKey key, Object value);
+
+    /**
      * Returns a property associated with this exchange by name
      *
      * @param  name the name of the property
diff --git a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
new file mode 100644
index 0000000..1228c18
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
@@ -0,0 +1,26 @@
+/*
+ * 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.camel;
+
+/**
+ * An enum of common and known keys for exchange properties used by camel-core.
+ */
+public enum ExchangePropertyKey {
+
+    TO_ENDPOINT
+
+}
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Pipeline.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Pipeline.java
index 728e31a..4973fb9 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Pipeline.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Pipeline.java
@@ -106,6 +106,7 @@ public class Pipeline extends AsyncProcessorSupport implements Navigate<Processo
 
                 processor.process(exchange, this);
             } else {
+                // TODO: optimize we can likely avoid copy results due to same exchange instance
                 ExchangeHelper.copyResults(exchange, exchange);
 
                 // logging nextExchange as it contains the exchange that might have altered the payload and since
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java
index a82be08..784d28e 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/SendProcessor.java
@@ -24,6 +24,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointAware;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
+import org.apache.camel.ExchangePropertyKey;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.Traceable;
 import org.apache.camel.spi.IdAware;
@@ -134,7 +135,7 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
                 target.setPattern(destinationExchangePattern != null ? destinationExchangePattern : pattern);
             }
             // set property which endpoint we send to
-            target.setProperty(Exchange.TO_ENDPOINT, destination.getEndpointUri());
+            exchange.setProperty(ExchangePropertyKey.TO_ENDPOINT, destination.getEndpointUri());
 
             final boolean sending = camelContext.isEventNotificationApplicable()
                     && EventHelper.notifyExchangeSending(exchange.getContext(), target, destination);
@@ -179,7 +180,7 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E
                 exchange.setPattern(destinationExchangePattern != null ? destinationExchangePattern : pattern);
             }
             // set property which endpoint we send to
-            exchange.setProperty(Exchange.TO_ENDPOINT, destination.getEndpointUri());
+            exchange.setProperty(ExchangePropertyKey.TO_ENDPOINT, destination.getEndpointUri());
 
             LOG.debug(">>>> {} {}", destination, exchange);
 
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java b/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
index e4f1cdb..4023be6 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
@@ -30,6 +30,7 @@ import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
+import org.apache.camel.ExchangePropertyKey;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.ExtendedExchange;
 import org.apache.camel.Message;
@@ -53,6 +54,8 @@ class AbstractExchange implements ExtendedExchange {
     final CamelContext context;
     // optimize to create properties always and with a reasonable small size
     final Map<String, Object> properties = new ConcurrentHashMap<>(8);
+    // optimize for known exchange properties
+    final Object[] knownProperties = new Object[ExchangePropertyKey.values().length];
     long created;
     Message in;
     Message out;
@@ -184,6 +187,16 @@ class AbstractExchange implements ExtendedExchange {
     }
 
     @Override
+    public Object getProperty(ExchangePropertyKey key) {
+        return knownProperties[key.ordinal()];
+    }
+
+    @Override
+    public void setProperty(ExchangePropertyKey key, Object value) {
+        knownProperties[key.ordinal()] = value;
+    }
+
+    @Override
     public Object getProperty(String name) {
         return properties.get(name);
     }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultPooledExchange.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultPooledExchange.java
index b13e73b..f381c9f 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultPooledExchange.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultPooledExchange.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.support;
 
+import java.util.Arrays;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -76,6 +78,7 @@ public final class DefaultPooledExchange extends AbstractExchange implements Poo
         if (created > 0 && (forced || autoRelease)) {
             this.created = 0; // by setting to 0 we also flag that this exchange is done and needs to be reset to use again
             this.properties.clear();
+            Arrays.fill(this.knownProperties, null);
             this.exchangeId = null;
             if (in != null && in.getClass() == originalInClassType) {
                 // okay we can reuse in


[camel] 01/02: CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.

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

davsclaus pushed a commit to branch opt-exchangekey
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8ffc458c1e87778ae6f7d24ba40432d6b1471d62
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 11 06:08:58 2021 +0100

    CAMEL-16326: camel-core - Optimize usage of exchanage properties for state in routing engine.
---
 core/camel-api/src/main/java/org/apache/camel/Exchange.java | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Exchange.java b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
index 7630c65..af4e559 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Exchange.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
@@ -65,6 +65,14 @@ import org.apache.camel.spi.annotations.ConstantProvider;
 @ConstantProvider("org.apache.camel.ExchangeConstantProvider")
 public interface Exchange {
 
+    // TODO: camel-core-processor using exchange properties for meta-data
+    // gather list of different keys they use, and then make an optimized
+    // exchange property map for this by getting key via some ordinal value (0, 1, 2, 3, etc)
+    // that is an index to an array that holds the value
+    // and then that array is reset in reset method
+    // and the getProperty is then aware of these special keys to lookup in array instead of map
+    // and then do profiling again JDK mission control, likely 1.4mb reduced down to very little
+
     String AUTHENTICATION = "CamelAuthentication";
     String AUTHENTICATION_FAILURE_POLICY_ID = "CamelAuthenticationFailurePolicyId";
     @Deprecated