Skip to content

[ML] Limit categorization memory usage#1167

Merged
droberts195 merged 3 commits intoelastic:masterfrom
droberts195:categorization_memory_limiting
Apr 28, 2020
Merged

[ML] Limit categorization memory usage#1167
droberts195 merged 3 commits intoelastic:masterfrom
droberts195:categorization_memory_limiting

Conversation

@droberts195
Copy link
Copy Markdown

Anomaly detection jobs have a model_memory_limit setting. This is
supposed to restrict the amount of memory the job can use, however,
in the past the limit only applied to anomaly detection and not to
categorization.

This change applies memory limiting to categorization as follows:

  • When a job is in hard_limit status no new categories will be
    created. The input document that could not be categorized is
    discarded as it cannot take part in anomaly detection without a
    category. The failed_category_count statistic is incremented
    each time this happens.
  • When a job is in soft_limit status, we stop recording examples
    for the category.

Fixes #1130

Anomaly detection jobs have a model_memory_limit setting.  This is
supposed to restrict the amount of memory the job can use, however,
in the past the limit only applied to anomaly detection and not to
categorization.

This change applies memory limiting to categorization as follows:

- When a job is in hard_limit status no new categories will be
  created.  The input document that could not be categorized is
  discarded as it cannot take part in anomaly detection without a
  category.  The failed_category_count statistic is incremented
  each time this happens.
- When a job is in soft_limit status, we stop recording examples
  for the category.

Fixes elastic#1130
@droberts195
Copy link
Copy Markdown
Author

retest

Copy link
Copy Markdown
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

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

This basically looks good. I have one question regarding difference in the way you're testing if allocations are allow.

m_NumRecordsHandled{0}, m_OutputFieldCategory{m_Overrides[MLCATEGORY_NAME]},
m_MaxMatchingLength{0}, m_JsonOutputWriter{jsonOutputWriter},
m_CategorizationFieldName{config.categorizationFieldName()},
m_CategorizationFilter{}, m_PersistenceManager{persistenceManager} {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: there doesn't seem to be any need to default initialise m_CategorizationFilter here. Also, how about initialising builtin types m_NumRecordsHandled, etc in the class body?

//! A soft categorization failure means downstream components can continue,
//! by considering the input record to be in some "uncategorizable"
//! category.
static const int SOFT_CATEGORIZATION_FAILURE_ERROR;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good idea!


bool CDataCategorizer::addExample(int categoryId, const std::string& example) {
// Don't add examples if we're memory-limited
if (m_Limits.resourceMonitor().getMemoryStatus() != model_t::E_MemoryStatusOk) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any reason not to use this->areNewCategoriesAllowed() here? I couldn't think of one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

areNewCategoriesAllowed() returns false when the job is in hard_limit. But we stop adding examples as soon as the job goes to soft_limit. It's in the spec for memory limiting in #1130 and the PR description, but I will expand the comment in the code to say this.

Copy link
Copy Markdown
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

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

LGTM

@droberts195 droberts195 merged commit 1767622 into elastic:master Apr 28, 2020
@droberts195 droberts195 deleted the categorization_memory_limiting branch April 28, 2020 12:37
droberts195 added a commit to droberts195/ml-cpp that referenced this pull request Apr 28, 2020
Anomaly detection jobs have a model_memory_limit setting.  This is
supposed to restrict the amount of memory the job can use, however,
in the past the limit only applied to anomaly detection and not to
categorization.

This change applies memory limiting to categorization as follows:

- When a job is in hard_limit status no new categories will be
  created.  The input document that could not be categorized is
  discarded as it cannot take part in anomaly detection without a
  category.  The failed_category_count statistic is incremented
  each time this happens.
- When a job is in soft_limit status, we stop recording examples
  for the category.

Backport of elastic#1167
droberts195 added a commit that referenced this pull request Apr 28, 2020
Anomaly detection jobs have a model_memory_limit setting.  This is
supposed to restrict the amount of memory the job can use, however,
in the past the limit only applied to anomaly detection and not to
categorization.

This change applies memory limiting to categorization as follows:

- When a job is in hard_limit status no new categories will be
  created.  The input document that could not be categorized is
  discarded as it cannot take part in anomaly detection without a
  category.  The failed_category_count statistic is incremented
  each time this happens.
- When a job is in soft_limit status, we stop recording examples
  for the category.

Backport of #1167
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ML] Categorization should take notice of hard_limit memory status

2 participants