Browse Source

Adds JMH benchmark module

Starts with Contract tests as this was suggested a place we may need
caching.

See #214
pull/229/head
Adrian Cole 10 years ago
parent
commit
feb49476ef
  1. 1
      CHANGELOG.md
  2. 10
      benchmark/README.md
  3. 93
      benchmark/pom.xml
  4. 46
      benchmark/src/main/java/feign/benchmark/ContractBenchmarks.java
  5. 39
      benchmark/src/main/java/feign/benchmark/FeignTestInterface.java
  6. 57
      benchmark/src/main/java/feign/benchmark/JAXRSTestInterface.java

1
CHANGELOG.md

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
### Version 8.2
* Adds JMH benchmark module
* Enforces source compatibility with animal-sniffer
### Version 8.1

10
benchmark/README.md

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
Feign Benchmarks
===================
This module includes [JMH](http://openjdk.java.net/projects/code-tools/jmh/) benchmarks for Feign.
=== Building the benchmark
Install and run `mvn -Dfeign.version=8.1.0` to produce `target/benchmark` pinned to version `8.1.0`
=== Running the benchmark
Execute `target/benchmark`

93
benchmark/pom.xml

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-benchmark</artifactId>
<packaging>jar</packaging>
<version>8.1.0-SNAPSHOT</version>
<name>Feign Benchmark (JMH)</name>
<properties>
<jmh.version>1.8</jmh.version>
</properties>
<dependencies>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-jaxrs</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.skife.maven</groupId>
<artifactId>really-executable-jar-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<programFile>benchmark</programFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>really-executable-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

46
benchmark/src/main/java/feign/benchmark/ContractBenchmarks.java

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
package feign.benchmark;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import java.util.concurrent.TimeUnit;
import feign.Contract;
import feign.jaxrs.JAXRSContract;
@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 5, time = 1)
@Fork(3)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
public class ContractBenchmarks {
private Contract feignContract;
private Contract jaxrsContract;
@Setup
public void setup() {
feignContract = new Contract.Default();
jaxrsContract = new JAXRSContract();
}
@Benchmark
public void parseFeign() {
feignContract.parseAndValidatateMetadata(FeignTestInterface.class);
}
@Benchmark
public void parseJAXRS() {
jaxrsContract.parseAndValidatateMetadata(JAXRSTestInterface.class);
}
}

39
benchmark/src/main/java/feign/benchmark/FeignTestInterface.java

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
package feign.benchmark;
import java.util.List;
import javax.ws.rs.HeaderParam;
import feign.Body;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
import feign.Response;
@Headers("Accept: application/json")
interface FeignTestInterface {
@RequestLine("GET /?Action=GetUser&Version=2010-05-08&limit=1")
Response query();
@RequestLine("GET /domains/{domainId}/records?name={name}&type={type}")
Response mixedParams(@Param("domainId") int id,
@Param("name") String nameFilter,
@Param("type") String typeFilter);
@RequestLine("PATCH /")
Response customMethod();
@RequestLine("PUT /")
@Headers("Content-Type: application/json")
void bodyParam(List<String> body);
@RequestLine("POST /")
@Body("%7B\"customer_name\": \"{customer_name}\", \"user_name\": \"{user_name}\", \"password\": \"{password}\"%7D")
void form(@Param("customer_name") String customer, @Param("user_name") String user,
@Param("password") String password);
@RequestLine("POST /")
@Headers({"Happy: sad", "Auth-Token: {authToken}"})
void headers(@HeaderParam("authToken") String token);
}

57
benchmark/src/main/java/feign/benchmark/JAXRSTestInterface.java

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
package feign.benchmark;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import feign.Headers;
import feign.Response;
@Consumes("application/json")
interface JAXRSTestInterface {
@GET
@Path("/?Action=GetUser&Version=2010-05-08&limit=1")
Response query();
@GET
@Path("/domains/{domainId}/records")
Response mixedParams(@PathParam("domainId") int id, @QueryParam("name") String nameFilter,
@QueryParam("type") String typeFilter);
@PATCH
Response customMethod();
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PATCH")
@interface PATCH {
}
@PUT
@Produces("application/json")
void bodyParam(List<String> body);
@POST
void form(@FormParam("customer_name") String customer, @FormParam("user_name") String user,
@FormParam("password") String password);
@POST
@Headers("Happy: sad")
void headers(@HeaderParam("Auth-Token") String token);
}
Loading…
Cancel
Save