Skip to content

Commit 2f70d70

Browse files
committed
Add continuous performance testing setup
1 parent 41f650a commit 2f70d70

File tree

5 files changed

+120
-8
lines changed

5 files changed

+120
-8
lines changed

.gitlab-ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variables:
2+
MAVEN_CLI_OPTS: ""
3+
MAVEN_OPTS: "-Dmaven.repo.local=cache/.m2/repository"
4+
5+
cache:
6+
paths:
7+
- cache/.m2/repository/
8+
9+
run_measurement:
10+
stage: test
11+
script:
12+
- export BENCHMARK_DIR=/ext_data/
13+
- export BENCHMARK_RESULT_DIR=${BENCHMARK_DIR}results/$(date '+%d-%m-%Y-%s%N')/
14+
- export BENCHMARK_MAP_NAME=andorra-190101.osm.pbf
15+
- export BENCHMARK_MAP_URL=http://download.geofabrik.de/europe/${BENCHMARK_MAP_NAME}
16+
- mkdir -p ${BENCHMARK_DIR}osm
17+
- export BENCHMARK_MAP_PATH=${BENCHMARK_DIR}osm/${BENCHMARK_MAP_NAME}
18+
- mvn $MAVEN_CLI_OPTS package -DskipTests -pl tools -am
19+
- chmod +x -R benchmark
20+
- benchmark/download_map.sh $BENCHMARK_MAP_URL $BENCHMARK_MAP_PATH
21+
- benchmark/benchmark.sh $BENCHMARK_DIR $BENCHMARK_RESULT_DIR $BENCHMARK_MAP_PATH
22+
- benchmark/post_benchmark.sh $BENCHMARK_RESULT_DIR $BENCHMARK_DB_USER $BENCHMARK_DB_PWD $BENCHMARK_DB_URL
23+
- rm -rf $BENCHMARK_RESULT_DIR

benchmark/benchmark.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# usage:
3+
# benchmark/benchmark.sh <data_dir> <results_dir> <osm_map_path>
4+
#
5+
# where:
6+
# <data_dir> = directory used to download map and store results
7+
# <results_dir> = name of directory where results of this run are stored
8+
# <osm_map_path> = path to osm map the measurement is run on
9+
10+
# make this script exit if a command fails, a variable is missing etc.
11+
set -euo pipefail
12+
13+
defaultDataDir=measurements/
14+
defaultSingleResultsDir=measurements/results/$(date '+%d-%m-%Y-%s%N')/
15+
defaultMap=core/files/andorra.osm.pbf
16+
17+
# this is the directory where we read/write data from/to
18+
DATA_DIR=${1:-$defaultDataDir}
19+
RESULTS_DIR=${DATA_DIR}results/
20+
TMP_DIR=${DATA_DIR}tmp/
21+
SINGLE_RESULTS_DIR=${2:-$defaultSingleResultsDir}
22+
OSM_MAP=${3:-$defaultMap}
23+
24+
# create directories
25+
mkdir -p ${DATA_DIR}
26+
mkdir -p ${RESULTS_DIR}
27+
mkdir -p ${TMP_DIR}
28+
mkdir -p ${SINGLE_RESULTS_DIR}
29+
30+
# actually run the benchmark
31+
java -cp tools/target/graphhopper-tools-*-jar-with-dependencies.jar com.graphhopper.tools.Measurement \
32+
datareader.file=${OSM_MAP} \
33+
measurement.folder=${SINGLE_RESULTS_DIR} \
34+
measurement.clean=true \
35+
measurement.summaryfile=${RESULTS_DIR}summary.dat \
36+
measurement.repeats=1 \
37+
measurement.run_slow_routing=false \
38+
prepare.ch.weightings=fastest \
39+
prepare.lm.weightings=fastest \
40+
graph.flag_encoders=car \
41+
prepare.ch.edge_based=off \
42+
graph.location=${TMP_DIR}measurement-gh \
43+
prepare.min_network_size=200 \
44+
prepare.min_oneway_network_size=200 \
45+
measurement.json=true \
46+
measurement.count=10
47+

benchmark/download_map.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# usage:
3+
# benchmark/download_map.sh <osm_map_url> <osm_map_path>
4+
#
5+
# where:
6+
# <osm_map_url> = remote url the map is downloaded from
7+
# <osm_map_path> = local path the map is downloaded to
8+
9+
# make this script exit if a command fails, a variable is missing etc.
10+
set -euo pipefail
11+
12+
# download OSM map if it does not exist already
13+
if [ ! -f $2 ];
14+
then
15+
wget -S -nv -O $2 $1
16+
fi

benchmark/post_benchmark.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# usage:
3+
# benchmark/post_benchmark.sh <results_dir> <user> <pwd> <url>
4+
#
5+
# where:
6+
# <results_dir> = path to a folder with measurement results to be posted
7+
# <user>:<pwd> = credentials for basic auth
8+
# <url> = url the results are posted to
9+
10+
# make this script exit if a command faiils, a variable is missing etc.
11+
set -euo pipefail
12+
13+
# use curl to post results (requires external variables to be set)
14+
for f in $1*.json
15+
# use some options to curl to make sure we notice when error is returned
16+
do curl --show-error --fail -XPOST -u $2:$3 -H "Content-Type: application/json" -d @$f $4
17+
done
18+

tools/src/main/java/com/graphhopper/tools/Measurement.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.io.File;
4141
import java.io.FileWriter;
4242
import java.io.IOException;
43+
import java.nio.file.Files;
44+
import java.nio.file.Paths;
4345
import java.text.SimpleDateFormat;
4446
import java.util.*;
4547
import java.util.Map.Entry;
@@ -58,7 +60,7 @@ public class Measurement {
5860
private long seed;
5961
private int maxNode;
6062

61-
public static void main(String[] strs) {
63+
public static void main(String[] strs) throws IOException {
6264
CmdArgs cmdArgs = CmdArgs.read(strs);
6365
int repeats = cmdArgs.getInt("measurement.repeats", 1);
6466
for (int i = 0; i < repeats; ++i)
@@ -67,24 +69,29 @@ public static void main(String[] strs) {
6769

6870
// creates properties file in the format key=value
6971
// Every value is one y-value in a separate diagram with an identical x-value for every Measurement.start call
70-
void start(CmdArgs args) {
72+
void start(CmdArgs args) throws IOException {
7173
final String graphLocation = args.get("graph.location", "");
7274
final boolean useJson = args.getBool("measurement.json", false);
7375
boolean cleanGraph = args.getBool("measurement.clean", false);
7476
String summaryLocation = args.get("measurement.summaryfile", "");
7577
final String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss").format(new Date());
7678
put("measurement.timestamp", timeStamp);
77-
String propLocation = args.get("measurement.location", "");
78-
if (isEmpty(propLocation)) {
79+
String propFolder = args.get("measurement.folder", "");
80+
if (!propFolder.isEmpty()) {
81+
Files.createDirectories(Paths.get(propFolder));
82+
}
83+
String propFilename = args.get("measurement.filename", "");
84+
if (isEmpty(propFilename)) {
7985
if (useJson) {
8086
String gitInfo = Constants.GIT_INFO;
8187
// if we start from IDE or otherwise jar was not built using maven the git commit id will be unknown
82-
String prefix = gitInfo.startsWith("${git.commit.id}") ? "unknown" : gitInfo.split("\\|")[0].substring(0, 8);
83-
propLocation = prefix + "_" + timeStamp + ".json";
88+
String id = gitInfo.startsWith("${git.commit.id}") ? "unknown" : gitInfo.split("\\|")[0].substring(0, 8);
89+
propFilename = "measurement_" + id + "_" + timeStamp + ".json";
8490
} else {
85-
propLocation = "measurement" + timeStamp + ".properties";
91+
propFilename = "measurement" + timeStamp + ".properties";
8692
}
8793
}
94+
final String propLocation = Paths.get(propFolder).resolve(propFilename).toString();
8895
seed = args.getLong("measurement.seed", 123);
8996
put("measurement.gitinfo", args.get("measurement.gitinfo", ""));
9097
int count = args.getInt("measurement.count", 5000);
@@ -594,9 +601,10 @@ private void storeJson(String graphLocation, String jsonLocation) {
594601
result.put("gitinfo", gitInfoMap);
595602
result.put("metrics", properties);
596603
try {
604+
File file = new File(jsonLocation);
597605
new ObjectMapper()
598606
.writerWithDefaultPrettyPrinter()
599-
.writeValue(new File(jsonLocation), result);
607+
.writeValue(file, result);
600608
} catch (IOException e) {
601609
logger.error("Problem while storing json " + graphLocation + ", " + jsonLocation, e);
602610
}

0 commit comments

Comments
 (0)