Skip to content

Commit

Permalink
add mode specific timing stats + lookup timings
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Dec 2, 2024
1 parent c246309 commit f6bf5ff
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[osr]
[email protected]:motis-project/osr.git
branch=master
commit=478bed28978461f0728c311899cc6bb22f0dd591
commit=797230efdb2fa40f2444c20e048bdbe24f67bbb2
[utl]
[email protected]:motis-project/utl.git
branch=master
Expand Down
4 changes: 2 additions & 2 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
15260926559282078310
1804700525112700337
cista 847b27100b7e730370b810ce62206a66b0bf2d79
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost 082a2d83c827e43f3b7eb8d6f0a1102cddb897ad
Expand Down Expand Up @@ -42,7 +42,7 @@ sol2 40c7cbc7c5cfed1e8c7f1bbe6fcbe23d7a67fc75
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles ab6c4b13544570f893c2d64434c613d8fd7d2ceb
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
osr 478bed28978461f0728c311899cc6bb22f0dd591
osr 797230efdb2fa40f2444c20e048bdbe24f67bbb2
reflect-cpp c54fe66de4650b60c23aadd4a06d9db4ffeda22f
FTXUI dd6a5d371fd7a3e2937bb579955003c54b727233
tg 20c0f298b8ce58de29a790290f44dca7c4ecc364
Expand Down
5 changes: 4 additions & 1 deletion include/motis/endpoints/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace motis::ep {

using stats_map_t = std::map<std::string, std::uint64_t>;

struct routing {
api::plan_response operator()(boost::urls::url_view const&) const;

Expand All @@ -22,7 +24,8 @@ struct routing {
bool wheelchair,
std::chrono::seconds max,
unsigned max_matching_distance,
gbfs::gbfs_data const*) const;
gbfs::gbfs_data const*,
stats_map_t&) const;

nigiri::hash_map<nigiri::location_idx_t,
std::vector<nigiri::routing::td_offset>>
Expand Down
18 changes: 10 additions & 8 deletions src/endpoints/footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ api::footpaths_response footpaths::operator()(
auto const loc = get_loc(tt_, w_, pl_, matches_, l);
for (auto const mode :
{osr::search_profile::kFoot, osr::search_profile::kWheelchair}) {
auto const results = osr::route(
w_, l_, mode, loc,
utl::to_vec(
neighbors,
[&](auto&& l) { return get_loc(tt_, w_, pl_, matches_, l); }),
kMaxDuration, osr::direction::kForward, kMaxMatchingDistance,
e == nullptr ? nullptr : &e->blocked_, nullptr,
[](osr::path const& p) { return p.uses_elevator_; });
auto const results =
osr::route(w_, l_, mode, loc,
utl::to_vec(neighbors,
[&](auto&& l) {
return get_loc(tt_, w_, pl_, matches_, l);
}),
kMaxDuration, osr::direction::kForward, kMaxMatchingDistance,
e == nullptr ? nullptr : &e->blocked_, nullptr,
[](osr::path const& p) { return p.uses_elevator_; })
.paths_;

for (auto const [n, r] : utl::zip(neighbors, results)) {
if (r.has_value()) {
Expand Down
19 changes: 10 additions & 9 deletions src/endpoints/one_to_many.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ api::oneToMany_response one_to_many::operator()(
"mode {} not supported for one-to-many",
json::serialize(json::value_from(query.mode_)));

auto const paths = osr::route(
w_, l_, to_profile(query.mode_, false), *one, many, query.max_,
query.arriveBy_ ? osr::direction::kBackward : osr::direction::kForward,
query.maxMatchingDistance_, nullptr);

return utl::to_vec(paths, [](std::optional<osr::path> const& p) {
return p.has_value() ? api::Duration{.duration_ = p->cost_}
: api::Duration{};
});
return utl::to_vec(
osr::route(w_, l_, to_profile(query.mode_, false), *one, many, query.max_,
query.arriveBy_ ? osr::direction::kBackward
: osr::direction::kForward,
query.maxMatchingDistance_, nullptr)
.paths_,
[](std::optional<osr::path> const& p) {
return p.has_value() ? api::Duration{.duration_ = p->cost_}
: api::Duration{};
});
}

} // namespace motis::ep
66 changes: 40 additions & 26 deletions src/endpoints/routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ static boost::thread_specific_ptr<n::routing::raptor_state> raptor_state;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static boost::thread_specific_ptr<osr::bitvec<osr::node_idx_t>> blocked;

stats_map_t join(auto&&... maps) {
auto ret = std::map<std::string, std::uint64_t>{};
auto const add = [&](std::map<std::string, std::uint64_t> const& x) {
ret.insert(begin(x), end(x));
};
(add(maps), ...);
return ret;
}

place_t get_place(n::timetable const* tt,
tag_lookup const* tags,
std::string_view s) {
Expand Down Expand Up @@ -121,7 +130,8 @@ std::vector<n::routing::offset> routing::get_offsets(
bool const wheelchair,
std::chrono::seconds const max,
unsigned const max_matching_distance,
gbfs::gbfs_data const* gbfs) const {
gbfs::gbfs_data const* gbfs,
stats_map_t& stats) const {
if (!loc_tree_ || !pl_ || !tt_ || !loc_tree_ || !matches_) {
return {};
}
Expand Down Expand Up @@ -155,32 +165,47 @@ std::vector<n::routing::offset> routing::get_offsets(
pos.pos_, max_dist, [&](auto const pi) { providers.insert(pi); });

for (auto const& pi : providers) {
UTL_START_TIMING(timer);
auto const& provider = gbfs->providers_.at(pi);
auto const sharing = provider->get_sharing_data(w_->n_nodes());
auto const paths =
osr::route(*w_, *l_, profile, pos, near_stop_locations,
static_cast<osr::cost_t>(max.count()), dir,
kMaxMatchingDistance, nullptr, &sharing);
ignore_walk = true;
for (auto const [p, l] : utl::zip(paths, near_stops)) {
for (auto const [p, l] : utl::zip(paths.paths_, near_stops)) {
if (p.has_value()) {
offsets.emplace_back(l, n::duration_t{p->cost_ / 60},
static_cast<n::transport_mode_id_t>(
kGbfsTransportModeIdOffset + to_idx(pi)));
}
}
UTL_STOP_TIMING(timer);
stats.emplace(fmt::format("GBFS_{}_{}_{}", provider->id_,
fmt::streamed(dir), fmt::streamed(m)),
UTL_TIMING_MS(timer));
stats.emplace(fmt::format("GBFS_{}_{}_{}_lookup", provider->id_,
fmt::streamed(dir), fmt::streamed(m)),
paths.lookup_time_.count());
}

} else {
UTL_START_TIMING(timer);
auto const paths = osr::route(*w_, *l_, profile, pos, near_stop_locations,
static_cast<osr::cost_t>(max.count()), dir,
max_matching_distance, nullptr, nullptr);
for (auto const [p, l] : utl::zip(paths, near_stops)) {
for (auto const [p, l] : utl::zip(paths.paths_, near_stops)) {
if (p.has_value()) {
offsets.emplace_back(l, n::duration_t{p->cost_ / 60},
static_cast<n::transport_mode_id_t>(profile));
}
}
UTL_STOP_TIMING(timer);
stats.emplace(fmt::format("{}_{}", fmt::streamed(dir), fmt::streamed(m)),
UTL_TIMING_MS(timer));
stats.emplace(
fmt::format("{}_{}_lookup", fmt::streamed(dir), fmt::streamed(m)),
paths.lookup_time_.count());
}
};

Expand Down Expand Up @@ -281,17 +306,6 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
return {itineraries, fastest_direct};
}

using stats_map_t = std::map<std::string, std::uint64_t>;

stats_map_t join(auto&&... maps) {
auto ret = std::map<std::string, std::uint64_t>{};
auto const add = [&](std::map<std::string, std::uint64_t> const& x) {
ret.insert(begin(x), end(x));
};
(add(maps), ...);
return ret;
}

void remove_slower_than_fastest_direct(n::routing::query& q) {
if (!q.fastest_direct_) {
return;
Expand Down Expand Up @@ -394,6 +408,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
"mode=TRANSIT requires timetable to be loaded");

UTL_START_TIMING(query_preparation);
auto stats = stats_map_t{};
auto q = n::routing::query{
.start_time_ = start_time.start_time_,
.start_match_mode_ = get_match_mode(start),
Expand All @@ -408,7 +423,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
return get_offsets(
pos, dir, start_modes, query.wheelchair_,
std::chrono::seconds{query.maxPreTransitTime_},
query.maxMatchingDistance_, gbfs.get());
query.maxMatchingDistance_, gbfs.get(), stats);
}},
start),
.destination_ = std::visit(
Expand All @@ -420,7 +435,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
return get_offsets(
pos, dir, dest_modes, query.wheelchair_,
std::chrono::seconds{query.maxPostTransitTime_},
query.maxMatchingDistance_, gbfs.get());
query.maxMatchingDistance_, gbfs.get(), stats);
}},
dest),
.td_start_ =
Expand Down Expand Up @@ -491,22 +506,21 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
raptor_state.reset(new n::routing::raptor_state{});
}

auto const query_stats =
stats_map_t{{"direct", UTL_TIMING_MS(direct)},
{"query_preparation", UTL_TIMING_MS(query_preparation)},
{"n_start_offsets", q.start_.size()},
{"n_dest_offsets", q.destination_.size()},
{"n_td_start_offsets", q.td_start_.size()},
{"n_td_dest_offsets", q.td_dest_.size()}};

auto const r = n::routing::raptor_search(
*tt_, rtt, *search_state, *raptor_state, std::move(q),
query.arriveBy_ ? n::direction::kBackward : n::direction::kForward,
std::nullopt);

return {
.debugOutput_ = join(std::move(query_stats), r.search_stats_.to_map(),
r.algo_stats_.to_map()),
.debugOutput_ = join(
stats,
stats_map_t{{"direct", UTL_TIMING_MS(direct)},
{"query_preparation", UTL_TIMING_MS(query_preparation)},
{"n_start_offsets", q.start_.size()},
{"n_dest_offsets", q.destination_.size()},
{"n_td_start_offsets", q.td_start_.size()},
{"n_td_dest_offsets", q.td_dest_.size()}},
r.search_stats_.to_map(), r.algo_stats_.to_map()),
.from_ = from_p,
.to_ = to_p,
.direct_ = std::move(direct),
Expand Down
2 changes: 1 addition & 1 deletion src/update_rtt_td_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::vector<n::td_footpath> get_td_footpaths(
static_cast<osr::cost_t>(max.count()), dir,
get_max_distance(profile, max), &blocked_mem);

for (auto const [to, p] : utl::zip(neighbors, results)) {
for (auto const [to, p] : utl::zip(neighbors, results.paths_)) {
auto const duration = p.has_value() && (n::duration_t{p->cost_ / 60U} <
n::footpath::kMaxDuration)
? n::duration_t{p->cost_ / 60U}
Expand Down

0 comments on commit f6bf5ff

Please sign in to comment.