Skip to content
Permalink
Browse files
Add http profiling demo
  • Loading branch information
davsclaus committed Mar 12, 2021
1 parent 6027bb8 commit 72f547f6e357078be2c83d3c08c93c08387dc630
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 0 deletions.
@@ -36,6 +36,7 @@

<modules>
<module>timer-log</module>
<module>timer-http</module>
<module>kafka-s3</module>
</modules>

@@ -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).

@@ -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>
@@ -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);
}

}
@@ -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");
}
}
@@ -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
@@ -0,0 +1,30 @@
<?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.
-->
<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>

0 comments on commit 72f547f

Please sign in to comment.