From b4142f79725c9b232964973c30cd5c624b5c0a23 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 21 May 2024 22:09:11 +0200 Subject: [PATCH 1/7] Add benchmark for route --- scripts/ci/run_benchmarks.sh | 2 + src/benchmarks/CMakeLists.txt | 15 +++++- src/benchmarks/route.cpp | 88 +++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/benchmarks/route.cpp diff --git a/scripts/ci/run_benchmarks.sh b/scripts/ci/run_benchmarks.sh index 94cf57a57d7..f81b29e6f79 100755 --- a/scripts/ci/run_benchmarks.sh +++ b/scripts/ci/run_benchmarks.sh @@ -13,6 +13,8 @@ function run_benchmarks_for_folder { ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench" ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench" + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/route.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/route.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" ./$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench" ./$BENCHMARKS_FOLDER/json-render-bench "./$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench" ./$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench" diff --git a/src/benchmarks/CMakeLists.txt b/src/benchmarks/CMakeLists.txt index 233445c4bda..86353dbbf01 100644 --- a/src/benchmarks/CMakeLists.txt +++ b/src/benchmarks/CMakeLists.txt @@ -30,6 +30,18 @@ target_link_libraries(match-bench ${TBB_LIBRARIES} ${MAYBE_SHAPEFILE}) +add_executable(route-bench + EXCLUDE_FROM_ALL + route.cpp + $) + +target_link_libraries(route-bench + osrm + ${BOOST_BASE_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${TBB_LIBRARIES} + ${MAYBE_SHAPEFILE}) + add_executable(json-render-bench EXCLUDE_FROM_ALL json_render.cpp @@ -72,5 +84,6 @@ add_custom_target(benchmarks rtree-bench packedvector-bench match-bench + route-bench json-render-bench - alias-bench) + alias-bench) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp new file mode 100644 index 00000000000..ddcc21b2d81 --- /dev/null +++ b/src/benchmarks/route.cpp @@ -0,0 +1,88 @@ +#include "engine/engine_config.hpp" +#include "util/coordinate.hpp" +#include "util/timing_util.hpp" + +#include "osrm/route_parameters.hpp" + +#include "osrm/coordinate.hpp" +#include "osrm/engine_config.hpp" +#include "osrm/json_container.hpp" + +#include "osrm/osrm.hpp" +#include "osrm/status.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char *argv[]) +try +{ + if (argc < 2) + { + std::cerr << "Usage: " << argv[0] << " data.osrm\n"; + return EXIT_FAILURE; + } + + using namespace osrm; + + // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore + EngineConfig config; + config.storage_config = {argv[1]}; + config.algorithm = (argc > 2 && std::string{argv[2]} == "mld") ? EngineConfig::Algorithm::MLD + : EngineConfig::Algorithm::CH; + config.use_shared_memory = false; + + // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) + OSRM osrm{config}; + + auto run_benchmark = [&](const std::vector &coordinates) + { + RouteParameters params; + params.overview = RouteParameters::OverviewType::Full; + params.steps = true; + params.coordinates = coordinates; + + TIMER_START(routes); + auto NUM = 1000; + for (int i = 0; i < NUM; ++i) + { + engine::api::ResultT result = json::Object(); + const auto rc = osrm.Route(params, result); + auto &json_result = result.get(); + if (rc != Status::Ok || json_result.values.find("routes") == json_result.values.end()) + { + throw std::runtime_error{"Couldn't route"}; + } + } + TIMER_STOP(routes); + std::cout << NUM << " routes with " << coordinates.size() << " coordinates: " << std::endl; + std::cout << TIMER_MSEC(routes) << "ms" << std::endl; + std::cout << TIMER_MSEC(routes) / NUM << "ms/req" << std::endl; + }; + + std::vector> routes = { + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}}; + + for (const auto &route : routes) + { + run_benchmark(route); + } + + return EXIT_SUCCESS; +} +catch (const std::exception &e) +{ + std::cerr << "Error: " << e.what() << std::endl; + return EXIT_FAILURE; +} From 08a51e223f3eebb8e951ac559bbe83675be307b7 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 21 May 2024 22:17:09 +0200 Subject: [PATCH 2/7] Add benchmark for route --- src/benchmarks/route.cpp | 41 +++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp index ddcc21b2d81..add1aeabe4e 100644 --- a/src/benchmarks/route.cpp +++ b/src/benchmarks/route.cpp @@ -42,12 +42,23 @@ try // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) OSRM osrm{config}; - auto run_benchmark = [&](const std::vector &coordinates) + struct Benchmark + { + std::string name; + std::vector coordinates; + std::optional alternatives = std::nullopt; + }; + + auto run_benchmark = [&](const Benchmark &benchmark) { RouteParameters params; params.overview = RouteParameters::OverviewType::Full; params.steps = true; - params.coordinates = coordinates; + params.coordinates = benchmark.coordinates; + if (benchmark.alternatives) + { + params.alternatives = *benchmark.alternatives; + } TIMER_START(routes); auto NUM = 1000; @@ -62,21 +73,29 @@ try } } TIMER_STOP(routes); - std::cout << NUM << " routes with " << coordinates.size() << " coordinates: " << std::endl; + std::cout << benchmark.name << std::endl; std::cout << TIMER_MSEC(routes) << "ms" << std::endl; std::cout << TIMER_MSEC(routes) / NUM << "ms/req" << std::endl; }; - std::vector> routes = { - {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, - {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, - {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, - {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}}; + std::vector benchmarks = { + {"1000 routes, 3 coordinates, no alternatives", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + std::nullopt}, + {"1000 routes, 2 coordinates, no alternatives", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + std::nullopt}, + {"1000 routes, 2 coordinates, 3 alternatives", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + 3}}; - for (const auto &route : routes) + for (const auto &benchmark : benchmarks) { - run_benchmark(route); + run_benchmark(benchmark); } return EXIT_SUCCESS; From be08eed877c7ceb4c7f90765068eb0cb5f5921b2 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 21 May 2024 22:37:29 +0200 Subject: [PATCH 3/7] Add benchmark for route --- scripts/ci/run_benchmarks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/run_benchmarks.sh b/scripts/ci/run_benchmarks.sh index f81b29e6f79..493e3e5c556 100755 --- a/scripts/ci/run_benchmarks.sh +++ b/scripts/ci/run_benchmarks.sh @@ -13,8 +13,8 @@ function run_benchmarks_for_folder { ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench" ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench" - ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/route.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" - ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/route.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/route.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" || true # TODO: remove `true` when this benchmark will be merged to master + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/route.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" || true # TODO: remove `true` when this benchmark will be merged to master ./$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench" ./$BENCHMARKS_FOLDER/json-render-bench "./$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench" ./$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench" From afe4e2a110459f8a926e8af5c906db3a948d2f48 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 21 May 2024 22:42:00 +0200 Subject: [PATCH 4/7] Add benchmark for route --- src/benchmarks/route.cpp | 41 ++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp index add1aeabe4e..7b8827c5e59 100644 --- a/src/benchmarks/route.cpp +++ b/src/benchmarks/route.cpp @@ -46,14 +46,16 @@ try { std::string name; std::vector coordinates; + RouteParameters::OverviewType overview; + bool steps = false; std::optional alternatives = std::nullopt; }; auto run_benchmark = [&](const Benchmark &benchmark) { RouteParameters params; - params.overview = RouteParameters::OverviewType::Full; - params.steps = true; + params.overview = benchmark.overview; + params.steps = benchmark.steps; params.coordinates = benchmark.coordinates; if (benchmark.alternatives) { @@ -79,19 +81,46 @@ try }; std::vector benchmarks = { - {"1000 routes, 3 coordinates, no alternatives", + {"1000 routes, 3 coordinates, no alternatives, overview=full, steps=true", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::Full, + true, std::nullopt}, - {"1000 routes, 2 coordinates, no alternatives", + {"1000 routes, 2 coordinates, no alternatives, overview=full, steps=true", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::Full, + true, std::nullopt}, - {"1000 routes, 2 coordinates, 3 alternatives", + {"1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - 3}}; + RouteParameters::OverviewType::Full, + true, + 3}, + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt}, + {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt}, + {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + 3} + + }; for (const auto &benchmark : benchmarks) { From e22e442dd34efdb4b9e41845ad9bd621a3e09589 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 21 May 2024 22:44:42 +0200 Subject: [PATCH 5/7] Add benchmark for route --- src/benchmarks/route.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp index 7b8827c5e59..26f18ab13e0 100644 --- a/src/benchmarks/route.cpp +++ b/src/benchmarks/route.cpp @@ -85,42 +85,42 @@ try {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - RouteParameters::OverviewType::Full, - true, + RouteParameters::OverviewType::Full, + true, std::nullopt}, {"1000 routes, 2 coordinates, no alternatives, overview=full, steps=true", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - RouteParameters::OverviewType::Full, - true, + RouteParameters::OverviewType::Full, + true, std::nullopt}, {"1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - RouteParameters::OverviewType::Full, - true, + RouteParameters::OverviewType::Full, + true, 3}, - {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false", + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - RouteParameters::OverviewType::False, - false, + RouteParameters::OverviewType::False, + false, std::nullopt}, {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - RouteParameters::OverviewType::False, - false, + RouteParameters::OverviewType::False, + false, std::nullopt}, {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false", {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, - RouteParameters::OverviewType::False, - false, + RouteParameters::OverviewType::False, + false, 3} - - }; + + }; for (const auto &benchmark : benchmarks) { From a6e268b445f84a1916a54ee60b3d1b66254c35a1 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Wed, 22 May 2024 16:27:19 +0200 Subject: [PATCH 6/7] Add benchmark for route --- src/benchmarks/route.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp index 26f18ab13e0..ea95d06fbff 100644 --- a/src/benchmarks/route.cpp +++ b/src/benchmarks/route.cpp @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -49,6 +50,7 @@ try RouteParameters::OverviewType overview; bool steps = false; std::optional alternatives = std::nullopt; + std::optional radius = std::nullopt; }; auto run_benchmark = [&](const Benchmark &benchmark) @@ -62,6 +64,12 @@ try params.alternatives = *benchmark.alternatives; } + if (benchmark.radius) + { + params.radiuses = std::vector>( + params.coordinates.size(), boost::make_optional(*benchmark.radius)); + } + TIMER_START(routes); auto NUM = 1000; for (int i = 0; i < NUM; ++i) @@ -118,7 +126,29 @@ try {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, RouteParameters::OverviewType::False, false, - 3} + 3}, + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt, + 750}, + {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + std::nullopt, + 750}, + {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + RouteParameters::OverviewType::False, + false, + 3, + 750} }; From 632594e2ae12b2757516f55fb43cf7fa66150aa5 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Wed, 22 May 2024 16:28:14 +0200 Subject: [PATCH 7/7] Add benchmark for route --- scripts/ci/run_benchmarks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/run_benchmarks.sh b/scripts/ci/run_benchmarks.sh index 493e3e5c556..6aea4e08924 100755 --- a/scripts/ci/run_benchmarks.sh +++ b/scripts/ci/run_benchmarks.sh @@ -13,8 +13,8 @@ function run_benchmarks_for_folder { ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench" ./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench" - ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/route.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" || true # TODO: remove `true` when this benchmark will be merged to master - ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/route.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" || true # TODO: remove `true` when this benchmark will be merged to master + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" || true # TODO: remove `true` when this benchmark will be merged to master + ./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" || true # TODO: remove `true` when this benchmark will be merged to master ./$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench" ./$BENCHMARKS_FOLDER/json-render-bench "./$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench" ./$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"