Skip to content

Commit 765ca84

Browse files
committed
[native] Default task.max-drivers-per-task to hardware concurrency
1 parent 0927c8f commit 765ca84

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

presto-docs/src/main/sphinx/presto_cpp/properties.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ The configuration properties of Presto C++ workers are described here, in alphab
129129
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130130

131131
* **Type:** ``integer``
132-
* **Default value:** ``number of hardware CPUs``
132+
* **Default value:** ``number of concurrent threads supported by the host``
133133

134-
Number of drivers to use per task. Defaults to hardware CPUs.
134+
Number of drivers to use per task. Defaults to the number of concurrent
135+
threads supported by the host if computable or 16.
135136

136137
``query.max-memory-per-node``
137138
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

presto-native-execution/presto_cpp/main/common/Configs.cpp

+22-25
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,6 @@ std::string ConfigBase::capacityPropertyAsBytesString(
7676
velox::config::CapacityUnit::BYTE));
7777
}
7878

79-
bool ConfigBase::registerProperty(
80-
const std::string& propertyName,
81-
const folly::Optional<std::string>& defaultValue) {
82-
if (registeredProps_.count(propertyName) != 0) {
83-
PRESTO_STARTUP_LOG(WARNING)
84-
<< "Property '" << propertyName
85-
<< "' is already registered with default value '"
86-
<< registeredProps_[propertyName].value_or("<none>") << "'.";
87-
return false;
88-
}
89-
90-
registeredProps_[propertyName] = defaultValue;
91-
return true;
92-
}
93-
9479
folly::Optional<std::string> ConfigBase::setValue(
9580
const std::string& propertyName,
9681
const std::string& value) {
@@ -138,7 +123,7 @@ SystemConfig::SystemConfig() {
138123
BOOL_PROP(kHttpServerReusePort, false),
139124
BOOL_PROP(kHttpServerBindToNodeInternalAddressOnlyEnabled, false),
140125
NONE_PROP(kDiscoveryUri),
141-
NUM_PROP(kMaxDriversPerTask, 16),
126+
NONE_PROP(kMaxDriversPerTask),
142127
NONE_PROP(kTaskWriterCount),
143128
NONE_PROP(kTaskPartitionedWriterCount),
144129
NUM_PROP(kConcurrentLifespansPerTask, 1),
@@ -292,14 +277,16 @@ std::string SystemConfig::prestoVersion() const {
292277
}
293278

294279
std::string SystemConfig::poolType() const {
295-
static const std::unordered_set<std::string> kPoolTypes = {"LEAF", "INTERMEDIATE", "DEFAULT"};
296-
static constexpr std::string_view kPoolTypeDefault = "DEFAULT";
297-
auto value = optionalProperty<std::string>(kPoolType).value_or(std::string(kPoolTypeDefault));
298-
VELOX_USER_CHECK(
299-
kPoolTypes.count(value),
300-
"{} must be one of 'LEAF', 'INTERMEDIATE', or 'DEFAULT'",
301-
kPoolType);
302-
return value;
280+
static const std::unordered_set<std::string> kPoolTypes = {
281+
"LEAF", "INTERMEDIATE", "DEFAULT"};
282+
static constexpr std::string_view kPoolTypeDefault = "DEFAULT";
283+
auto value = optionalProperty<std::string>(kPoolType).value_or(
284+
std::string(kPoolTypeDefault));
285+
VELOX_USER_CHECK(
286+
kPoolTypes.count(value),
287+
"{} must be one of 'LEAF', 'INTERMEDIATE', or 'DEFAULT'",
288+
kPoolType);
289+
return value;
303290
}
304291

305292
bool SystemConfig::mutableConfig() const {
@@ -355,7 +342,17 @@ std::string SystemConfig::remoteFunctionServerSerde() const {
355342
}
356343

357344
int32_t SystemConfig::maxDriversPerTask() const {
358-
return optionalProperty<int32_t>(kMaxDriversPerTask).value();
345+
auto val = optionalProperty<int32_t>(kMaxDriversPerTask);
346+
if (val.has_value()) {
347+
return val.value();
348+
}
349+
auto numThreads = std::thread::hardware_concurrency();
350+
// The spec says std::thread::hardware_concurrency() might return 0.
351+
if (numThreads > 0) {
352+
return numThreads;
353+
} else {
354+
return 16;
355+
}
359356
}
360357

361358
folly::Optional<int32_t> SystemConfig::taskWriterCount() const {

presto-native-execution/presto_cpp/main/common/Configs.h

-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ class ConfigBase {
4242
config_ = std::move(config);
4343
}
4444

45-
/// Registers an extra property in the config.
46-
/// Returns true if succeeded, false if failed (due to the property already
47-
/// registered).
48-
bool registerProperty(
49-
const std::string& propertyName,
50-
const folly::Optional<std::string>& defaultValue = {});
51-
5245
/// Adds or replaces value at the given key. Can be used by debugging or
5346
/// testing code.
5447
/// Returns previous value if there was any.

presto-native-execution/presto_cpp/main/common/tests/ConfigTest.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
#include <filesystem>
1514
#include <gtest/gtest.h>
15+
#include <filesystem>
1616
#include <unordered_set>
1717
#include "presto_cpp/main/common/ConfigReader.h"
1818
#include "presto_cpp/main/common/Configs.h"
@@ -217,7 +217,9 @@ TEST_F(ConfigTest, optionalNodeConfigs) {
217217
TEST_F(ConfigTest, optionalSystemConfigsWithDefault) {
218218
SystemConfig config;
219219
init(config, {});
220-
ASSERT_EQ(config.maxDriversPerTask(), 16);
220+
// std::thread::hardware_concurrency() value depends on the host.
221+
// Most hardware should have atleast 8 threads.
222+
ASSERT_GE(config.maxDriversPerTask(), 8);
221223
init(config, {{std::string(SystemConfig::kMaxDriversPerTask), "1024"}});
222224
ASSERT_EQ(config.maxDriversPerTask(), 1024);
223225
}

0 commit comments

Comments
 (0)