Skip to content

Commit 6dc3a20

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

File tree

5 files changed

+27
-36
lines changed

5 files changed

+27
-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.
135136

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

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

+20-24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ std::string bool2String(bool value) {
3737
return value ? "true" : "false";
3838
}
3939

40+
int getThreadCount() {
41+
auto numThreads = std::thread::hardware_concurrency();
42+
// The spec says std::thread::hardware_concurrency() might return 0.
43+
// But we depend on std::thread::hardware_concurrency() to create executors.
44+
// Check to ensure numThreads is > 0.
45+
VELOX_CHECK_GT(numThreads, 0);
46+
return numThreads;
47+
}
48+
4049
#define STR_PROP(_key_, _val_) \
4150
{ std::string(_key_), std::string(_val_) }
4251
#define NUM_PROP(_key_, _val_) \
@@ -76,21 +85,6 @@ std::string ConfigBase::capacityPropertyAsBytesString(
7685
velox::config::CapacityUnit::BYTE));
7786
}
7887

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-
9488
folly::Optional<std::string> ConfigBase::setValue(
9589
const std::string& propertyName,
9690
const std::string& value) {
@@ -138,7 +132,7 @@ SystemConfig::SystemConfig() {
138132
BOOL_PROP(kHttpServerReusePort, false),
139133
BOOL_PROP(kHttpServerBindToNodeInternalAddressOnlyEnabled, false),
140134
NONE_PROP(kDiscoveryUri),
141-
NUM_PROP(kMaxDriversPerTask, 16),
135+
NUM_PROP(kMaxDriversPerTask, getThreadCount()),
142136
NONE_PROP(kTaskWriterCount),
143137
NONE_PROP(kTaskPartitionedWriterCount),
144138
NUM_PROP(kConcurrentLifespansPerTask, 1),
@@ -292,14 +286,16 @@ std::string SystemConfig::prestoVersion() const {
292286
}
293287

294288
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;
289+
static const std::unordered_set<std::string> kPoolTypes = {
290+
"LEAF", "INTERMEDIATE", "DEFAULT"};
291+
static constexpr std::string_view kPoolTypeDefault = "DEFAULT";
292+
auto value = optionalProperty<std::string>(kPoolType).value_or(
293+
std::string(kPoolTypeDefault));
294+
VELOX_USER_CHECK(
295+
kPoolTypes.count(value),
296+
"{} must be one of 'LEAF', 'INTERMEDIATE', or 'DEFAULT'",
297+
kPoolType);
298+
return value;
303299
}
304300

305301
bool SystemConfig::mutableConfig() 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

+2-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,7 @@ TEST_F(ConfigTest, optionalNodeConfigs) {
217217
TEST_F(ConfigTest, optionalSystemConfigsWithDefault) {
218218
SystemConfig config;
219219
init(config, {});
220-
ASSERT_EQ(config.maxDriversPerTask(), 16);
220+
ASSERT_EQ(config.maxDriversPerTask(), std::thread::hardware_concurrency());
221221
init(config, {{std::string(SystemConfig::kMaxDriversPerTask), "1024"}});
222222
ASSERT_EQ(config.maxDriversPerTask(), 1024);
223223
}

presto-native-execution/presto_cpp/main/tests/ServerOperationTest.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ TEST_F(ServerOperationTest, systemConfigEndpoint) {
240240
{.target = ServerOperation::Target::kSystemConfig,
241241
.action = ServerOperation::Action::kGetProperty},
242242
&httpMessage);
243-
EXPECT_EQ(getPropertyResponse, "16\n");
243+
EXPECT_EQ(
244+
std::stoi(getPropertyResponse), std::thread::hardware_concurrency());
244245
}
245246

246247
} // namespace facebook::presto

0 commit comments

Comments
 (0)