Skip to content

Commit

Permalink
Add an program option to specify the number of threads.
Browse files Browse the repository at this point in the history
With the latest changes, we can do calculation in parallel in multiple different threads.

The updateCache API call is not thread-safe yet. We need to add locks around the transitData object and the updateCache
call. But in the majority of cases, we do not use this api call, so it's safe to use as is for the moment.
  • Loading branch information
greenscientist committed Nov 24, 2023
1 parent 5a0755f commit 250d80e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions connection_scan_algorithm/include/program_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace TrRouting
bool debug;
bool cacheAllConnectionSets;
bool useEuclideanDistance;
int numberOfThreads;
std::string algorithm;
std::string dataFetcherShortname;
std::string osrmWalkingPort;
Expand Down
7 changes: 7 additions & 0 deletions connection_scan_algorithm/src/program_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace TrRouting {
("cacheAllConnectionSets", boost::program_options::value<bool>() ->default_value(false), "cache all connections set instead of the ones from the last used scenario");
options.add_options()
("useEuclideanDistance", boost::program_options::value<bool>() ->default_value(false), "Use euclidean distance calculation instead of OSRM for access and egress calculations");
options.add_options()
("threads", boost::program_options::value<int>() ->default_value(1), "Number of threads to use to serve requests");
options.add_options()
("osrmPort,osrmWalkPort,osrmWalkingPort", boost::program_options::value<std::string>()->default_value("5000"), "osrm walking port");
options.add_options()
Expand All @@ -46,6 +48,7 @@ namespace TrRouting {
cachePath = "cache";
cacheAllConnectionSets = false;
useEuclideanDistance = false;
numberOfThreads = 1;
osrmWalkingPort = "5000";
osrmCyclingPort = "8000";
osrmDrivingPort = "7000";
Expand Down Expand Up @@ -85,6 +88,10 @@ namespace TrRouting {
{
useEuclideanDistance = variablesMap["useEuclideanDistance"].as<bool>();
}
if(variablesMap.count("threads") == 1)
{
numberOfThreads = variablesMap["threads"].as<int>();
}

if(variablesMap.count("osrmWalkPort") == 1)
{
Expand Down
6 changes: 2 additions & 4 deletions connection_scan_algorithm/src/transit_routing_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,11 @@ int main(int argc, char** argv) {
spdlog::info("Using OSRM for access/egress node time/distance");
}

spdlog::info("preparing server...");
spdlog::info("preparing server with {} threads...", programOptions.numberOfThreads);

//HTTP-server using 1 thread
//Unless you do more heavy non-threaded processing in the resources,
//1 thread is usually faster than several threads
HttpServer server;
server.config.port = programOptions.port;
server.config.thread_pool_size = programOptions.numberOfThreads;

// updateCache:
server.resource["^/updateCache[/]?$"]["GET"]=[&server, &transitData](std::shared_ptr<HttpServer::Response> serverResponse, std::shared_ptr<HttpServer::Request> request) {
Expand Down

0 comments on commit 250d80e

Please sign in to comment.