Skip to content

Commit

Permalink
Adds gbench microbenchmarking library; example mapmatch benchmark. (#…
Browse files Browse the repository at this point in the history
…2222)

* Adds gbench microbenchmarking library; example mapmatch benchmark.

- Adds a CMake support for Google Benchmark (aka, 'gbench') for
  performing highly-configurable microbenchmarking. This library
  provides standardize benchmark runners and reporting, which we can
  use in the future for tracking regressions on releases.
- Adds an example of using gbench for the mapmatching module, which
  currently lacks any CPU or latency benchmarks.
  • Loading branch information
Buro Mookerji committed Apr 21, 2020
1 parent db13688 commit 1c4a4f0
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines.yml
Expand Up @@ -56,7 +56,7 @@ jobs:
- script: |
cmake --version
cmake -H$(Build.SourcesDirectory) -B%BUILD_DIR% -G "%GENERATOR%" -DCMAKE_TOOLCHAIN_FILE=%VCPKG_DIR%\scripts\buildsystems\vcpkg.cmake -DVCPKG_APPLOCAL_DEPS=ON -DENABLE_CCACHE=OFF -DENABLE_DATA_TOOLS=OFF -DENABLE_HTTP=OFF -DENABLE_NODE_BINDINGS=OFF -DENABLE_PYTHON_BINDINGS=OFF -DENABLE_SERVICES=OFF -DENABLE_TOOLS=OFF
cmake -H$(Build.SourcesDirectory) -B%BUILD_DIR% -G "%GENERATOR%" -DCMAKE_TOOLCHAIN_FILE=%VCPKG_DIR%\scripts\buildsystems\vcpkg.cmake -DVCPKG_APPLOCAL_DEPS=ON -DENABLE_CCACHE=OFF -DENABLE_DATA_TOOLS=OFF -DENABLE_HTTP=OFF -DENABLE_NODE_BINDINGS=OFF -DENABLE_PYTHON_BINDINGS=OFF -DENABLE_SERVICES=OFF -DENABLE_TOOLS=OFF -DENABLE_BENCHMARKS=OFF
displayName: 'Run CMake to configure build'
- script: |
Expand Down
8 changes: 8 additions & 0 deletions .circleci/config.yml
Expand Up @@ -150,6 +150,8 @@ jobs:
- run: make -C build utrecht_tiles
- run: make -C build -j2 tests
- run: make -C build -j2 check
- run: make -C build -j2 benchmarks

This comment has been minimized.

Copy link
@kevinkreiser

kevinkreiser Aug 7, 2020

Member

@mookerji do you think its worth it to run the benchmarks in debug mode? presumably we dont really care about the values a debug build spits out right?

- run: make -C build run-benchmarks
# Note: we save the cache here before doing linting so that if linting fails, we can rebuild quickly
# for follow-up fixes
- save_cache:
Expand Down Expand Up @@ -182,6 +184,8 @@ jobs:
- run: make -C build utrecht_tiles
- run: make -C build -j2 tests
- run: make -C build -j2 check
- run: make -C build -j2 benchmarks
- run: make -C build run-benchmarks
- save_cache:
key: ccache-release-linux-x86_64-{{ .Branch }}-{{ epoch }}
paths:
Expand All @@ -208,6 +212,8 @@ jobs:
- run: make -C build utrecht_tiles
- run: make -C build -j2 tests
- run: make -C build -j2 check
- run: make -C build -j2 benchmarks
- run: make -C build run-benchmarks
- save_cache:
key: ccache-release-linux-x86_32-{{ .Branch }}-{{ epoch }}
paths:
Expand All @@ -233,6 +239,8 @@ jobs:
- run: make -C build utrecht_tiles
- run: make -C build -j2 tests
- run: make -C build -j2 check
- run: make -C build -j2 benchmarks
- run: make -C build run-benchmarks
- save_cache:
key: ccache-release-macos-{{ .Branch }}-{{ epoch }}
paths:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -22,3 +22,6 @@
[submodule "third_party/microtar"]
path = third_party/microtar
url = https://github.com/rxi/microtar.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://github.com/google/benchmark
8 changes: 7 additions & 1 deletion CMakeLists.txt
Expand Up @@ -29,6 +29,7 @@ option(ENABLE_COMPILER_WARNINGS "Build with compiler warnings" OFF)
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)
option(ENABLE_TESTS "Enable Valhalla tests" ON)
option(ENABLE_WERROR "Convert compiler warnings to errors. Requires ENABLE_COMPILER_WARNINGS=ON to take effect" OFF)
option(ENABLE_BENCHMARKS "Enable microbenchmarking" ON)
set(LOGGING_LEVEL "" CACHE STRING "Logging level, default is INFO")
set_property(CACHE LOGGING_LEVEL PROPERTY STRINGS "NONE;ALL;ERROR;WARN;INFO;DEBUG;TRACE")

Expand Down Expand Up @@ -123,7 +124,7 @@ if(NOT TARGET CURL::CURL)
find_package(CURL REQUIRED)
endif()
set_target_properties(CURL::CURL PROPERTIES
#INTERFACE_LINK_LIBRARIES "${CURL_LIBRARIES}"
#INTERFACE_LINK_LIBRARIES "${CURL_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIR}"
INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
if(NOT WIN32)
Expand Down Expand Up @@ -321,6 +322,11 @@ if(ENABLE_TESTS)
add_subdirectory(test)
endif()

# NOTE(mookerji): Windows CI seems to break on the gbench build, so shelve Win32 support for now.
if(ENABLE_BENCHMARKS AND NOT WIN32)
add_subdirectory(bench)
endif()

## Packaging via CPack
include(CPackComponent)

Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -150,6 +150,7 @@ Important build options include:
| `-DENABLE_NODE_BINDINGS` (`ON` / `OFF`) | Build the node bindings (defaults to on)|
| `-DENABLE_COMPILER_WARNINGS` (`ON` / `OFF`) | Build with common compiler warnings (defaults to off)|
| `-DENABLE_WERROR` (`ON` / `OFF`) | Treat compiler warnings as errors (defaults to off). Requires `-DENABLE_COMPILER_WARNINGS=ON` to take effect.|
| `-DENABLE_BENCHMARKS` (`ON` / `OFF`) | Enable microbenchmarking (defaults to on).|

For more build options run the interactive GUI:

Expand Down Expand Up @@ -239,6 +240,17 @@ You may check some notes on [unit tests](docs/testing.md)

Coverage reports are automatically generated using codecov for each pull request, but you can also build them locally by passing `-DENABLE_COVERAGE=On` and running `make coverage`.

Benchmarks
----------

Valhalla includes several microbenchmarks which you can build and run using:

make benchmarks
make run-benchmarks

They are enabled by the `-DENABLE_BENCHMARKS=On` CMake flag and are currently only available for
Linux and MacOS.

Command Line Tools
------------------
#### valhalla_run_route
Expand Down
30 changes: 30 additions & 0 deletions bench/CMakeLists.txt
@@ -0,0 +1,30 @@
add_subdirectory(${VALHALLA_SOURCE_DIR}/third_party/benchmark
${CMAKE_BINARY_DIR}/benchmark)

# Custom targets building and running all microbenchmarks in the project
add_custom_target(benchmarks)
add_custom_target(run-benchmarks)

# Benchmarks generally require utrecht test tiles to be present, so add this dependency by default.
add_dependencies(benchmarks utrecht_tiles)

# Macro for defining Google Benchmark microbenchmark targets
macro (add_valhalla_benchmark target_file)
set(target_name benchmark-${target_file})
add_executable(${target_name} ${target_file}.cc)
set_target_properties(${target_name}
PROPERTIES
COMPILE_DEFINITIONS
VALHALLA_SOURCE_DIR="${VALHALLA_SOURCE_DIR}/")
target_link_libraries(${target_name} valhalla benchmark::benchmark)
add_dependencies(benchmarks ${target_name})
# Add a custom target running the benchmark
add_custom_target(run-${target_name}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${target_name}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running ${target_name} in ${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${target_name})
add_dependencies(run-benchmarks run-${target_name})
endmacro()

add_subdirectory(meili)
1 change: 1 addition & 0 deletions bench/meili/CMakeLists.txt
@@ -0,0 +1 @@
add_valhalla_benchmark(mapmatch)
115 changes: 115 additions & 0 deletions bench/meili/config.json
@@ -0,0 +1,115 @@
{
"mjolnir": {
"tile_dir": "test/data/utrecht_tiles",
"concurrency": 1
},
"loki": {
"actions": [
"route",
"sources_to_targets",
"trace_route",
"trace_attributes"
],
"logging": {
"long_request": 100
},
"service_defaults": {
"minimum_reachability": 50,
"radius": 0,
"search_cutoff": 35000,
"node_snap_tolerance": 5,
"street_side_tolerance": 5,
"heading_tolerance": 60
}
},
"thor": {
"logging": {
"long_request": 110
}
},
"skadi": {
"actons": [
"height"
],
"logging": {
"long_request": 5
}
},
"meili": {
"customizable": [
"turn_penalty_factor",
"max_route_distance_factor",
"max_route_time_factor",
"search_radius"
],
"mode": "auto",
"grid": {
"cache_size": 100240,
"size": 500
},
"default": {
"beta": 3,
"breakage_distance": 2000,
"geometry": false,
"gps_accuracy": 5,
"interpolation_distance": 10,
"max_route_distance_factor": 5,
"max_route_time_factor": 5,
"max_search_radius": 200,
"route": true,
"search_radius": 15,
"sigma_z": 4.07,
"turn_penalty_factor": 200
}
},
"service_limits": {
"auto": {
"max_distance": 5000000,
"max_locations": 20,
"max_matrix_distance": 400000,
"max_matrix_locations": 50
},
"auto_shorter": {
"max_distance": 5000000,
"max_locations": 20,
"max_matrix_distance": 400000,
"max_matrix_locations": 50
},
"isochrone": {
"max_contours": 4,
"max_distance": 25000,
"max_locations": 1,
"max_time": 120
},
"max_avoid_locations": 50,
"max_radius": 200,
"max_reachability": 100,
"max_alternates": 2,
"multimodal": {
"max_distance": 500000,
"max_locations": 50,
"max_matrix_distance": 0,
"max_matrix_locations": 0
},
"pedestrian": {
"max_distance": 250000,
"max_locations": 50,
"max_matrix_distance": 200000,
"max_matrix_locations": 50,
"max_transit_walking_distance": 10000,
"min_transit_walking_distance": 1
},
"skadi": {
"max_shape": 750000,
"min_resample": 10
},
"trace": {
"max_distance": 200000,
"max_gps_accuracy": 100,
"max_search_radius": 100,
"max_shape": 16000,
"max_best_paths": 4,
"max_best_paths_shape": 100
}
}
}
102 changes: 102 additions & 0 deletions bench/meili/fixtures/3km_loop_utrecht.json
@@ -0,0 +1,102 @@
{
"costing": "auto",
"format": "osrm",
"shape_match": "map_snap",
"shape": [
{
"lon": 5.08531221,
"lat": 52.0938563,
"type": "break"
},
{
"lon": 5.0865867,
"lat": 52.0930211,
"type": "break"
},
{
"lon": 5.08769141,
"lat": 52.0923946,
"type": "break"
},
{
"lon": 5.0896245,
"lat": 52.0912591,
"type": "break"
},
{
"lon": 5.0909416,
"lat": 52.090737,
"type": "break"
},
{
"lon": 5.0926623,
"lat": 52.0905021,
"type": "break"
},
{
"lon": 5.0946379,
"lat": 52.090737,
"type": "break"
},
{
"lon": 5.0961035,
"lat": 52.0907892,
"type": "break"
},
{
"lon": 5.097442,
"lat": 52.0909328,
"type": "break"
},
{
"lon": 5.09884401,
"lat": 52.09115474,
"type": "break"
},
{
"lon": 5.100416,
"lat": 52.0913244,
"type": "break"
},
{
"lon": 5.101733,
"lat": 52.09137664,
"type": "break"
},
{
"lon": 5.1034112,
"lat": 52.0915854,
"type": "break"
},
{
"lon": 5.10351751,
"lat": 52.09202915,
"type": "break"
},
{
"lon": 5.102345,
"lat": 52.0929627,
"type": "break"
},
{
"lon": 5.0959337,
"lat": 52.093477899999996,
"type": "break"
},
{
"lon": 5.0932129,
"lat": 52.0939153,
"type": "break"
},
{
"lon": 5.08858141,
"lat": 52.094623799999994,
"type": "break"
},
{
"lon": 5.0858904,
"lat": 52.0958159,
"type": "break"
}
]
}
17 changes: 17 additions & 0 deletions bench/meili/fixtures/intersection_matching1.json
@@ -0,0 +1,17 @@
{
"costing": "auto",
"format": "osrm",
"shape_match": "map_snap",
"shape": [
{
"lat": 52.0981267,
"lon": 5.129618,
"type": "break"
},
{
"lat": 52.098128,
"lon": 5.129725,
"type": "break"
}
]
}

0 comments on commit 1c4a4f0

Please sign in to comment.