parallesim a bit of improvement

This commit is contained in:
vaclavt
2022-01-19 19:29:25 +01:00
parent 471f218bdf
commit 33554706a4
4 changed files with 28 additions and 7 deletions

View File

@@ -31,10 +31,10 @@ namespace usql {
size_t len = 0;
// TODO handle it by settings
const std::size_t hw_concurrency = std::max(0, (int)(std::thread::hardware_concurrency() - 2));
const std::size_t hw_concurrency = getConcurrency();
const bool use_threadpool = hw_concurrency > 1;
thread_pool tp{hw_concurrency};
ThreadPool tp{hw_concurrency};
std::mutex row_cnt_mutex;
try {
@@ -140,4 +140,22 @@ namespace usql {
return row_cnt;
}
size_t CsvReader::getConcurrency() {
auto value = Settings::get_setting("MAX_PARALLELISM");
if (value == "1" || value == "0")
return 0;
else if (value == "AUTO")
return std::thread::hardware_concurrency();
else {
char *end;
long i = strtol( value.c_str(), &end, 10 );
if ( *end == '\0' ) { // Success
if (i >= 0) return i;
else return std::max(std::thread::hardware_concurrency() + i, 0l);
}
}
return 0;
}
} // namespace