This is an automated email from the ASF dual-hosted git repository. dfoulks pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-performance-tests.git
commit 72f547f6e357078be2c83d3c08c93c08387dc630 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Mar 12 14:36:03 2021 +0100 Add http profiling demo --- profiling/pom.xml | 1 + profiling/timer-http/README.md | 22 +++++ profiling/timer-http/pom.xml | 98 ++++++++++++++++++++++ .../org/apache/camel/example/MyApplication.java | 38 +++++++++ .../org/apache/camel/example/MyRouteBuilder.java | 31 +++++++ .../src/main/resources/application.properties | 49 +++++++++++ .../src/main/resources/logback.xml} | 34 +++----- 7 files changed, 250 insertions(+), 23 deletions(-) diff --git a/profiling/pom.xml b/profiling/pom.xml index 36c93db..cf5315e 100644 --- a/profiling/pom.xml +++ b/profiling/pom.xml @@ -36,6 +36,7 @@ <modules> <module>timer-log</module> + <module>timer-http</module> <module>kafka-s3</module> </modules> diff --git a/profiling/timer-http/README.md b/profiling/timer-http/README.md new file mode 100644 index 0000000..7be1dbc --- /dev/null +++ b/profiling/timer-http/README.md @@ -0,0 +1,22 @@ +## Camel Performance - Timer HTTP + +This is a small demo application that is used for cpu and memory profiling the HTTP component. + +The demo uses a timer to trigger 1000 msg/sec that calls a HTTP service. + + +### Profiling + +At first start the HTTP service using docker: + + docker run -p 5678:5678 hashicorp/http-echo -text="hello world" + +Then the demo can be run with `mvn camel:run` or by running the `MyApplication.java` +main class (from an IDE you can right-click this file and Run...). + +A profile such as _YourKit_ or _JDK mission control_ can be attached to +the running application and manually profiled. + +The application can be configured in `application.properties` such as +the functionality to turn on|off the pooling of exchanges (and other objects). + diff --git a/profiling/timer-http/pom.xml b/profiling/timer-http/pom.xml new file mode 100644 index 0000000..3c57513 --- /dev/null +++ b/profiling/timer-http/pom.xml @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <parent> + <groupId>org.apache.camel.tests</groupId> + <artifactId>profiling</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>timer-http</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>Camel Performance :: Profiling :: Timer HTTP</name> + <description>A little example to profile Camel routing engine</description> + + <dependencyManagement> + <dependencies> + <!-- Add Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bom</artifactId> + <version>${camel.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-main</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-timer</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-http</artifactId> + </dependency> + + <!-- logging --> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-core</artifactId> + <version>${logback-version}</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback-version}</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <!-- to run the application --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${camel.version}</version> + <configuration> + <mainClass>org.apache.camel.example.MyApplication</mainClass> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/profiling/timer-http/src/main/java/org/apache/camel/example/MyApplication.java b/profiling/timer-http/src/main/java/org/apache/camel/example/MyApplication.java new file mode 100644 index 0000000..496b37d --- /dev/null +++ b/profiling/timer-http/src/main/java/org/apache/camel/example/MyApplication.java @@ -0,0 +1,38 @@ +/* + * 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.example; + +import org.apache.camel.main.Main; + +/** + * Main class that boot the Camel application + */ +public final class MyApplication { + + private MyApplication() { + } + + public static void main(String[] args) throws Exception { + // use Camels Main class + Main main = new Main(); + // and add the routes (you can specify multiple classes) + main.configure().addRoutesBuilder(MyRouteBuilder.class); + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + main.run(args); + } + +} diff --git a/profiling/timer-http/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/profiling/timer-http/src/main/java/org/apache/camel/example/MyRouteBuilder.java new file mode 100644 index 0000000..e08606c --- /dev/null +++ b/profiling/timer-http/src/main/java/org/apache/camel/example/MyRouteBuilder.java @@ -0,0 +1,31 @@ +/* + * 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.example; + +import org.apache.camel.builder.RouteBuilder; + +public class MyRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("timer:foo?delay=10s&period={{myPeriod}}&includeMetadata=false") + // we can include a request body + .setBody(constant("Hi from Camel")) + .to("http://localhost:5678/") + .to("log:out?level=OFF"); + } +} diff --git a/profiling/timer-http/src/main/resources/application.properties b/profiling/timer-http/src/main/resources/application.properties new file mode 100644 index 0000000..f106b44 --- /dev/null +++ b/profiling/timer-http/src/main/resources/application.properties @@ -0,0 +1,49 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# to configure camel main +# here you can configure options on camel main (see MainConfigurationProperties class) +camel.main.name = MyTinyCamel + +# run in lightweight mode to be tiny as possible +camel.main.lightweight = true + +# use short uuid which uses 16 bytes vs 32 by default +camel.main.uuid-generator = short + +# use object pooling to reduce JVM garbage collection +camel.main.exchange-factory = pooled +camel.main.exchange-factory-capacity = 25 +camel.main.exchange-factory-statistics-enabled = true + +# turn off various things on http component we do not need +camel.component.http.cookie-management-disabled = true +camel.component.http.auth-caching-disabled = true +camel.component.http.content-compression-disabled = true + +# we can turn on|off whether to include request/response header mappings +# camel.component.http.skip-request-headers = true +# camel.component.http.skip-response-headers = true + +# we can turn copy headers off as we do not need this as http producer only +camel.component.http.copy-headers = false + +# run for about 2 minutes +camel.main.duration-max-seconds = 130 + +# properties used in the route +myPeriod = 1 diff --git a/profiling/pom.xml b/profiling/timer-http/src/main/resources/logback.xml similarity index 53% copy from profiling/pom.xml copy to profiling/timer-http/src/main/resources/logback.xml index 36c93db..a798d0b 100644 --- a/profiling/pom.xml +++ b/profiling/timer-http/src/main/resources/logback.xml @@ -17,26 +17,14 @@ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.camel.tests</groupId> - <artifactId>camel-tests-parent</artifactId> - <version>1.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>profiling</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>pom</packaging> - <name>Camel Performance :: Profiling</name> - - <modules> - <module>timer-log</module> - <module>kafka-s3</module> - </modules> - -</project> +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <root level="INFO"> + <appender-ref ref="STDOUT" /> + </root> +</configuration>