router: working local OSRM backend + per-backend bench goldens
- fix encoded-polyline decoder (zigzag: (n>>1) ^ -(n&1)) — caught by the OSRM integration tests (Boston clearance 5681km -> 38km) - OSRM client: routes[] JSON shape, overview=full for geometry, polyline+geojson support - local OSRM 26.4.1 built from source (no sudo): deps.sh (bzip2, lua 5.2 with readline stub, oneTBB, boost 1.84 via b2 + hand-rolled CMake config files, osmium-tool), setup-osrm.sh (merge PBFs -> extract -> partition -> customize -> serve :5000); v26 flag fixes - bench: tasks.osrm.json goldens; both backends 26/26 PASS and agree on all 5 optimized orders (Ladd->Cascade etc.) - README: profile deltas (Valhalla 332min vs OSRM 410min, same route shape), per-backend goldens, verified self-host status
This commit is contained in:
Executable
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build the runtime dependencies OSRM needs, from source, no sudo, no
|
||||
# conan: bzip2, lua 5.2 (static), oneTBB, boost (b2, with hand-rolled
|
||||
# CMake config files — boost release tarballs ship no CMake support).
|
||||
#
|
||||
# Artifacts: $W (default /tmp/osm-build), installed into $W/prefix.
|
||||
# Idempotent: each dep is skipped when its .done-<name> marker exists.
|
||||
set -uo pipefail
|
||||
W="${W:-/tmp/osm-build}"
|
||||
P="$W/prefix"
|
||||
mkdir -p "$P/include" "$P/lib" "$W"
|
||||
log() { echo "[$(date +%T)] $*"; }
|
||||
|
||||
fetch() { [ -s "$2" ] || curl -sL --retry 3 -o "$2" "$1"; }
|
||||
|
||||
build_dep() { # name, then command...
|
||||
local name=$1; shift
|
||||
[ -f "$W/.done-$name" ] && { log "$name: already done"; return; }
|
||||
log "$name: building"
|
||||
if "$@" > "$W/$name.log" 2>&1; then
|
||||
touch "$W/.done-$name"
|
||||
else
|
||||
log "$name: FAILED (see $W/$name.log)"; exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# --- sources ---
|
||||
fetch "https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz" "$W/bzip2.tgz"
|
||||
[ -d "$W/bzip2-1.0.8" ] || tar -C "$W" -xzf "$W/bzip2.tgz"
|
||||
fetch "https://www.lua.org/ftp/lua-5.2.4.tar.gz" "$W/lua.tgz"
|
||||
[ -d "$W/lua-5.2.4" ] || tar -C "$W" -xzf "$W/lua.tgz"
|
||||
fetch "https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.13.0.tar.gz" "$W/tbb.tgz"
|
||||
[ -d "$W/oneTBB-2021.13.0" ] || tar -C "$W" -xzf "$W/tbb.tgz"
|
||||
fetch "https://archives.boost.io/release/1.84.0/source/boost_1_84_0.tar.gz" "$W/boost.tgz"
|
||||
[ -d "$W/boost_1_84_0" ] || tar -C "$W" -xzf "$W/boost.tgz"
|
||||
|
||||
# --- bzip2 ---
|
||||
build_dep bzip2 bash -c "
|
||||
cd $W/bzip2-1.0.8 && make -s -j16 CFLAGS='-O2 -fPIC'
|
||||
cp bzlib.h $P/include/ && cp libbz2.a $P/lib/"
|
||||
|
||||
# --- lua 5.2 (library only; the interactive REPL needs readline dev
|
||||
# headers, which we stub — we only link liblua.a into osrm-extract) ---
|
||||
build_dep lua bash -c "
|
||||
mkdir -p $W/local/include/readline $W/local/lib
|
||||
cat > $W/local/include/readline/readline.h <<'HDR'
|
||||
#ifndef READLINE_STUB_H
|
||||
#define READLINE_STUB_H
|
||||
char *readline(const char *prompt);
|
||||
void add_history(const char *line);
|
||||
#endif
|
||||
HDR
|
||||
cat > $W/local/include/readline/history.h <<'HDR'
|
||||
#ifndef HISTORY_STUB_H
|
||||
#define HISTORY_STUB_H
|
||||
void using_history(void);
|
||||
void clear_history(void);
|
||||
#endif
|
||||
HDR
|
||||
ln -sf /usr/lib/x86_64-linux-gnu/libreadline.so.8 $W/local/lib/libreadline.so
|
||||
cd $W/lua-5.2.4/src && make -s clean >/dev/null 2>&1
|
||||
make -s -j16 linux MYCFLAGS='-I$W/local/include' MYLDFLAGS='-L$W/local/lib'
|
||||
cp lua.h luaconf.h lualib.h lauxlib.h lua.hpp $P/include/
|
||||
cp liblua.a $P/lib/"
|
||||
|
||||
# --- nlohmann/json (single header; needed by osmium-tool) ---
|
||||
if [ ! -f "$P/include/nlohmann/json.hpp" ]; then
|
||||
log "nlohmann-json: fetching single header"
|
||||
mkdir -p "$P/include/nlohmann"
|
||||
curl -sL -o "$P/include/nlohmann/json.hpp" \
|
||||
https://github.com/nlohmann/json/releases/download/v3.11.3/json.hpp
|
||||
fi
|
||||
|
||||
# --- oneTBB (CMake, installs TBBConfig.cmake) ---
|
||||
build_dep tbb bash -c "
|
||||
cmake -S $W/oneTBB-2021.13.0 -B $W/tbb-build -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=$P -DTBB_TEST=OFF -DTBB_STRICT=OFF
|
||||
cmake --build $W/tbb-build -j16
|
||||
cmake --install $W/tbb-build"
|
||||
|
||||
# --- boost: b2 for the libs, then headers + CMake config files ---
|
||||
build_dep boost bash -c "
|
||||
cd $W/boost_1_84_0
|
||||
[ -x ./b2 ] || ./bootstrap.sh
|
||||
./b2 -j16 --with-date_time --with-iostreams --with-program_options \
|
||||
--with-thread --with-test --with-regex \
|
||||
--layout=versioned link=static cxxstd=17
|
||||
rm -rf $P/include/boost && cp -r $W/boost_1_84_0/boost $P/include/boost
|
||||
cp -a $W/boost_1_84_0/stage/lib/libboost_*.a $P/lib/
|
||||
W=$W bash $(dirname "$0")/install-boost-cmake.sh"
|
||||
|
||||
# --- osmium-tool (PBF merging; uses OSRM's vendored libosmium/protozero) ---
|
||||
build_dep osmium bash -c "
|
||||
if [ ! -d $W/osrm-backend-26.4.1 ]; then
|
||||
fetch "https://github.com/Project-OSRM/osrm-backend/archive/refs/tags/v26.4.1.tar.gz" $W/osrm.tar.gz
|
||||
tar -C $W -xzf $W/osrm.tar.gz
|
||||
fi
|
||||
if [ ! -d $W/osmium-tool-1.19.0 ]; then
|
||||
fetch "https://github.com/osmcode/osmium-tool/archive/refs/tags/v1.19.0.tar.gz" $W/osmium.tgz
|
||||
tar -C $W -xzf $W/osmium.tgz
|
||||
fi
|
||||
rm -rf $W/osmium-build
|
||||
cmake -S $W/osmium-tool-1.19.0 -B $W/osmium-build -DCMAKE_BUILD_TYPE=Release \
|
||||
-DOSMIUM_BUILD_PROGRAMS=ON -DOSMIUM_BUILD_TESTS=OFF \
|
||||
-DCMAKE_PREFIX_PATH=$P \
|
||||
-DOSMIUM_INCLUDE_DIR=$W/osrm-backend-26.4.1/third_party/libosmium/include \
|
||||
-DPROTOZERO_INCLUDE_DIR=$W/osrm-backend-26.4.1/third_party/protozero/include
|
||||
cmake --build $W/osmium-build --target osmium -j16"
|
||||
|
||||
log "ALL DEPS DONE"
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate the Boost CMake config files OSRM's find_package(Boost CONFIG)
|
||||
# needs, pointing at a b2-built boost (headers in $P/include/boost,
|
||||
# static libs in $P/lib). Boost release tarballs ship no CMake support,
|
||||
# so we roll minimal configs: one per component + version + main.
|
||||
#
|
||||
# W=/tmp/osm-build bash install-boost-cmake.sh
|
||||
set -euo pipefail
|
||||
W="${W:-/tmp/osm-build}"
|
||||
P="$W/prefix"
|
||||
CM="$P/lib/cmake/Boost-1.84.0"
|
||||
mkdir -p "$CM"
|
||||
|
||||
cat > "$CM/BoostConfigVersion.cmake" <<'EOF'
|
||||
set(PACKAGE_VERSION "1.84.0")
|
||||
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
if(PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_EXACT TRUE)
|
||||
endif()
|
||||
endif()
|
||||
EOF
|
||||
|
||||
# component: cmlist-name b2-lib-name
|
||||
for pair in "date_time date_time" "iostreams iostreams" \
|
||||
"program_options program_options" "thread thread" \
|
||||
"unit_test_framework test" "regex regex" "zlib zlib"; do
|
||||
comp=${pair% *}
|
||||
b2name=${pair#* }
|
||||
cap=$(echo "$comp" | tr 'a-z' 'A-Z')
|
||||
if [ "$comp" = "zlib" ]; then
|
||||
# OSRM lists Boost_ZLIB_LIBRARY in BOOST_ENGINE_LIBRARIES; use system zlib
|
||||
cat > "$CM/Boost${cap}Config.cmake" <<EOF
|
||||
set(Boost_${cap}_LIBRARY /usr/lib/x86_64-linux-gnu/libz.so)
|
||||
set(Boost_${cap}_FOUND TRUE)
|
||||
set(Boost_${comp}_FOUND TRUE)
|
||||
EOF
|
||||
continue
|
||||
fi
|
||||
lib=$(ls "$P"/lib/libboost_${b2name}*.a 2>/dev/null | head -1 || true)
|
||||
if [ -z "$lib" ]; then
|
||||
echo "FATAL: no static lib for $comp (b2name $b2name)" >&2
|
||||
exit 1
|
||||
fi
|
||||
cat > "$CM/Boost${cap}Config.cmake" <<EOF
|
||||
set(Boost_${cap}_LIBRARY "$lib")
|
||||
set(Boost_${cap}_FOUND TRUE)
|
||||
set(Boost_${comp}_FOUND TRUE)
|
||||
EOF
|
||||
done
|
||||
|
||||
cat > "$CM/BoostConfig.cmake" <<EOF
|
||||
if(Boost_FOUND)
|
||||
return()
|
||||
endif()
|
||||
set(Boost_VERSION 108400)
|
||||
set(Boost_VERSION_STRING "1.84.0")
|
||||
set(Boost_LIB_VERSION "1_84")
|
||||
get_filename_component(Boost_INCLUDE_DIRS "$P/include" ABSOLUTE)
|
||||
set(Boost_INCLUDE_DIR "\${Boost_INCLUDE_DIRS}")
|
||||
set(Boost_LIBRARIES "")
|
||||
foreach(_comp \${Boost_FIND_COMPONENTS})
|
||||
string(TOUPPER "\${_comp}" _uc)
|
||||
include("\${CMAKE_CURRENT_LIST_DIR}/Boost\${_uc}Config.cmake")
|
||||
list(APPEND Boost_LIBRARIES \${Boost_\${_uc}_LIBRARY})
|
||||
endforeach()
|
||||
set(Boost_FOUND TRUE)
|
||||
EOF
|
||||
|
||||
ls "$CM"
|
||||
echo "boost cmake config installed in $CM"
|
||||
Regular → Executable
+65
-43
@@ -1,68 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
# Self-host the OSRM router over the NH+MA+CT+NY extract.
|
||||
# Prereqs: cmake, g++, make, >=12GB RAM for extract, >=10GB disk.
|
||||
# Build + run the self-hosted OSRM router over the NH+MA+CT+NY extract.
|
||||
#
|
||||
# The PBFs are pre-downloaded in ../osm/ (us-new-hampshire, us-connecticut,
|
||||
# us-massachusetts, us-new-york .osm.pbf, from the geofabrik mirror on
|
||||
# HuggingFace: NoeFlandre/osm-geofabrik-raw-pbf-extracts).
|
||||
# Steps: deps.sh (bzip2/lua/tbb/boost/osmium, no sudo) → build OSRM 26.4.1
|
||||
# → merge the 4 state PBFs → extract → partition → customize → serve :5000.
|
||||
#
|
||||
# Artifacts go to ../osm/build/. Router ends up on http://localhost:5000.
|
||||
# Usage: scripts/setup-osrm.sh # everything, then serve
|
||||
# scripts/setup-osrm.sh --no-serve # build + extract, don't serve
|
||||
#
|
||||
# NOTE: /tmp is wiped on reboot. For a persistent install set W to a
|
||||
# durable dir (and the extract's ~8 GB lives under $W/data).
|
||||
#
|
||||
# PBFs are pre-downloaded in ../../osm/ (see router/README.md); ~1.1 GB.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
OSM_DIR="$(pwd)/osm"
|
||||
BUILD_DIR="$OSM_DIR/build"
|
||||
DATA_DIR="$BUILD_DIR/data"
|
||||
OSRM_BIN="$BUILD_DIR/osrm-backend-26.4.1/build"
|
||||
W="${W:-/tmp/osm-build}"
|
||||
P="$W/prefix"
|
||||
OSM_DIR="$(cd ../.. && pwd)/osm"
|
||||
DATA_DIR="${DATA_DIR:-$W/data}"
|
||||
OSRM_SRC="$W/osrm-backend-26.4.1"
|
||||
OSRM_BIN="$W/build"
|
||||
SERVE=1
|
||||
[ "${1:-}" = "--no-serve" ] && SERVE=0
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
step() { echo; echo "=== $1"; }
|
||||
|
||||
step "1/5 OSRM binaries"
|
||||
step "1/6 dependencies (bzip2, lua, tbb, boost, osmium)"
|
||||
bash deps.sh
|
||||
|
||||
step "2/6 OSRM 26.4.1"
|
||||
if [ ! -d "$OSRM_SRC" ]; then
|
||||
curl -sL -o "$W/osrm.tar.gz" https://github.com/Project-OSRM/osrm-backend/archive/refs/tags/v26.4.1.tar.gz
|
||||
tar -C "$W" -xzf "$W/osrm.tar.gz"
|
||||
fi
|
||||
if [ ! -x "$OSRM_BIN/osrm-extract" ]; then
|
||||
if [ ! -d "$BUILD_DIR/osrm-backend-26.4.1" ]; then
|
||||
curl -sL -o "$BUILD_DIR/osrm.tar.gz" https://github.com/Project-OSRM/osrm-backend/archive/refs/tags/v26.4.1.tar.gz
|
||||
tar -C "$BUILD_DIR" -xzf "$BUILD_DIR/osrm.tar.gz"
|
||||
fi
|
||||
# Boost is header-usage only for OSRM; point BOOST_ROOT at a source tree.
|
||||
if [ ! -d "$BUILD_DIR/boost_1_84_0" ]; then
|
||||
curl -sL -o "$BUILD_DIR/boost.tgz" https://archives.boost.io/release/1.84.0/source/boost_1_84_0.tar.gz
|
||||
tar -C "$BUILD_DIR" -xzf "$BUILD_DIR/boost.tgz"
|
||||
fi
|
||||
cmake -S "$BUILD_DIR/osrm-backend-26.4.1" -B "$OSRM_BIN" \
|
||||
-DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=OFF -DWITH_EXAMPLES=OFF \
|
||||
-DBOOST_ROOT="$BUILD_DIR/boost_1_84_0"
|
||||
# -Wno-maybe-uninitialized: GCC 12 + boost 1.84 spirit X3 false positive
|
||||
# under OSRM's -Werror.
|
||||
cmake -S "$OSRM_SRC" -B "$OSRM_BIN" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH="$P" \
|
||||
-DCMAKE_CXX_FLAGS="-Wno-maybe-uninitialized"
|
||||
cmake --build "$OSRM_BIN" -j"$(nproc)"
|
||||
fi
|
||||
ls -la "$OSRM_BIN"/osrm-extract "$OSRM_BIN"/osrm-routed
|
||||
|
||||
step "2/5 OSM PBFs"
|
||||
for f in us-new-hampshire us-connecticut us-massachusetts us-new-york; do
|
||||
if [ ! -s "$OSM_DIR/$f.osm.pbf" ]; then
|
||||
curl -sL -o "$OSM_DIR/$f.osm.pbf" \
|
||||
step "3/6 OSM PBFs (NH+MA+CT+NY)"
|
||||
if [ ! -s "$OSM_DIR/us-new-hampshire.osm.pbf" ]; then
|
||||
echo "PBFs missing; downloading from the geofabrik HF mirror (~1.1 GB)..."
|
||||
for f in us-new-hampshire us-connecticut us-massachusetts us-new-york; do
|
||||
[ -s "$OSM_DIR/$f.osm.pbf" ] || curl -sL -o "$OSM_DIR/$f.osm.pbf" \
|
||||
"https://huggingface.co/datasets/NoeFlandre/osm-geofabrik-raw-pbf-extracts/resolve/main/$f-latest.osm.pbf"
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
ls -la "$OSM_DIR"/us-*.osm.pbf
|
||||
|
||||
step "3/5 extract (needs ~12GB RAM; this is the slow part)"
|
||||
touch "$DATA_DIR/timestamp"
|
||||
if [ ! -s "$DATA_DIR/northeast.osrm" ] || [ ! -s "$DATA_DIR/northeast.osrm.tile" ]; then
|
||||
"$OSRM_BIN/osrm-extract" \
|
||||
step "4/6 merge PBFs (osrm-extract takes one input file)"
|
||||
MERGED="$DATA_DIR/northeast.osm.pbf"
|
||||
if [ ! -s "$MERGED" ]; then
|
||||
"$W/osmium-build/osmium" merge \
|
||||
"$OSM_DIR/us-new-hampshire.osm.pbf" \
|
||||
"$OSM_DIR/us-connecticut.osm.pbf" \
|
||||
"$OSM_DIR/us-massachusetts.osm.pbf" \
|
||||
"$OSM_DIR/us-new-york.osm.pbf" \
|
||||
--profile-file "$OSRM_BIN/../profiles/driving.lua" \
|
||||
--timestamp-file "$DATA_DIR/timestamp" \
|
||||
--output-location "$DATA_DIR/northeast" \
|
||||
--ignore-waterway --ignore-tunnels 2>&1 | tail -5
|
||||
-o "$MERGED"
|
||||
fi
|
||||
ls -la "$MERGED"
|
||||
|
||||
step "5/6 extract + partition + customize (extract needs ~9-12GB RAM)"
|
||||
if [ ! -s "$DATA_DIR/northeast.osrm.ebg" ]; then
|
||||
"$OSRM_BIN/osrm-extract" "$MERGED" \
|
||||
-p "$OSRM_SRC/profiles/car.lua" \
|
||||
-o "$DATA_DIR/northeast"
|
||||
fi
|
||||
if [ ! -s "$DATA_DIR/northeast.osrm.partition" ]; then
|
||||
"$OSRM_BIN/osrm-partition" "$DATA_DIR/northeast"
|
||||
fi
|
||||
if [ ! -s "$DATA_DIR/northeast.osrm.tld" ]; then
|
||||
# v26 bakes the profile into the extract; customize takes no -p.
|
||||
"$OSRM_BIN/osrm-customize" "$DATA_DIR/northeast"
|
||||
fi
|
||||
|
||||
step "4/5 partition + customize"
|
||||
"$OSRM_BIN/osrm-partition" --input-location "$DATA_DIR/northeast"
|
||||
"$OSRM_BIN/osrm-customize" --input-location "$DATA_DIR/northeast" --profile-file "$OSRM_BIN/../profiles/driving.lua"
|
||||
if [ "$SERVE" = 0 ]; then
|
||||
echo "done (not serving; start with: $OSRM_BIN/osrm-routed --algorithm mld --port 5000 $DATA_DIR/northeast.osrm)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
step "5/5 serve"
|
||||
echo "Starting osrm-routed on :5000 (Ctrl-C to stop)"
|
||||
step "6/6 serve on :5000 (Ctrl-C to stop)"
|
||||
exec "$OSRM_BIN/osrm-routed" --algorithm mld --port 5000 "$DATA_DIR/northeast.osrm"
|
||||
|
||||
Reference in New Issue
Block a user