Link TBB task_scheduler lifetime with Engine scope
This commit is contained in:
parent
172a8bdcdb
commit
ee19383f4d
@ -3,6 +3,8 @@
|
||||
- New function to support relations: `process_relation`. Read more in profiles documentation.
|
||||
- Infrastructure:
|
||||
- Lua 5.1 support is removed due to lack of support in sol2 https://github.com/ThePhD/sol2/issues/302
|
||||
- Node.js Bindings:
|
||||
- Exposes `use_threads_number=Number` parameter of `EngineConfig` to limit a number of threads in a TBB internal pool
|
||||
|
||||
# 5.12.0
|
||||
- Guidance
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "util/fingerprint.hpp"
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@ -53,7 +55,8 @@ template <typename Algorithm> class Engine final : public EngineInterface
|
||||
{
|
||||
public:
|
||||
explicit Engine(const EngineConfig &config)
|
||||
: route_plugin(config.max_locations_viaroute, config.max_alternatives), //
|
||||
: task_scheduler(config.use_threads_number),
|
||||
route_plugin(config.max_locations_viaroute, config.max_alternatives), //
|
||||
table_plugin(config.max_locations_distance_table), //
|
||||
nearest_plugin(config.max_results_nearest), //
|
||||
trip_plugin(config.max_locations_trip), //
|
||||
@ -125,6 +128,7 @@ template <typename Algorithm> class Engine final : public EngineInterface
|
||||
}
|
||||
std::unique_ptr<DataFacadeProvider<Algorithm>> facade_provider;
|
||||
mutable SearchEngineData<Algorithm> heaps;
|
||||
tbb::task_scheduler_init task_scheduler;
|
||||
|
||||
const plugins::ViaRoutePlugin route_plugin;
|
||||
const plugins::TablePlugin table_plugin;
|
||||
|
@ -90,6 +90,8 @@ struct EngineConfig final
|
||||
int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user
|
||||
bool use_shared_memory = true;
|
||||
Algorithm algorithm = Algorithm::CH;
|
||||
int use_threads_number = 1;
|
||||
std::string verbosity;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +186,7 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
params->Get(Nan::New("max_locations_map_matching").ToLocalChecked());
|
||||
auto max_results_nearest = params->Get(Nan::New("max_results_nearest").ToLocalChecked());
|
||||
auto max_alternatives = params->Get(Nan::New("max_alternatives").ToLocalChecked());
|
||||
auto use_threads_number = params->Get(Nan::New("use_threads_number").ToLocalChecked());
|
||||
|
||||
if (!max_locations_trip->IsUndefined() && !max_locations_trip->IsNumber())
|
||||
{
|
||||
@ -217,6 +218,11 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
Nan::ThrowError("max_alternatives must be an integral number");
|
||||
return engine_config_ptr();
|
||||
}
|
||||
if (!use_threads_number->IsUndefined() && !use_threads_number->IsNumber())
|
||||
{
|
||||
Nan::ThrowError("use_threads_number must be an integral number");
|
||||
return engine_config_ptr();
|
||||
}
|
||||
|
||||
if (max_locations_trip->IsNumber())
|
||||
engine_config->max_locations_trip = static_cast<int>(max_locations_trip->NumberValue());
|
||||
@ -233,6 +239,8 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
engine_config->max_results_nearest = static_cast<int>(max_results_nearest->NumberValue());
|
||||
if (max_alternatives->IsNumber())
|
||||
engine_config->max_alternatives = static_cast<int>(max_alternatives->NumberValue());
|
||||
if (use_threads_number->IsNumber())
|
||||
engine_config->use_threads_number = static_cast<int>(use_threads_number->NumberValue());
|
||||
|
||||
return engine_config;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ bool EngineConfig::IsValid() const
|
||||
unlimited_or_more_than(max_locations_trip, 2) &&
|
||||
unlimited_or_more_than(max_locations_viaroute, 2) &&
|
||||
unlimited_or_more_than(max_results_nearest, 0) &&
|
||||
max_alternatives >= 0;
|
||||
max_alternatives >= 0 && use_threads_number >= 1;
|
||||
|
||||
return ((use_shared_memory && all_path_are_empty) || storage_config.IsValid()) && limits_valid;
|
||||
}
|
||||
|
@ -52,36 +52,37 @@ const static unsigned INIT_OK_START_ENGINE = 0;
|
||||
const static unsigned INIT_OK_DO_NOT_START_ENGINE = 1;
|
||||
const static unsigned INIT_FAILED = -1;
|
||||
|
||||
static EngineConfig::Algorithm stringToAlgorithm(std::string algorithm)
|
||||
namespace osrm
|
||||
{
|
||||
boost::to_lower(algorithm);
|
||||
namespace engine
|
||||
{
|
||||
std::istream &operator>>(std::istream &in, EngineConfig::Algorithm &algorithm)
|
||||
{
|
||||
std::string token;
|
||||
in >> token;
|
||||
boost::to_lower(token);
|
||||
|
||||
if (algorithm == "ch")
|
||||
return EngineConfig::Algorithm::CH;
|
||||
if (algorithm == "corech")
|
||||
return EngineConfig::Algorithm::CoreCH;
|
||||
if (algorithm == "mld")
|
||||
return EngineConfig::Algorithm::MLD;
|
||||
throw util::RuntimeError(algorithm, ErrorCode::UnknownAlgorithm, SOURCE_REF);
|
||||
if (token == "ch")
|
||||
algorithm = EngineConfig::Algorithm::CH;
|
||||
else if (token == "corech")
|
||||
algorithm = EngineConfig::Algorithm::CoreCH;
|
||||
else if (token == "mld")
|
||||
algorithm = EngineConfig::Algorithm::MLD;
|
||||
else
|
||||
throw util::RuntimeError(token, ErrorCode::UnknownAlgorithm, SOURCE_REF);
|
||||
return in;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
inline unsigned generateServerProgramOptions(const int argc,
|
||||
const char *argv[],
|
||||
std::string verbosity,
|
||||
boost::filesystem::path &base_path,
|
||||
std::string &ip_address,
|
||||
int &ip_port,
|
||||
int &requested_num_threads,
|
||||
bool &use_shared_memory,
|
||||
std::string &algorithm,
|
||||
bool &trial,
|
||||
int &max_locations_trip,
|
||||
int &max_locations_viaroute,
|
||||
int &max_locations_distance_table,
|
||||
int &max_locations_map_matching,
|
||||
int &max_results_nearest,
|
||||
int &max_alternatives)
|
||||
EngineConfig &config)
|
||||
{
|
||||
using boost::program_options::value;
|
||||
using boost::filesystem::path;
|
||||
@ -91,7 +92,7 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
generic_options.add_options() //
|
||||
("version,v", "Show version")("help,h", "Show this help message")(
|
||||
"verbosity,l",
|
||||
boost::program_options::value<std::string>(&verbosity)->default_value("INFO"),
|
||||
boost::program_options::value<std::string>(&config.verbosity)->default_value("INFO"),
|
||||
std::string("Log verbosity level: " + util::LogPolicy::GetLevels()).c_str())(
|
||||
"trial", value<bool>(&trial)->implicit_value(true), "Quit after initialization");
|
||||
|
||||
@ -105,31 +106,32 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
value<int>(&ip_port)->default_value(5000),
|
||||
"TCP/IP port") //
|
||||
("threads,t",
|
||||
value<int>(&requested_num_threads)->default_value(8),
|
||||
value<int>(&config.use_threads_number)->default_value(8),
|
||||
"Number of threads to use") //
|
||||
("shared-memory,s",
|
||||
value<bool>(&use_shared_memory)->implicit_value(true)->default_value(false),
|
||||
value<bool>(&config.use_shared_memory)->implicit_value(true)->default_value(false),
|
||||
"Load data from shared memory") //
|
||||
("algorithm,a",
|
||||
value<std::string>(&algorithm)->default_value("CH"),
|
||||
value<EngineConfig::Algorithm>(&config.algorithm)
|
||||
->default_value(EngineConfig::Algorithm::CH, "CH"),
|
||||
"Algorithm to use for the data. Can be CH, CoreCH, MLD.") //
|
||||
("max-viaroute-size",
|
||||
value<int>(&max_locations_viaroute)->default_value(500),
|
||||
value<int>(&config.max_locations_viaroute)->default_value(500),
|
||||
"Max. locations supported in viaroute query") //
|
||||
("max-trip-size",
|
||||
value<int>(&max_locations_trip)->default_value(100),
|
||||
value<int>(&config.max_locations_trip)->default_value(100),
|
||||
"Max. locations supported in trip query") //
|
||||
("max-table-size",
|
||||
value<int>(&max_locations_distance_table)->default_value(100),
|
||||
value<int>(&config.max_locations_distance_table)->default_value(100),
|
||||
"Max. locations supported in distance table query") //
|
||||
("max-matching-size",
|
||||
value<int>(&max_locations_map_matching)->default_value(100),
|
||||
value<int>(&config.max_locations_map_matching)->default_value(100),
|
||||
"Max. locations supported in map matching query") //
|
||||
("max-nearest-size",
|
||||
value<int>(&max_results_nearest)->default_value(100),
|
||||
value<int>(&config.max_results_nearest)->default_value(100),
|
||||
"Max. results supported in nearest query") //
|
||||
("max-alternatives",
|
||||
value<int>(&max_alternatives)->default_value(3),
|
||||
value<int>(&config.max_alternatives)->default_value(3),
|
||||
"Max. number of alternatives supported in the MLD route query");
|
||||
|
||||
// hidden options, will be allowed on command line, but will not be shown to the user
|
||||
@ -180,15 +182,15 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
|
||||
boost::program_options::notify(option_variables);
|
||||
|
||||
if (!use_shared_memory && option_variables.count("base"))
|
||||
if (!config.use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
else if (use_shared_memory && !option_variables.count("base"))
|
||||
else if (config.use_shared_memory && !option_variables.count("base"))
|
||||
{
|
||||
return INIT_OK_START_ENGINE;
|
||||
}
|
||||
else if (use_shared_memory && option_variables.count("base"))
|
||||
else if (config.use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
util::Log(logWARNING) << "Shared memory settings conflict with path settings.";
|
||||
}
|
||||
@ -203,28 +205,13 @@ int main(int argc, const char *argv[]) try
|
||||
|
||||
bool trial_run = false;
|
||||
std::string ip_address;
|
||||
int ip_port, requested_thread_num;
|
||||
int ip_port;
|
||||
|
||||
EngineConfig config;
|
||||
std::string verbosity;
|
||||
boost::filesystem::path base_path;
|
||||
std::string algorithm;
|
||||
const unsigned init_result = generateServerProgramOptions(argc,
|
||||
argv,
|
||||
verbosity,
|
||||
base_path,
|
||||
ip_address,
|
||||
ip_port,
|
||||
requested_thread_num,
|
||||
config.use_shared_memory,
|
||||
algorithm,
|
||||
trial_run,
|
||||
config.max_locations_trip,
|
||||
config.max_locations_viaroute,
|
||||
config.max_locations_distance_table,
|
||||
config.max_locations_map_matching,
|
||||
config.max_results_nearest,
|
||||
config.max_alternatives);
|
||||
|
||||
const unsigned init_result =
|
||||
generateServerProgramOptions(argc, argv, base_path, ip_address, ip_port, trial_run, config);
|
||||
if (init_result == INIT_OK_DO_NOT_START_ENGINE)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
@ -234,7 +221,7 @@ int main(int argc, const char *argv[]) try
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||
util::LogPolicy::GetInstance().SetLevel(config.verbosity);
|
||||
|
||||
if (!base_path.empty())
|
||||
{
|
||||
@ -253,7 +240,6 @@ int main(int argc, const char *argv[]) try
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
config.algorithm = stringToAlgorithm(algorithm);
|
||||
|
||||
util::Log() << "starting up engines, " << OSRM_VERSION;
|
||||
|
||||
@ -262,6 +248,10 @@ int main(int argc, const char *argv[]) try
|
||||
util::Log() << "Loading from shared memory";
|
||||
}
|
||||
|
||||
// Use the same number of threads for Server and TBB threads pools
|
||||
// It doubles number of used threads
|
||||
auto requested_thread_num = config.use_threads_number;
|
||||
|
||||
util::Log() << "Threads: " << requested_thread_num;
|
||||
util::Log() << "IP address: " << ip_address;
|
||||
util::Log() << "IP port: " << ip_port;
|
||||
|
Loading…
Reference in New Issue
Block a user