Skip to content

Commit

Permalink
[native] Advance velox version and add reserved memory capacity configs
Browse files Browse the repository at this point in the history
Add two system configs for reserved query memory capacity:
query-reserved-memory-gb: the total amount of query memory capacity reserved to ensure that a
query has minimal memory capacity to run
memory-pool-reserved-capacity: the minimal amount of memory capacity in bytes reserved for
each query memory pool.
  • Loading branch information
xiaoxmeng committed Apr 26, 2024
1 parent fdc97c1 commit 9a53624
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
9 changes: 9 additions & 0 deletions presto-native-execution/presto_cpp/main/PrestoServer.cpp
Expand Up @@ -656,7 +656,16 @@ void PrestoServer::initializeVeloxMemory() {
memoryGb,
"Query memory capacity must not be larger than system memory capacity");
options.arbitratorCapacity = queryMemoryGb << 30;
const uint64_t queryReservedMemoryGb =
systemConfig->queryReservedMemoryGb();
VELOX_USER_CHECK_LE(
queryReservedMemoryGb,
queryMemoryGb,
"Query reserved memory capacity must not be larger than query memory capacity");
options.arbitratorReservedCapacity = queryReservedMemoryGb << 30;
options.memoryPoolInitCapacity = systemConfig->memoryPoolInitCapacity();
options.memoryPoolReservedCapacity =
systemConfig->memoryPoolReservedCapacity();
options.memoryPoolTransferCapacity =
systemConfig->memoryPoolTransferCapacity();
options.memoryReclaimWaitMs = systemConfig->memoryReclaimWaitMs();
Expand Down
13 changes: 12 additions & 1 deletion presto-native-execution/presto_cpp/main/common/Configs.cpp
Expand Up @@ -12,8 +12,8 @@
* limitations under the License.
*/

#include "presto_cpp/main/common/ConfigReader.h"
#include "presto_cpp/main/common/Configs.h"
#include "presto_cpp/main/common/ConfigReader.h"
#include "presto_cpp/main/common/Utils.h"
#include "velox/core/QueryConfig.h"

Expand Down Expand Up @@ -185,6 +185,7 @@ SystemConfig::SystemConfig() {
BOOL_PROP(kUseMmapAllocator, true),
STR_PROP(kMemoryArbitratorKind, ""),
NUM_PROP(kQueryMemoryGb, 38),
NUM_PROP(kQueryReservedMemoryGb, 4),
BOOL_PROP(kEnableVeloxTaskLogging, false),
BOOL_PROP(kEnableVeloxExprSetLogging, false),
NUM_PROP(kLocalShuffleMaxPartitionBytes, 268435456),
Expand Down Expand Up @@ -462,12 +463,22 @@ int32_t SystemConfig::queryMemoryGb() const {
return optionalProperty<int32_t>(kQueryMemoryGb).value();
}

int32_t SystemConfig::queryReservedMemoryGb() const {
return optionalProperty<int32_t>(kQueryReservedMemoryGb).value();
}

uint64_t SystemConfig::memoryPoolInitCapacity() const {
static constexpr uint64_t kMemoryPoolInitCapacityDefault = 128 << 20;
return optionalProperty<uint64_t>(kMemoryPoolInitCapacity)
.value_or(kMemoryPoolInitCapacityDefault);
}

uint64_t SystemConfig::memoryPoolReservedCapacity() const {
static constexpr uint64_t kMemoryPoolReservedCapacityDefault = 64 << 20;
return optionalProperty<uint64_t>(kMemoryPoolReservedCapacity)
.value_or(kMemoryPoolReservedCapacityDefault);
}

uint64_t SystemConfig::memoryPoolTransferCapacity() const {
static constexpr uint64_t kMemoryPoolTransferCapacityDefault = 32 << 20;
return optionalProperty<uint64_t>(kMemoryPoolTransferCapacity)
Expand Down
20 changes: 20 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.h
Expand Up @@ -256,6 +256,17 @@ class SystemConfig : public ConfigBase {
/// this config only applies if the memory arbitration has been enabled.
static constexpr std::string_view kQueryMemoryGb{"query-memory-gb"};

/// Specifies the amount of query memory capacity reserved to ensure that a
/// query has minimal memory capacity to run. This capacity should be less
/// than 'query-memory-gb'. A query's minimal memory capacity is specified by
/// 'memory-pool-reserved-capacity'.
///
/// NOTE: the reserved query memory capacity is enforced by memory arbitrator
/// so that this config only applies if the memory arbitration has been
/// enabled.
static constexpr std::string_view kQueryReservedMemoryGb{
"query-reserved-memory-gb"};

/// If true, enable memory pushback when the server is under low memory
/// condition. This only applies if 'system-mem-limit-gb' is set.
static constexpr std::string_view kSystemMemPushbackEnabled{
Expand Down Expand Up @@ -335,6 +346,11 @@ class SystemConfig : public ConfigBase {
static constexpr std::string_view kMemoryPoolInitCapacity{
"memory-pool-init-capacity"};

/// The minimal amount of memory capacity in bytes reserved for each query
/// memory pool.
static constexpr std::string_view kMemoryPoolReservedCapacity{
"memory-pool-reserved-capacity"};

/// The minimal memory capacity in bytes transferred between memory pools
/// during memory arbitration.
///
Expand Down Expand Up @@ -620,8 +636,12 @@ class SystemConfig : public ConfigBase {

int32_t queryMemoryGb() const;

int32_t queryReservedMemoryGb() const;

uint64_t memoryPoolInitCapacity() const;

uint64_t memoryPoolReservedCapacity() const;

uint64_t memoryPoolTransferCapacity() const;

uint64_t memoryReclaimWaitMs() const;
Expand Down
Expand Up @@ -57,14 +57,14 @@ TEST_F(RemoteFunctionRegistererTest, singleFile) {

// Write to a single output file.
auto path = exec::test::TempFilePath::create();
writeToFile(path->path, json);
writeToFile(path->getPath(), json);

// Check functions do not exist first.
EXPECT_TRUE(exec::getVectorFunctionSignatures("mock1") == std::nullopt);
EXPECT_TRUE(exec::getVectorFunctionSignatures("mock2") == std::nullopt);

// Read and register functions in that file.
EXPECT_EQ(registerRemoteFunctions(path->path, {}), 2);
EXPECT_EQ(registerRemoteFunctions(path->getPath(), {}), 2);
EXPECT_TRUE(exec::getVectorFunctionSignatures("mock1") != std::nullopt);
EXPECT_TRUE(exec::getVectorFunctionSignatures("mock2") != std::nullopt);
}
Expand All @@ -87,7 +87,7 @@ TEST_F(RemoteFunctionRegistererTest, prefixes) {

// Write to a single output file.
auto path = exec::test::TempFilePath::create();
writeToFile(path->path, json);
writeToFile(path->getPath(), json);

EXPECT_TRUE(exec::getVectorFunctionSignatures("mock3") == std::nullopt);
EXPECT_TRUE(
Expand All @@ -96,7 +96,7 @@ TEST_F(RemoteFunctionRegistererTest, prefixes) {
exec::getVectorFunctionSignatures("json.mock_schema.mock3") ==
std::nullopt);

EXPECT_EQ(registerRemoteFunctions(path->path, {}), 1);
EXPECT_EQ(registerRemoteFunctions(path->getPath(), {}), 1);

EXPECT_TRUE(exec::getVectorFunctionSignatures("mock3") == std::nullopt);
EXPECT_TRUE(
Expand All @@ -105,7 +105,7 @@ TEST_F(RemoteFunctionRegistererTest, prefixes) {
exec::getVectorFunctionSignatures("json.mock_schema.mock3") ==
std::nullopt);

EXPECT_EQ(registerRemoteFunctions(path->path, {}, "json"), 1);
EXPECT_EQ(registerRemoteFunctions(path->getPath(), {}, "json"), 1);

EXPECT_TRUE(exec::getVectorFunctionSignatures("mock3") == std::nullopt);
EXPECT_TRUE(
Expand Down
Expand Up @@ -78,7 +78,7 @@ dwio::common::FileFormat toVeloxFileFormat(
return dwio::common::FileFormat::JSON;
}
} else if (format.inputFormat == "com.facebook.alpha.AlphaInputFormat") {
return dwio::common::FileFormat::ALPHA;
return dwio::common::FileFormat::NIMBLE;
}
VELOX_UNSUPPORTED(
"Unsupported file format: {} {}", format.inputFormat, format.serDe);
Expand Down Expand Up @@ -880,7 +880,7 @@ dwio::common::FileFormat toFileFormat(
case protocol::HiveStorageFormat::PARQUET:
return dwio::common::FileFormat::PARQUET;
case protocol::HiveStorageFormat::ALPHA:
return dwio::common::FileFormat::ALPHA;
return dwio::common::FileFormat::NIMBLE;
default:
VELOX_UNSUPPORTED(
"Unsupported file format in {}: {}.",
Expand Down Expand Up @@ -1468,4 +1468,4 @@ std::unique_ptr<protocol::ConnectorProtocol>
TpchPrestoToVeloxConnector::createConnectorProtocol() const {
return std::make_unique<protocol::TpchConnectorProtocol>();
}
} // namespace facebook::presto
} // namespace facebook::presto
2 changes: 1 addition & 1 deletion presto-native-execution/velox
Submodule velox updated 196 files

0 comments on commit 9a53624

Please sign in to comment.