-
Notifications
You must be signed in to change notification settings - Fork 65
[ML] Report the "actual" memory usage of the autodetect process #2846
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
base: main
Are you sure you want to change the base?
Conversation
Determine the actual memory usgae of the autodetect process as reported by the OS, e.g. on Linux this mould be the value of the maximum resident set size returned by a call to `getrusage`. Add this value to the model size stats record returned to the ES Java process so it can be included in the `job counts` tab for anomaly detection jobs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ed. I did the first pass.
We should discuss the naming of the new field. While "actual" conveys the intention of the value, it is confusing to the user.
Also, does maximum resident set size actually correspond to the actual current memory usage or is it the historical peak process memory usage?
include/model/CResourceMonitor.h
Outdated
@@ -180,6 +181,8 @@ class MODEL_EXPORT CResourceMonitor { | |||
//! Returns the sum of used memory plus any extra memory | |||
std::size_t totalMemory() const; | |||
|
|||
std::size_t actualMemoryUsage() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can come up with something better than actualMemoryUsage
. Maybe: systemMemoryUsage
?
The resident set size (RSS) represents the process's current RAM usage (so not counting pages that have been swapped out etc.), and the max RSS is the high water mark of that value. I think that reporting both would be useful for our purposes. |
* ActualMemory -> SystemMemory * Report current resident set size as well as max
include/model/ModelTypes.h
Outdated
E_AssignmentBasisSystemMemoryBytes = 4, //!< Use the current system memory size | ||
E_AssignmentBasisMaxSystemMemoryBytes = 5 //!< Use the highest ever system memory size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this assignment basis reasons (at least so far)
bin/autodetect/Main.cc
Outdated
ml::counter_t::E_TSADResidentSetSize, | ||
ml::counter_t::E_TSADMaxResidentSetSize}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call these counters SystemMemoryUsage
for consistency?
lib/model/ModelTypes.cc
Outdated
case E_AssignmentBasisSystemMemoryBytes: | ||
return "system_memory_bytes"; | ||
case E_AssignmentBasisMaxSystemMemoryBytes: | ||
return "max_system_memory_bytes"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those necessary?
Co-authored-by: Valeriy Khakhutskyy <[email protected]>
Co-authored-by: Valeriy Khakhutskyy <[email protected]>
Co-authored-by: Valeriy Khakhutskyy <[email protected]>
…mem_usage # Conflicts: # bin/autodetect/Main.cc # include/model/CResourceMonitor.h
|
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
* Address failing unit tests * More accurate, meaningful description of new program counters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I think the last piece that is missing now is that we use the system memory usage when in CResourceMemory
when calculating if allocations are allowed and that we report it back to Java as "model memory usage" and "peak model memory usage" instead of the estimated values on Linux.
… set size) for the "model memory usage" and "peak model memory usage" fields reported to Java.
buildkite run_qa_tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, this change is missing to update CResrouceMonitor::totalMemory()
. Please, correct me if I'm wrong, but the way I understand this code, totalMemory()
on Linux should now simply return systemMemoryUsage()
.
lib/model/CResourceMonitor.cc
Outdated
res.s_Usage = this->totalMemory(); | ||
res.s_AdjustedUsage = this->adjustedUsage(res.s_Usage); | ||
res.s_AdjustedUsage = systemMemoryUsage(this->adjustedUsage(res.s_Usage)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this complexity here. We can keep reporting adjusted usage the way we did before. But we need to update the value for s_Usage
. If you change the logic in totalMemory()
, you don't need to change anything here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments Valeriy.
What I was thinking was since s_AdjustedUsage
and s_AdjustedPeakUsage
are used as the values for the fields MODEL_BYTES and PEAK_MODEL_BYTES respectively -
ml-cpp/lib/api/CModelSizeStatsJsonWriter.cc
Lines 57 to 61 in c56874a
writer.onKey(MODEL_BYTES); | |
writer.onUint64(results.s_AdjustedUsage); | |
writer.onKey(PEAK_MODEL_BYTES); | |
writer.onUint64(results.s_AdjustedPeakUsage); |
systemMemoryUsage()
and left as-is elsewhere. In doing so I was trying to avoid "adjusting" the system memory usage as it should not be necessary to do so.
That said, I'll adjust the code as you suggest and see how the results look.
On Linux, use systemMemoryUsage for the value of totalMem. Do not "adjust" this value as is done for the estimated usage, as it is unnecessary.
|
Determine the actual memory usage of the autodetect process as reported by the OS, e.g. on Linux this would be the value of the maximum resident set size returned by a call to
getrusage
.Add this value to the model size stats record returned to the ES Java process so it can be included in the
job counts
tab for anomaly detection jobs.Relates elastic/elasticsearch#126256