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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2a47682  camel-http - Little optimize and load tests to reuse template 
to avoid creating garbage objects.
2a47682 is described below

commit 2a47682a4e85a4aaca47875df122546188ece6e0
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Feb 16 16:01:56 2021 +0100

    camel-http - Little optimize and load tests to reuse template to avoid 
creating garbage objects.
---
 .../apache/camel/component/http/HttpProducerLoadTest.java  | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerLoadTest.java
 
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerLoadTest.java
index 57ddd62..e9fc12b 100644
--- 
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerLoadTest.java
+++ 
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerLoadTest.java
@@ -20,6 +20,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.http.handler.DrinkValidationHandler;
@@ -85,10 +87,20 @@ public class HttpProducerLoadTest extends BaseHttpTest {
 
         StopWatch watch = new StopWatch();
 
+        // do not use template but reuse exchange/producer to be light-weight
+        // and not create additional objects in the JVM as we want to analyze
+        // the "raw" http producer
         Endpoint to = getMandatoryEndpoint("direct:echo");
+        Producer producer = to.createProducer();
+        producer.start();
+
+        Exchange exchange = to.createExchange();
+        exchange.getMessage().setHeaders(map);
         for (int i = 0; i < 10000000; i++) {
-            template.sendBodyAndHeaders(to, "Message " + i, map);
+            exchange.getMessage().setBody("Message " + i);
+            producer.process(exchange);
         }
+        producer.stop();
 
         LOG.info("Took {} ms", watch.taken());
     }

Reply via email to