Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "src/test/resources/maxmind-db"]
path = src/test/resources/maxmind-db
path = reader/src/test/resources/maxmind-db
url = https://github.com/maxmind/MaxMind-DB
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ Maven, you must
Failure to do so will result in `InvalidDatabaseException` exceptions being
thrown when querying the database.

## Benchmarking ##

Set an environment variable `GEO_LITE` with the path to `GeoLite2-City.mmdb`.

```shell
mvn -Dcheckstyle.skip -DskipTests clean package
GEO_LITE=/.../GeoLite2-City.mmdb java -jar benchmarks/target/microbenchmarks.jar
```

For more, see [https://github.com/openjdk/jmh](https://github.com/openjdk/jmh) or
`java -jar benchmarks/target/microbenchmarks.jar -h`.

## Format ##

The MaxMind DB format is an open format for quickly mapping IP addresses to
Expand Down
73 changes: 73 additions & 0 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maxmind.db</groupId>
<artifactId>benchmarks</artifactId>
<version>3.1.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<jmhVersion>1.37</jmhVersion>
</properties>
<dependencies>
<dependency>
<groupId>com.maxmind.db</groupId>
<artifactId>maxmind-db</artifactId>
<version>3.1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmhVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>11</release>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmhVersion}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>microbenchmarks</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/services/javax.annotation.processing.Processor</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
71 changes: 71 additions & 0 deletions benchmarks/src/main/java/com/maxmind/db/BenchmarkGet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.maxmind.db;

import com.maxmind.db.Reader.FileMode;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
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.OperationsPerInvocation;
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 org.openjdk.jmh.infra.Blackhole;

@State(Scope.Benchmark)
@Warmup(iterations = 3, time = 5)
@Measurement(iterations = 10, time = 5)
@Fork(1)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class BenchmarkGet {
private static final int COUNT = 1_000_000;

private static InetAddress[] getInetAddresses(final int seed) throws UnknownHostException {
final InetAddress[] addresses = new InetAddress[COUNT];
final Random random = new Random(seed);
final byte[] address = new byte[4];
for (int addressIx = 0; addressIx < COUNT; addressIx++) {
random.nextBytes(address);
addresses[addressIx] = InetAddress.getByAddress(address);
}
return addresses;
}

InetAddress[] addresses;
Reader reader;
Reader cachedReader;

@Setup
public void setup() throws IOException {
addresses = getInetAddresses(0);
final File database = new File(System.getenv("GEO_LITE"));
reader = new Reader(database, FileMode.MEMORY_MAPPED, NoCache.getInstance());
cachedReader = new Reader(database, FileMode.MEMORY_MAPPED, new CHMCache());
}

@Benchmark
@OperationsPerInvocation(COUNT)
public void withoutCaching(Blackhole bh) throws IOException {
for (InetAddress address: addresses) {
bh.consume(reader.get(address, Map.class));
}
}

@Benchmark
@OperationsPerInvocation(COUNT)
public void withCaching(Blackhole bh) throws IOException {
for (InetAddress address: addresses) {
bh.consume(cachedReader.get(address, Map.class));
}
}
}
8 changes: 4 additions & 4 deletions dev-bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ fi


# could be combined with the primary build
mvn release:clean
mvn release:prepare -DreleaseVersion="$version" -Dtag="$tag"
mvn release:perform
mvn -pl reader release:clean
mvn -pl reader release:prepare -DreleaseVersion="$version" -Dtag="$tag"
mvn -pl reader release:perform
rm -fr ".gh-pages/doc/$tag"
cp -r target/checkout/target/reports/apidocs ".gh-pages/doc/$tag"
cp -r reader/target/checkout/target/reports/apidocs ".gh-pages/doc/$tag"
rm .gh-pages/doc/latest
ln -fs "$tag" .gh-pages/doc/latest

Expand Down
Loading
Loading