Skip to content

Commit

Permalink
fiber executor
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Nov 29, 2024
1 parent 47404be commit 6ec1ad7
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
[boost]
[email protected]:motis-project/boost.git
branch=boost-1.86.0
commit=930f38eb0365ceb7853273e03da4d9e7787abfb9
commit=082a2d83c827e43f3b7eb8d6f0a1102cddb897ad
[tg]
[email protected]:triptix-tech/tg.git
branch=main
Expand Down
4 changes: 2 additions & 2 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
6176226545254116619
8748848983185993664
cista 847b27100b7e730370b810ce62206a66b0bf2d79
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost 930f38eb0365ceb7853273e03da4d9e7787abfb9
boost 082a2d83c827e43f3b7eb8d6f0a1102cddb897ad
googletest 7b64fca6ea0833628d6f86255a81424365f7cc0c
mimalloc e2f4fe647e8aff4603a7d5119b8639fd1a47c8a6
libressl 24acd9e710fbe842e863572da9d738715fbc74b8
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ target_link_libraries(motislib
osr
adr
boost-json
Boost::fiber
motis-api
reflectcpp
web-server
Expand Down
2 changes: 1 addition & 1 deletion include/motis/journey_to_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ api::Itinerary journey_to_response(osr::ways const*,
place_t const& start,
place_t const& dest,
street_routing_cache_t&,
osr::bitvec<osr::node_idx_t>& blocked_mem);
osr::bitvec<osr::node_idx_t>* blocked_mem);

} // namespace motis
2 changes: 1 addition & 1 deletion include/motis/street_routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ api::Itinerary route(osr::ways const&,
std::optional<nigiri::unixtime_t> end_time,
gbfs_provider_idx_t,
street_routing_cache_t&,
osr::bitvec<osr::node_idx_t>& blocked_mem,
osr::bitvec<osr::node_idx_t>* blocked_mem,
std::chrono::seconds max = std::chrono::seconds{3600});

} // namespace motis
6 changes: 3 additions & 3 deletions src/endpoints/routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
(!omit_walk && m == api::ModeEnum::WALK)) {
auto itinerary = route(
*w_, *l_, gbfs, e, from, to, m, wheelchair, start_time, std::nullopt,
gbfs_provider_idx_t::invalid(), cache, *blocked, max);
gbfs_provider_idx_t::invalid(), cache, blocked.get(), max);
if (itinerary.legs_.empty()) {
continue;
}
Expand All @@ -265,7 +265,7 @@ std::pair<std::vector<api::Itinerary>, n::duration_t> routing::route_direct(
for (auto const& pi : providers) {
auto itinerary =
route(*w_, *l_, gbfs, e, from, to, m, wheelchair, start_time,
std::nullopt, pi, cache, *blocked, max);
std::nullopt, pi, cache, blocked.get(), max);
if (itinerary.legs_.empty()) {
continue;
}
Expand Down Expand Up @@ -516,7 +516,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const {
return journey_to_response(w_, l_, pl_, *tt_, *tags_, e, rtt,
matches_, shapes_, gbfs.get(),
query.wheelchair_, j, start, dest,
cache, *blocked);
cache, blocked.get());
}),
.previousPageCursor_ =
fmt::format("EARLIER|{}", to_seconds(r.interval_.from_)),
Expand Down
4 changes: 1 addition & 3 deletions src/endpoints/trip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ api::Itinerary trip::operator()(boost::urls::url_view const& url) const {
auto const start_time = from_l.time(n::event_type::kDep);
auto const dest_time = to_l.time(n::event_type::kArr);
auto cache = street_routing_cache_t{};
auto blocked = osr::bitvec<osr::node_idx_t>{};

return journey_to_response(
w_, l_, pl_, tt_, tags_, nullptr, rtt, matches_, shapes_, nullptr, false,
{.legs_ = {n::routing::journey::leg{
Expand All @@ -49,7 +47,7 @@ api::Itinerary trip::operator()(boost::urls::url_view const& url) const {
.transfers_ = 0U},
tt_location{from_l.get_location_idx(),
from_l.get_scheduled_location_idx()},
tt_location{to_l.get_location_idx()}, cache, blocked);
tt_location{to_l.get_location_idx()}, cache, nullptr);
}

} // namespace motis::ep
2 changes: 1 addition & 1 deletion src/journey_to_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ api::Itinerary journey_to_response(osr::ways const* w,
place_t const& start,
place_t const& dest,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem) {
osr::bitvec<osr::node_idx_t>* blocked_mem) {
utl::verify(!j.legs_.empty(), "journey without legs");

auto itinerary = api::Itinerary{
Expand Down
16 changes: 8 additions & 8 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace fs = std::filesystem;
namespace asio = boost::asio;
namespace bf = boost::fibers;

namespace motis {

Expand All @@ -54,9 +55,9 @@ void POST(auto&& r, std::string target, From& from) {

int server(data d, config const& c) {
auto ioc = asio::io_context{};
auto workers = asio::io_context{};
auto s = net::web_server{ioc};
auto qr = net::query_router{net::asio_exec(ioc, workers)};
auto ch = net::fiber_exec::channel_t{2048U};
auto qr = net::query_router{net::fiber_exec(ioc, ch)};

POST<ep::matches>(qr, "/api/matches", d);
POST<ep::elevators>(qr, "/api/elevators", d);
Expand Down Expand Up @@ -101,7 +102,7 @@ int server(data d, config const& c) {
if (c.requires_rt_timetable_updates()) {
rt_update_ioc = std::make_unique<asio::io_context>();
rt_update_thread = std::make_unique<std::thread>([&]() {
utl::set_current_thread_name("rt update");
utl::set_current_thread_name("motis rt update");
run_rt_update(*rt_update_ioc, c, *d.tt_, *d.tags_, d.rt_);
rt_update_ioc->run();
});
Expand All @@ -112,18 +113,17 @@ int server(data d, config const& c) {
if (d.w_ && d.l_ && c.has_gbfs_feeds()) {
gbfs_update_ioc = std::make_unique<asio::io_context>();
gbfs_update_thread = std::make_unique<std::thread>([&]() {
utl::set_current_thread_name("gbfs update");
utl::set_current_thread_name("motis gbfs update");
gbfs::run_gbfs_update(*gbfs_update_ioc, c, *d.w_, *d.l_, d.gbfs_);
gbfs_update_ioc->run();
});
}

auto const work_guard = asio::make_work_guard(workers);
auto threads = std::vector<std::thread>(
static_cast<unsigned>(std::max(1U, server_config.n_threads_)));
for (auto [i, t] : utl::enumerate(threads)) {
t = std::thread(net::run(workers));
utl::set_thread_name(t, fmt::format("worker {}", i));
t = std::thread(net::fiber_exec::run(ch, server_config.n_threads_));
utl::set_thread_name(t, fmt::format("motis worker {}", i));
}

auto const stop = net::stop_handler(ioc, [&]() {
Expand All @@ -143,7 +143,7 @@ int server(data d, config const& c) {
server_config.host_, server_config.port_, server_config.port_);
net::run(ioc)();

workers.stop();
ch.close();
for (auto& t : threads) {
t.join();
}
Expand Down
15 changes: 8 additions & 7 deletions src/street_routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::optional<osr::path> get_path(osr::ways const& w,
nigiri::unixtime_t const start_time,
osr::cost_t const max,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem) {
osr::bitvec<osr::node_idx_t>* blocked_mem) {
auto const s = e ? get_states_at(w, l, *e, start_time, from.pos_)
: std::optional{std::pair<nodes_t, states_t>{}};
auto const& [e_nodes, e_states] = *s;
Expand All @@ -38,11 +38,12 @@ std::optional<osr::path> get_path(osr::ways const& w,
auto const path =
it != end(cache)
? it->second
: osr::route(
w, l, profile, from, to, max, osr::direction::kForward,
kMaxMatchingDistance,
s ? &set_blocked(e_nodes, e_states, blocked_mem) : nullptr,
sharing);
: osr::route(w, l, profile, from, to, max, osr::direction::kForward,
kMaxMatchingDistance,
s && blocked_mem
? &set_blocked(e_nodes, e_states, *blocked_mem)
: nullptr,
sharing);
if (it == end(cache)) {
cache.emplace(std::pair{key, path});
}
Expand Down Expand Up @@ -213,7 +214,7 @@ api::Itinerary route(osr::ways const& w,
std::optional<n::unixtime_t> const end_time,
gbfs_provider_idx_t const provider_idx,
street_routing_cache_t& cache,
osr::bitvec<osr::node_idx_t>& blocked_mem,
osr::bitvec<osr::node_idx_t>* blocked_mem,
std::chrono::seconds const max) {
auto const profile = to_profile(mode, wheelchair);
utl::verify(profile != osr::search_profile::kBikeSharing || gbfs != nullptr,
Expand Down

0 comments on commit 6ec1ad7

Please sign in to comment.