Skip to content

[ML] Round up data frame analytics memory estimates to next MB #1126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
* Reduce CPU scheduling priority of native analysis processes to favor the ES JVM
when CPU is constrained. (See {ml-pull}1109[#1109].)
* Take `training_percent` into account when estimating memory usage for classification and regression.
(See {ml-pull}1111[1111].)
(See {ml-pull}1111[#1111].)
* Support maximize minimum recall when assigning class labels for multiclass classification.
(See {ml-pull}1113[#1113].)
* Improve robustness of anomaly detection to bad input data. (See {ml-pull}1114[#1114].)
* Adds new `num_matches` and `preferred_to_categories` fields to category output.
(See {ml-pull}1062[#1062])
(See {ml-pull}1062[#1062].)
* Switched data frame analytics model memory estimates from kilobytes to megabytes.
(See {ml-pull}1126[#1126], issue: {issue}54506[#54506].)

== {es} version 7.7.0

Expand Down
12 changes: 7 additions & 5 deletions lib/api/CDataFrameAnalysisRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ std::size_t maximumNumberPartitions(const CDataFrameAnalysisSpecification& spec)
// user to allocate more resources for the job in this case.
return static_cast<std::size_t>(std::sqrt(static_cast<double>(spec.numberRows())) + 0.5);
}

const std::size_t BYTES_IN_MB{1024 * 1024};
}

CDataFrameAnalysisRunner::CDataFrameAnalysisRunner(const CDataFrameAnalysisSpecification& spec)
Expand All @@ -54,11 +56,11 @@ void CDataFrameAnalysisRunner::estimateMemoryUsage(CMemoryUsageEstimationResultJ
this->estimateMemoryUsage(numberRows, numberRows, numberColumns)};
std::size_t expectedMemoryWithDisk{this->estimateMemoryUsage(
numberRows, numberRows / maxNumberPartitions, numberColumns)};
auto roundUpToNearestKilobyte = [](std::size_t bytes) {
return std::to_string((bytes + 1024 - 1) / 1024) + "kB";
auto roundUpToNearestMb = [](std::size_t bytes) {
return std::to_string((bytes + BYTES_IN_MB - 1) / BYTES_IN_MB) + "mb";
};
writer.write(roundUpToNearestKilobyte(expectedMemoryWithoutDisk),
roundUpToNearestKilobyte(expectedMemoryWithDisk));
writer.write(roundUpToNearestMb(expectedMemoryWithoutDisk),
roundUpToNearestMb(expectedMemoryWithDisk));
}

void CDataFrameAnalysisRunner::computeAndSaveExecutionStrategy() {
Expand Down Expand Up @@ -95,7 +97,7 @@ void CDataFrameAnalysisRunner::computeAndSaveExecutionStrategy() {

if (memoryUsage > memoryLimit) {
auto roundMb = [](std::size_t memory) {
return 0.01 * static_cast<double>((100 * memory) / (1024 * 1024));
return 0.01 * static_cast<double>((100 * memory) / BYTES_IN_MB);
};

// Report rounded up to the nearest MB.
Expand Down
14 changes: 7 additions & 7 deletions lib/api/unittest/CDataFrameAnalysisRunnerTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor0Rows) {
}

BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor1Row) {
testEstimateMemoryUsage(1, "4kB", "4kB", 0);
testEstimateMemoryUsage(1, "1mb", "1mb", 0);
}

BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor10Rows) {
testEstimateMemoryUsage(10, "12kB", "10kB", 0);
BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor10000Rows) {
testEstimateMemoryUsage(10000, "5mb", "2mb", 0);
}

BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor100Rows) {
testEstimateMemoryUsage(100, "57kB", "35kB", 0);
BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor100000Rows) {
testEstimateMemoryUsage(100000, "40mb", "9mb", 0);
}

BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor1000Rows) {
testEstimateMemoryUsage(1000, "403kB", "142kB", 0);
BOOST_AUTO_TEST_CASE(testEstimateMemoryUsageFor1000000Rows) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Test name is off by one 0

testEstimateMemoryUsage(10000000, "4511mb", "88mb", 0);
}

BOOST_AUTO_TEST_SUITE_END()
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(testWrite) {
{
core::CJsonOutputStreamWrapper wrappedOutStream(sstream);
CMemoryUsageEstimationResultJsonWriter writer(wrappedOutStream);
writer.write("16kB", "8kB");
writer.write("16mb", "8mb");
}

rapidjson::Document arrayDoc;
Expand All @@ -42,10 +42,10 @@ BOOST_AUTO_TEST_CASE(testWrite) {
BOOST_TEST_REQUIRE(object.IsObject());

BOOST_TEST_REQUIRE(object.HasMember("expected_memory_without_disk"));
BOOST_REQUIRE_EQUAL(std::string("16kB"),
BOOST_REQUIRE_EQUAL(std::string("16mb"),
std::string(object["expected_memory_without_disk"].GetString()));
BOOST_TEST_REQUIRE(object.HasMember("expected_memory_with_disk"));
BOOST_REQUIRE_EQUAL(std::string("8kB"),
BOOST_REQUIRE_EQUAL(std::string("8mb"),
std::string(object["expected_memory_with_disk"].GetString()));
}

Expand Down