Compare commits

...

7 Commits

Author SHA1 Message Date
Siarhei Fedartsou eb50311d5e Use custom d-ary heap implementation 2024-08-22 22:16:23 +02:00
Siarhei Fedartsou 203314b1aa Remove unused middle_nodes_table vector (#7012) 2024-08-03 22:32:37 +02:00
Siarhei Fedartsou e5e25a1aca Configure self-hosted runner for benchmarks job (#6975) 2024-07-26 21:19:47 +02:00
Siarhei Fedartsou 84f12c7c6d Add NodeJs bindings benchmarks (#7004) 2024-07-26 19:36:43 +02:00
Siarhei Fedartsou 7802f86bd6 Measure peak RAM in benchmarks (#6995) 2024-07-25 21:27:37 +02:00
Siarhei Fedartsou 43afec3b39 Move flatbuffers non-generated files back to include/engine/api/flatbuffers/ (#6996) 2024-07-13 13:43:56 +02:00
Dennis Luxen 2da7ca5338 Route pedestrians over highway=platform (#6993) 2024-07-12 20:12:19 +02:00
20 changed files with 682 additions and 87 deletions
+48 -46
View File
@@ -653,7 +653,7 @@ jobs:
benchmarks:
if: github.event_name == 'pull_request'
needs: [format-taginfo-docs]
runs-on: ubuntu-24.04
runs-on: self-hosted
env:
CCOMPILER: clang-16
CXXCOMPILER: clang++-16
@@ -664,37 +664,17 @@ jobs:
GITHUB_REPOSITORY: ${{ github.repository }}
RUN_BIG_BENCHMARK: ${{ contains(github.event.pull_request.labels.*.name, 'Performance') }}
steps:
- name: Enable data.osm.pbf cache
if: ${{ ! env.RUN_BIG_BENCHMARK }}
uses: actions/cache@v4
with:
path: ~/data.osm.pbf
key: v1-data-osm-pbf
restore-keys: |
v1-data-osm-pbf
- name: Enable compiler cache
uses: actions/cache@v4
with:
path: ~/.ccache
key: v1-ccache-benchmarks-${{ github.sha }}
restore-keys: |
v1-ccache-benchmarks-
- name: Enable Conan cache
uses: actions/cache@v4
with:
path: ~/.conan
key: v1-conan-benchmarks-${{ github.sha }}
restore-keys: |
v1-conan-benchmarks-
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
path: pr
- name: Install dependencies
run: |
python3 -m pip install "conan<2.0.0" "requests==2.31.0" "numpy==1.26.4" --break-system-packages
sudo apt-get update -y && sudo apt-get install ccache
- name: Activate virtualenv
run: |
python3 -m venv .venv
source .venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
pip install "conan<2.0.0" "requests==2.31.0" "numpy==1.26.4"
- name: Prepare data
run: |
if [ "$RUN_BIG_BENCHMARK" = "true" ]; then
@@ -722,50 +702,72 @@ jobs:
path: base
- name: Build Base Branch
run: |
cd base
npm ci --ignore-scripts
cd ..
mkdir base/build
cd base/build
cmake -DENABLE_CONAN=ON -DCMAKE_BUILD_TYPE=Release ..
cmake -DENABLE_CONAN=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_NODE_BINDINGS=ON ..
make -j$(nproc)
make -j$(nproc) benchmarks
cd ..
make -C test/data
- name: Build PR Branch
run: |
cd pr
npm ci --ignore-scripts
cd ..
mkdir -p pr/build
cd pr/build
cmake -DENABLE_CONAN=ON -DCMAKE_BUILD_TYPE=Release ..
cmake -DENABLE_CONAN=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_NODE_BINDINGS=ON ..
make -j$(nproc)
make -j$(nproc) benchmarks
cd ..
make -C test/data
# we run benchmarks in tmpfs to avoid impact of disk IO
- name: Create folder for tmpfs
run: mkdir -p /opt/benchmarks
run: |
# if by any chance it was mounted before(e.g. due to previous job failed), unmount it
sudo umount ~/benchmarks | true
rm -rf ~/benchmarks
mkdir -p ~/benchmarks
for i in {1..15}; do sudo cset shield --reset && break || echo "cset shield reset attempt $i failed"; sleep 1; done
# see https://llvm.org/docs/Benchmarking.html
- name: Run PR Benchmarks
run: |
sudo mount -t tmpfs -o size=4g none /opt/benchmarks
cp -rf pr/build /opt/benchmarks/build
mkdir -p /opt/benchmarks/test
cp -rf pr/test/data /opt/benchmarks/test/data
cp -rf pr/profiles /opt/benchmarks/profiles
sudo cset shield -c 2-3 -k on
sudo mount -t tmpfs -o size=4g none ~/benchmarks
cp -rf pr/build ~/benchmarks/build
cp -rf pr/lib ~/benchmarks/lib
mkdir -p ~/benchmarks/test
cp -rf pr/test/data ~/benchmarks/test/data
cp -rf pr/profiles ~/benchmarks/profiles
sudo cset shield --exec -- ./pr/scripts/ci/run_benchmarks.sh -f ~/benchmarks -r $(pwd)/pr_results -s $(pwd)/pr -b ~/benchmarks/build -o ~/data.osm.pbf -g ~/gps_traces.csv
sudo umount ~/benchmarks
for i in {1..15}; do sudo cset shield --reset && break || echo "cset shield reset attempt $i failed"; sleep 1; done
./pr/scripts/ci/run_benchmarks.sh -f /opt/benchmarks -r $(pwd)/pr_results -s $(pwd)/pr -b /opt/benchmarks/build -o ~/data.osm.pbf -g ~/gps_traces.csv
sudo umount /opt/benchmarks
- name: Run Base Benchmarks
run: |
sudo mount -t tmpfs -o size=4g none /opt/benchmarks
cp -rf base/build /opt/benchmarks/build
mkdir -p /opt/benchmarks/test
cp -rf base/test/data /opt/benchmarks/test/data
cp -rf base/profiles /opt/benchmarks/profiles
sudo cset shield -c 2-3 -k on
sudo mount -t tmpfs -o size=4g none ~/benchmarks
cp -rf base/build ~/benchmarks/build
cp -rf base/lib ~/benchmarks/lib
mkdir -p ~/benchmarks/test
cp -rf base/test/data ~/benchmarks/test/data
cp -rf base/profiles ~/benchmarks/profiles
# TODO: remove it when base branch will have this file at needed location
if [ ! -f /opt/benchmarks/test/data/portugal_to_korea.json ]; then
cp base/src/benchmarks/portugal_to_korea.json /opt/benchmarks/test/data/portugal_to_korea.json
if [ ! -f ~/benchmarks/test/data/portugal_to_korea.json ]; then
cp base/src/benchmarks/portugal_to_korea.json ~/benchmarks/test/data/portugal_to_korea.json
fi
# we intentionally use scripts from PR branch to be able to update them and see results in the same PR
./pr/scripts/ci/run_benchmarks.sh -f /opt/benchmarks -r $(pwd)/base_results -s $(pwd)/pr -b /opt/benchmarks/build -o ~/data.osm.pbf -g ~/gps_traces.csv
sudo umount /opt/benchmarks
sudo cset shield --exec -- ./pr/scripts/ci/run_benchmarks.sh -f ~/benchmarks -r $(pwd)/base_results -s $(pwd)/pr -b ~/benchmarks/build -o ~/data.osm.pbf -g ~/gps_traces.csv
sudo umount ~/benchmarks
for i in {1..15}; do sudo cset shield --reset && break || echo "cset shield reset attempt $i failed"; sleep 1; done
- name: Post Benchmark Results
run: |
python3 pr/scripts/ci/post_benchmark_results.py base_results pr_results
+1
View File
@@ -1,6 +1,7 @@
# Unreleased
- Changes from 5.27.1
- Features
- ADDED: Route pedestrians over highway=platform [#6993](https://github.com/Project-OSRM/osrm-backend/pull/6993)
- REMOVED: Remove all core-CH left-overs [#6920](https://github.com/Project-OSRM/osrm-backend/pull/6920)
- ADDED: Add support for a keepalive_timeout flag. [#6674](https://github.com/Project-OSRM/osrm-backend/pull/6674)
- ADDED: Add support for a default_radius flag. [#6575](https://github.com/Project-OSRM/osrm-backend/pull/6575)
+9 -1
View File
@@ -26,7 +26,15 @@ Feature: Foot - Access tags on ways
| motorway | no | | |
| motorway | no | yes | x |
| motorway | no | no | |
| platform | | | x |
| platform | | yes | x |
| platform | | no | |
| platform | yes | | x |
| platform | yes | yes | x |
| platform | yes | no | |
| platform | no | | |
| platform | no | yes | x |
| platform | no | no | |
Scenario: Foot - Overwriting implied acccess on ways
Then routability should be
+113
View File
@@ -0,0 +1,113 @@
#pragma once
#include <boost/assert.hpp>
#include <functional>
#include <limits>
#include <utility>
#include <vector>
namespace osrm::util
{
template <typename HeapData, int Arity, typename Comparator = std::less<HeapData>> class DAryHeap
{
public:
using HeapHandle = size_t;
static constexpr HeapHandle INVALID_HANDLE = std::numeric_limits<size_t>::max();
public:
const HeapData &top() const { return heap[0]; }
size_t size() const { return heap.size(); }
bool empty() const { return heap.empty(); }
const HeapData &operator[](HeapHandle handle) const { return heap[handle]; }
template <typename ReorderHandler>
void emplace(HeapData &&data, ReorderHandler &&reorderHandler)
{
heap.emplace_back(std::forward<HeapData>(data));
heapifyUp(heap.size() - 1, std::forward<ReorderHandler>(reorderHandler));
}
template <typename ReorderHandler>
void decrease(HeapHandle handle, HeapData &&data, ReorderHandler &&reorderHandler)
{
BOOST_ASSERT(handle < heap.size());
heap[handle] = std::forward<HeapData>(data);
heapifyUp(handle, std::forward<ReorderHandler>(reorderHandler));
}
void clear() { heap.clear(); }
template <typename ReorderHandler> void pop(ReorderHandler &&reorderHandler)
{
BOOST_ASSERT(!heap.empty());
heap[0] = std::move(heap.back());
heap.pop_back();
if (!heap.empty())
{
heapifyDown(0, std::forward<ReorderHandler>(reorderHandler));
}
}
private:
size_t parent(size_t index) { return (index - 1) / Arity; }
size_t kthChild(size_t index, size_t k) { return Arity * index + k + 1; }
template <typename ReorderHandler> void heapifyUp(size_t index, ReorderHandler &&reorderHandler)
{
HeapData temp = std::move(heap[index]);
while (index > 0 && comp(temp, heap[parent(index)]))
{
size_t parentIndex = parent(index);
heap[index] = std::move(heap[parentIndex]);
reorderHandler(heap[index], index);
index = parentIndex;
}
heap[index] = std::move(temp);
reorderHandler(heap[index], index);
}
template <typename ReorderHandler>
void heapifyDown(size_t index, ReorderHandler &&reorderHandler)
{
HeapData temp = std::move(heap[index]);
size_t child;
while (kthChild(index, 0) < heap.size())
{
child = minChild(index);
if (!comp(heap[child], temp))
{
break;
}
heap[index] = std::move(heap[child]);
reorderHandler(heap[index], index);
index = child;
}
heap[index] = std::move(temp);
reorderHandler(heap[index], index);
}
size_t minChild(size_t index)
{
size_t bestChild = kthChild(index, 0);
for (size_t k = 1; k < Arity; ++k)
{
size_t pos = kthChild(index, k);
if (pos < heap.size() && comp(heap[pos], heap[bestChild]))
{
bestChild = pos;
}
}
return bestChild;
}
private:
Comparator comp;
std::vector<HeapData> heap;
};
} // namespace osrm::util
+14 -4
View File
@@ -2,6 +2,7 @@
#define MEMINFO_HPP
#include "util/log.hpp"
#include <cstddef>
#ifndef _WIN32
#include <sys/resource.h>
@@ -10,22 +11,31 @@
namespace osrm::util
{
inline void DumpMemoryStats()
inline size_t PeakRAMUsedInBytes()
{
#ifndef _WIN32
rusage usage;
getrusage(RUSAGE_SELF, &usage);
#ifdef __linux__
// Under linux, ru.maxrss is in kb
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss * 1024;
return usage.ru_maxrss * 1024;
#else // __linux__
// Under BSD systems (OSX), it's in bytes
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss;
return usage.ru_maxrss;
#endif // __linux__
#else // _WIN32
return 0;
#endif // _WIN32
}
inline void DumpMemoryStats()
{
#ifndef _WIN32
util::Log() << "RAM: peak bytes used: " << PeakRAMUsedInBytes();
#else // _WIN32
util::Log() << "RAM: peak bytes used: <not implemented on Windows>";
#endif // _WIN32
}
} // namespace osrm::util
#endif
#endif
+49 -28
View File
@@ -4,8 +4,10 @@
#include <boost/assert.hpp>
#include <boost/heap/d_ary_heap.hpp>
#include "d_ary_heap.hpp"
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <map>
#include <optional>
@@ -133,20 +135,17 @@ class QueryHeap
Weight weight;
Key index;
bool operator>(const HeapData &other) const
bool operator<(const HeapData &other) const
{
if (weight == other.weight)
{
return index > other.index;
return index < other.index;
}
return weight > other.weight;
return weight < other.weight;
}
};
using HeapContainer = boost::heap::d_ary_heap<HeapData,
boost::heap::arity<4>,
boost::heap::mutable_<true>,
boost::heap::compare<std::greater<HeapData>>>;
using HeapHandle = typename HeapContainer::handle_type;
using HeapContainer = DAryHeap<HeapData, 4>;
using HeapHandle = typename HeapContainer::HeapHandle;
public:
using WeightType = Weight;
@@ -178,11 +177,31 @@ class QueryHeap
void Insert(NodeID node, Weight weight, const Data &data)
{
checkInvariants();
BOOST_ASSERT(node < std::numeric_limits<NodeID>::max());
const auto index = static_cast<Key>(inserted_nodes.size());
const auto handle = heap.emplace(HeapData{weight, index});
inserted_nodes.emplace_back(HeapNode{handle, node, weight, data});
inserted_nodes.emplace_back(HeapNode{heap.size(), node, weight, data});
heap.emplace(HeapData{weight, index},
[this](const auto &heapData, auto new_handle)
{ inserted_nodes[heapData.index].handle = new_handle; });
node_index[node] = index;
checkInvariants();
}
void checkInvariants()
{
#ifndef NDEBUG
for (size_t handle = 0; handle < heap.size(); ++handle)
{
auto &in_heap = heap[handle];
auto &inserted = inserted_nodes[in_heap.index];
BOOST_ASSERT(in_heap.weight == inserted.weight);
BOOST_ASSERT(inserted.handle == handle);
}
#endif // !NDEBUG
}
Data &GetData(NodeID node)
@@ -216,16 +235,7 @@ class QueryHeap
{
BOOST_ASSERT(WasInserted(node));
const Key index = node_index.peek_index(node);
// Use end iterator as a reliable "non-existent" handle.
// Default-constructed handles are singular and
// can only be checked-compared to another singular instance.
// Behaviour investigated at https://lists.boost.org/boost-users/2017/08/87787.php,
// eventually confirmation at https://stackoverflow.com/a/45622940/151641.
// Corrected in https://github.com/Project-OSRM/osrm-backend/pull/4396
auto const end_it = const_cast<HeapContainer &>(heap).end(); // non-const iterator
auto const none_handle = heap.s_handle_from_iterator(end_it); // from non-const iterator
return inserted_nodes[index].handle == none_handle;
return inserted_nodes[index].handle == HeapContainer::INVALID_HANDLE;
}
bool WasInserted(const NodeID node) const
@@ -276,26 +286,30 @@ class QueryHeap
{
BOOST_ASSERT(!heap.empty());
const Key removedIndex = heap.top().index;
heap.pop();
inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator(heap.end());
inserted_nodes[removedIndex].handle = HeapContainer::INVALID_HANDLE;
heap.pop([this](const auto &heapData, auto new_handle)
{ inserted_nodes[heapData.index].handle = new_handle; });
return inserted_nodes[removedIndex].node;
}
HeapNode &DeleteMinGetHeapNode()
{
BOOST_ASSERT(!heap.empty());
checkInvariants();
const Key removedIndex = heap.top().index;
heap.pop();
inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator(heap.end());
inserted_nodes[removedIndex].handle = HeapContainer::INVALID_HANDLE;
heap.pop([this](const auto &heapData, auto new_handle)
{ inserted_nodes[heapData.index].handle = new_handle; });
checkInvariants();
return inserted_nodes[removedIndex];
}
void DeleteAll()
{
auto const none_handle = heap.s_handle_from_iterator(heap.end());
std::for_each(inserted_nodes.begin(),
inserted_nodes.end(),
[&none_handle](auto &node) { node.handle = none_handle; });
[&](auto &node) { node.handle = HeapContainer::INVALID_HANDLE; });
heap.clear();
}
@@ -305,13 +319,19 @@ class QueryHeap
const auto index = node_index.peek_index(node);
auto &reference = inserted_nodes[index];
reference.weight = weight;
heap.increase(reference.handle, HeapData{weight, static_cast<Key>(index)});
heap.decrease(reference.handle,
HeapData{weight, static_cast<Key>(index)},
[this](const auto &heapData, auto new_handle)
{ inserted_nodes[heapData.index].handle = new_handle; });
}
void DecreaseKey(const HeapNode &heapNode)
{
BOOST_ASSERT(!WasRemoved(heapNode.node));
heap.increase(heapNode.handle, HeapData{heapNode.weight, (*heapNode.handle).index});
heap.decrease(heapNode.handle,
HeapData{heapNode.weight, heap[heapNode.handle].index},
[this](const auto &heapData, auto new_handle)
{ inserted_nodes[heapData.index].handle = new_handle; });
}
private:
@@ -319,6 +339,7 @@ class QueryHeap
HeapContainer heap;
IndexStorage node_index;
};
} // namespace osrm::util
#endif // OSRM_UTIL_QUERY_HEAP_HPP
+12 -1
View File
@@ -10,7 +10,8 @@
"hasInstallScript": true,
"license": "BSD-2-Clause",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11"
"@mapbox/node-pre-gyp": "^1.0.11",
"seedrandom": "^3.0.5"
},
"devDependencies": {
"@babel/cli": "^7.18.10",
@@ -14652,6 +14653,11 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"devOptional": true
},
"node_modules/seedrandom": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
},
"node_modules/semver": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
@@ -30296,6 +30302,11 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"devOptional": true
},
"seedrandom": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
},
"semver": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
+7 -4
View File
@@ -4,7 +4,8 @@
"private": false,
"description": "The Open Source Routing Machine is a high performance routing engine written in C++ designed to run on OpenStreetMap data.",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11"
"@mapbox/node-pre-gyp": "^1.0.11",
"seedrandom": "^3.0.5"
},
"browserify": {
"transform": [
@@ -57,6 +58,7 @@
"jsonpath": "^1.1.1",
"mkdirp": "^0.5.6",
"node-addon-api": "^5.0.0",
"node-cmake": "^2.5.1",
"node-timeout": "0.0.4",
"polyline": "^0.2.0",
"request": "^2.88.2",
@@ -64,12 +66,13 @@
"tape": "^4.16.0",
"turf": "^3.0.14",
"uglify-js": "^3.17.0",
"xmlbuilder": "^4.2.1",
"node-cmake": "^2.5.1"
"xmlbuilder": "^4.2.1"
},
"main": "lib/index.js",
"binary": {
"napi_versions": [8],
"napi_versions": [
8
],
"module_name": "node_osrm",
"module_path": "./lib/binding_napi_v{napi_build_version}/",
"host": "https://github.com",
+1
View File
@@ -90,6 +90,7 @@ function setup()
path = walking_speed,
steps = walking_speed,
pedestrian = walking_speed,
platform = walking_speed,
footway = walking_speed,
pier = walking_speed,
},
+211
View File
@@ -0,0 +1,211 @@
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const seedrandom = require('seedrandom');
let RNG;
class GPSData {
constructor(gpsTracesFilePath) {
this.tracks = {};
this.coordinates = [];
this.trackIds = [];
this._loadGPSTraces(gpsTracesFilePath);
}
_loadGPSTraces(gpsTracesFilePath) {
const expandedPath = path.resolve(gpsTracesFilePath);
const data = fs.readFileSync(expandedPath, 'utf-8');
const lines = data.split('\n');
const headers = lines[0].split(',');
const latitudeIndex = headers.indexOf('Latitude');
const longitudeIndex = headers.indexOf('Longitude');
const trackIdIndex = headers.indexOf('TrackID');
for (let i = 1; i < lines.length; i++) {
if (lines[i].trim() === '') continue;
const row = lines[i].split(',');
const latitude = parseFloat(row[latitudeIndex]);
const longitude = parseFloat(row[longitudeIndex]);
const trackId = row[trackIdIndex];
const coord = [longitude, latitude];
this.coordinates.push(coord);
if (!this.tracks[trackId]) {
this.tracks[trackId] = [];
}
this.tracks[trackId].push(coord);
}
this.trackIds = Object.keys(this.tracks);
}
getRandomCoordinate() {
const randomIndex = Math.floor(RNG() * this.coordinates.length);
return this.coordinates[randomIndex];
}
getRandomTrack() {
const randomIndex = Math.floor(RNG() * this.trackIds.length);
const trackId = this.trackIds[randomIndex];
return this.tracks[trackId];
}
};
async function runOSRMMethod(osrm, method, coordinates) {
const time = await new Promise((resolve, reject) => {
const startTime = process.hrtime();
osrm[method]({coordinates}, (err, result) => {
if (err) {
if (['NoSegment', 'NoMatch', 'NoRoute', 'NoTrips'].includes(err.message)) {
resolve(null);
} else {
reject(err);
}
} else {
const endTime = process.hrtime(startTime);
resolve(endTime[0] + endTime[1] / 1e9);
}
});
});
return time;
}
async function nearest(osrm, gpsData) {
const times = [];
for (let i = 0; i < 1000; i++) {
const coord = gpsData.getRandomCoordinate();
times.push(await runOSRMMethod(osrm, 'nearest', [coord]));
}
return times;
}
async function route(osrm, gpsData) {
const times = [];
for (let i = 0; i < 1000; i++) {
const from = gpsData.getRandomCoordinate();
const to = gpsData.getRandomCoordinate();
times.push(await runOSRMMethod(osrm, 'route', [from, to]));
}
return times;
}
async function table(osrm, gpsData) {
const times = [];
for (let i = 0; i < 250; i++) {
const numPoints = Math.floor(RNG() * 3) + 15;
const coordinates = [];
for (let i = 0; i < numPoints; i++) {
coordinates.push(gpsData.getRandomCoordinate());
}
times.push(await runOSRMMethod(osrm, 'table', coordinates));
}
return times;
}
async function match(osrm, gpsData) {
const times = [];
for (let i = 0; i < 1000; i++) {
const numPoints = Math.floor(RNG() * 50) + 50;
const coordinates = gpsData.getRandomTrack().slice(0, numPoints);
times.push(await runOSRMMethod(osrm, 'match', coordinates));
}
return times;
}
async function trip(osrm, gpsData) {
const times = [];
for (let i = 0; i < 250; i++) {
const numPoints = Math.floor(RNG() * 2) + 5;
const coordinates = [];
for (let i = 0; i < numPoints; i++) {
coordinates.push(gpsData.getRandomCoordinate());
}
times.push(await runOSRMMethod(osrm, 'trip', coordinates));
}
return times;
}
function bootstrapConfidenceInterval(data, numSamples = 1000, confidenceLevel = 0.95) {
let means = [];
let dataLength = data.length;
for (let i = 0; i < numSamples; i++) {
let sample = [];
for (let j = 0; j < dataLength; j++) {
let randomIndex = Math.floor(RNG() * dataLength);
sample.push(data[randomIndex]);
}
let sampleMean = sample.reduce((a, b) => a + b, 0) / sample.length;
means.push(sampleMean);
}
means.sort((a, b) => a - b);
let lowerBoundIndex = Math.floor((1 - confidenceLevel) / 2 * numSamples);
let upperBoundIndex = Math.floor((1 + confidenceLevel) / 2 * numSamples);
let mean = means.reduce((a, b) => a + b, 0) / means.length;
let lowerBound = means[lowerBoundIndex];
let upperBound = means[upperBoundIndex];
return { mean: mean, lowerBound: lowerBound, upperBound: upperBound };
}
function calculateConfidenceInterval(data) {
let { mean, lowerBound, upperBound } = bootstrapConfidenceInterval(data);
let bestValue = Math.max(...data);
let errorMargin = (upperBound - lowerBound) / 2;
return { mean, errorMargin, bestValue };
}
async function main() {
const args = process.argv.slice(2);
const {OSRM} = require(args[0]);
const path = args[1];
const algorithm = args[2].toUpperCase();
const method = args[3];
const gpsTracesFilePath = args[4];
const iterations = parseInt(args[5]);
const gpsData = new GPSData(gpsTracesFilePath);
const osrm = new OSRM({path, algorithm});
const functions = {
route: route,
table: table,
nearest: nearest,
match: match,
trip: trip
};
const func = functions[method];
if (!func) {
throw new Error('Unknown method');
}
const allTimes = [];
for (let i = 0; i < iterations; i++) {
RNG = seedrandom(42);
allTimes.push((await func(osrm, gpsData)).filter(t => t !== null));
}
const opsPerSec = allTimes.map(times => times.length / times.reduce((a, b) => a + b, 0));
const { mean, errorMargin, bestValue } = calculateConfidenceInterval(opsPerSec);
console.log(`Ops: ${mean.toFixed(1)} ± ${errorMargin.toFixed(1)} ops/s. Best: ${bestValue.toFixed(1)} ops/s`);
}
main();
+13
View File
@@ -53,6 +53,7 @@ function run_benchmarks_for_folder {
mkdir -p $RESULTS_FOLDER
BENCHMARKS_FOLDER="$BINARIES_FOLDER/src/benchmarks"
echo "Running match-bench MLD"
$BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
echo "Running match-bench CH"
@@ -81,6 +82,18 @@ function run_benchmarks_for_folder {
echo "Running osrm-contract"
measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_contract.bench"
for ALGORITHM in ch mld; do
for BENCH in nearest table trip route match; do
echo "Running node $BENCH $ALGORITHM"
START=$(date +%s.%N)
node $SCRIPTS_FOLDER/scripts/ci/bench.js $FOLDER/lib/binding/node_osrm.node $FOLDER/data.osrm $ALGORITHM $BENCH $GPS_TRACES > "$RESULTS_FOLDER/node_${BENCH}_${ALGORITHM}.bench" 5
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
echo "Took: ${DIFF}s"
done
done
for ALGORITHM in ch mld; do
for BENCH in nearest table trip route match; do
echo "Running random $BENCH $ALGORITHM"
+7 -1
View File
@@ -16,8 +16,8 @@
#include "osrm/osrm.hpp"
#include "osrm/status.hpp"
#include "util/meminfo.hpp"
#include <boost/assert.hpp>
#include <boost/optional/optional.hpp>
#include <cstdlib>
#include <exception>
@@ -655,6 +655,12 @@ try
std::cerr << "Unknown benchmark: " << benchmarkToRun << std::endl;
return EXIT_FAILURE;
}
std::cout << "Peak RAM: " << std::setprecision(3)
<< static_cast<double>(osrm::util::PeakRAMUsedInBytes()) /
static_cast<double>((1024 * 1024))
<< "MB" << std::endl;
return EXIT_SUCCESS;
}
catch (const std::exception &e)
@@ -222,7 +222,6 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
std::vector<EdgeDuration> durations_table(target_indices.size(), MAXIMAL_EDGE_DURATION);
std::vector<EdgeDistance> distances_table(calculate_distance ? target_indices.size() : 0,
MAXIMAL_EDGE_DISTANCE);
std::vector<NodeID> middle_nodes_table(target_indices.size(), SPECIAL_NODEID);
// Collect destination (source) nodes into a map
std::unordered_multimap<NodeID, std::tuple<std::size_t, EdgeWeight, EdgeDuration, EdgeDistance>>
@@ -307,7 +306,6 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
weights_table[index] = path_weight;
durations_table[index] = path_duration;
current_distance = path_distance;
middle_nodes_table[index] = node;
}
// Remove node from destinations list
+175
View File
@@ -0,0 +1,175 @@
#include "util/d_ary_heap.hpp"
#include <boost/test/unit_test.hpp>
using namespace osrm::util;
BOOST_AUTO_TEST_SUITE(d_ary_heap_test)
BOOST_AUTO_TEST_CASE(test_empty_heap)
{
DAryHeap<int, 2> heap;
BOOST_CHECK(heap.empty());
BOOST_CHECK_EQUAL(heap.size(), 0);
heap.emplace(10, [](int &, size_t) {});
BOOST_CHECK(!heap.empty());
BOOST_CHECK_EQUAL(heap.size(), 1);
}
BOOST_AUTO_TEST_CASE(test_emplace_and_top)
{
DAryHeap<int, 2> heap;
heap.emplace(10, [](int &, size_t) {});
heap.emplace(5, [](int &, size_t) {});
heap.emplace(8, [](int &, size_t) {});
BOOST_CHECK_EQUAL(heap.top(), 5);
BOOST_CHECK_EQUAL(heap.size(), 3);
}
BOOST_AUTO_TEST_CASE(test_pop)
{
DAryHeap<int, 2> heap;
heap.emplace(10, [](int &, size_t) {});
heap.emplace(5, [](int &, size_t) {});
heap.emplace(8, [](int &, size_t) {});
heap.pop([](int &, size_t) {});
BOOST_CHECK_EQUAL(heap.top(), 8);
BOOST_CHECK_EQUAL(heap.size(), 2);
heap.pop([](int &, size_t) {});
BOOST_CHECK_EQUAL(heap.top(), 10);
BOOST_CHECK_EQUAL(heap.size(), 1);
}
BOOST_AUTO_TEST_CASE(test_decrease)
{
struct HeapData
{
int key;
int data;
bool operator<(const HeapData &other) const { return key < other.key; }
};
DAryHeap<HeapData, 2> heap;
size_t handle = DAryHeap<HeapData, 2>::INVALID_HANDLE;
auto reorder_handler = [&](const HeapData &value, size_t new_handle)
{
if (value.data == 42)
{
handle = new_handle;
}
};
heap.emplace({10, 42}, reorder_handler);
heap.emplace({5, 73}, reorder_handler);
heap.emplace({8, 37}, reorder_handler);
heap.decrease(handle, {3, 42}, reorder_handler);
BOOST_CHECK_EQUAL(heap.size(), 3);
BOOST_CHECK_EQUAL(heap.top().key, 3);
BOOST_CHECK_EQUAL(heap.top().data, 42);
heap.pop(reorder_handler);
BOOST_CHECK_EQUAL(heap.size(), 2);
BOOST_CHECK_EQUAL(heap.top().key, 5);
BOOST_CHECK_EQUAL(heap.top().data, 73);
heap.pop(reorder_handler);
BOOST_CHECK_EQUAL(heap.size(), 1);
BOOST_CHECK_EQUAL(heap.top().key, 8);
BOOST_CHECK_EQUAL(heap.top().data, 37);
heap.pop(reorder_handler);
BOOST_CHECK_EQUAL(heap.size(), 0);
BOOST_CHECK(heap.empty());
}
BOOST_AUTO_TEST_CASE(test_reorder_handler)
{
std::vector<int> reordered_values;
std::vector<size_t> reordered_indices;
auto reorder_handler = [&](int value, size_t index)
{
reordered_values.push_back(value);
reordered_indices.push_back(index);
};
DAryHeap<int, 2> heap;
std::vector<int> expected_reordered_values;
std::vector<int> expected_reordered_indices;
heap.emplace(10, reorder_handler);
expected_reordered_values = {10};
expected_reordered_indices = {0};
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_values.begin(),
reordered_values.end(),
expected_reordered_values.begin(),
expected_reordered_values.end());
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_indices.begin(),
reordered_indices.end(),
expected_reordered_indices.begin(),
expected_reordered_indices.end());
heap.emplace(5, reorder_handler);
expected_reordered_values = {10, 10, 5};
expected_reordered_indices = {0, 1, 0};
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_values.begin(),
reordered_values.end(),
expected_reordered_values.begin(),
expected_reordered_values.end());
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_indices.begin(),
reordered_indices.end(),
expected_reordered_indices.begin(),
expected_reordered_indices.end());
heap.emplace(8, reorder_handler);
expected_reordered_values = {10, 10, 5, 8};
expected_reordered_indices = {0, 1, 0, 2};
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_values.begin(),
reordered_values.end(),
expected_reordered_values.begin(),
expected_reordered_values.end());
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_indices.begin(),
reordered_indices.end(),
expected_reordered_indices.begin(),
expected_reordered_indices.end());
heap.pop(reorder_handler);
expected_reordered_values = {10, 10, 5, 8, 8};
expected_reordered_indices = {0, 1, 0, 2, 0};
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_values.begin(),
reordered_values.end(),
expected_reordered_values.begin(),
expected_reordered_values.end());
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_indices.begin(),
reordered_indices.end(),
expected_reordered_indices.begin(),
expected_reordered_indices.end());
heap.pop(reorder_handler);
expected_reordered_values = {10, 10, 5, 8, 8, 10};
expected_reordered_indices = {0, 1, 0, 2, 0, 0};
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_values.begin(),
reordered_values.end(),
expected_reordered_values.begin(),
expected_reordered_values.end());
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_indices.begin(),
reordered_indices.end(),
expected_reordered_indices.begin(),
expected_reordered_indices.end());
heap.pop(reorder_handler);
expected_reordered_values = {10, 10, 5, 8, 8, 10};
expected_reordered_indices = {0, 1, 0, 2, 0, 0};
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_values.begin(),
reordered_values.end(),
expected_reordered_values.begin(),
expected_reordered_values.end());
BOOST_CHECK_EQUAL_COLLECTIONS(reordered_indices.begin(),
reordered_indices.end(),
expected_reordered_indices.begin(),
expected_reordered_indices.end());
}
BOOST_AUTO_TEST_SUITE_END()
+22
View File
@@ -120,6 +120,28 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_all_test, T, storage_types, RandomDataFi
BOOST_CHECK(heap.Empty());
}
BOOST_FIXTURE_TEST_CASE_TEMPLATE(smoke_test, T, storage_types, RandomDataFixture<NUM_NODES>)
{
QueryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(NUM_NODES);
for (unsigned idx : order)
{
heap.Insert(ids[idx], weights[idx], data[idx]);
}
while (!heap.Empty())
{
auto old_weight = heap.MinKey();
auto node = heap.GetHeapNodeIfWasInserted(heap.Min());
BOOST_CHECK(old_weight == node->weight);
BOOST_CHECK(node);
node->weight = node->weight - 1;
heap.DecreaseKey(*node);
BOOST_CHECK(heap.MinKey() == node->weight);
heap.DeleteMin();
}
}
BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomDataFixture<10>)
{
QueryHeap<TestNodeID, TestKey, TestWeight, TestData, T> heap(10);