From ec98745bd481a18b1eab606794cfe4d3324bb15d Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 7 Jun 2024 21:07:53 +0200 Subject: [PATCH] wip --- .github/workflows/osrm-backend.yml | 8 +- scripts/ci/run_benchmarks.sh | 4 +- src/benchmarks/CMakeLists.txt | 15 +++ src/benchmarks/route.cpp | 167 +++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+), 6 deletions(-) create mode 100644 src/benchmarks/route.cpp diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 653226fae..96828d790 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -660,10 +660,10 @@ jobs: sudo apt-get update -y && sudo apt-get install ccache - name: Prepare data run: | - # if [ ! -f "~/data.osm.pbf" ]; then - # wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf -O ~/data.osm.pbf - # fi - wget http://download.geofabrik.de/europe/germany-latest.osm.pbf -O ~/data.osm.pbf --quiet + if [ ! -f "~/data.osm.pbf" ]; then + wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf -O ~/data.osm.pbf + fi + # wget http://download.geofabrik.de/europe/germany-latest.osm.pbf -O ~/data.osm.pbf --quiet gunzip -c ./pr/test/data/berlin_gps_traces.csv.gz > ~/gps_traces.csv - name: Prepare environment run: | diff --git a/scripts/ci/run_benchmarks.sh b/scripts/ci/run_benchmarks.sh index ab9e6d3fa..c0b033745 100755 --- a/scripts/ci/run_benchmarks.sh +++ b/scripts/ci/run_benchmarks.sh @@ -27,8 +27,8 @@ function run_benchmarks_for_folder { $BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm for BENCH in nearest table trip route match; do - ./$BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" mld ~/gps_traces.csv ${BENCH} > "$RESULTS_FOLDER/${BENCH}_mld.bench" || true - ./$BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" ch ~/gps_traces.csv ${BENCH} > "$RESULTS_FOLDER/${BENCH}_ch.bench" || true + ./$BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" mld ~/gps_traces.csv ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_mld.bench" || true + ./$BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" ch ~/gps_traces.csv ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_ch.bench" || true done if [ -f "$FOLDER/scripts/ci/locustfile.py" ]; then diff --git a/src/benchmarks/CMakeLists.txt b/src/benchmarks/CMakeLists.txt index 09ba2ded4..d2478ab4a 100644 --- a/src/benchmarks/CMakeLists.txt +++ b/src/benchmarks/CMakeLists.txt @@ -18,6 +18,7 @@ target_link_libraries(rtree-bench ${TBB_LIBRARIES} ${MAYBE_SHAPEFILE}) + add_executable(match-bench EXCLUDE_FROM_ALL ${MatchBenchmarkSources} @@ -30,6 +31,19 @@ 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(bench EXCLUDE_FROM_ALL bench.cpp @@ -84,6 +98,7 @@ add_custom_target(benchmarks rtree-bench packedvector-bench match-bench + route-bench bench json-render-bench alias-bench) diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp new file mode 100644 index 000000000..c4242956f --- /dev/null +++ b/src/benchmarks/route.cpp @@ -0,0 +1,167 @@ +#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 +#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}; + + struct Benchmark + { + std::string name; + std::vector coordinates; + RouteParameters::OverviewType overview; + bool steps = false; + std::optional alternatives = std::nullopt; + std::optional radius = std::nullopt; + }; + + auto run_benchmark = [&](const Benchmark &benchmark) + { + RouteParameters params; + params.overview = benchmark.overview; + params.steps = benchmark.steps; + params.coordinates = benchmark.coordinates; + if (benchmark.alternatives) + { + 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) + { + engine::api::ResultT result = json::Object(); + const auto rc = osrm.Route(params, result); + auto &json_result = std::get(result); + 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 << benchmark.name << std::endl; + std::cout << TIMER_MSEC(routes) << "ms" << std::endl; + std::cout << TIMER_MSEC(routes) / NUM << "ms/req" << std::endl; + }; + + std::vector benchmarks = { + {"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, 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, overview=full, steps=true", + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, + 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}, + {"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} + + }; + + for (const auto &benchmark : benchmarks) + { + run_benchmark(benchmark); + } + + return EXIT_SUCCESS; +} +catch (const std::exception &e) +{ + std::cerr << "Error: " << e.what() << std::endl; + return EXIT_FAILURE; +} + \ No newline at end of file