[role="xpack"]
[testenv="enterprise"]
[[autoscaling-machine-learning-decider]]
=== Machine learning decider

The {ml} decider (`ml`) calculates the memory required to run {ml} jobs.

The {ml} decider is enabled for policies governing `ml` nodes.

NOTE: For {ml} jobs to open when the cluster is not appropriately
scaled, set `xpack.ml.max_lazy_ml_nodes` to the largest number of possible {ml} 
jobs (refer to <<advanced-ml-settings>> for more information). In {ess}, this is 
automatically set.

[[autoscaling-machine-learning-decider-settings]]
==== Configuration settings

Both `num_anomaly_jobs_in_queue` and `num_analytics_jobs_in_queue` are designed 
to delay a scale-up event. If the cluster is too small, these settings indicate how many jobs of each type can be 
unassigned from a node. Both settings are 
only considered for jobs that can be opened given the current scale. If a job is 
too large for any node size or if a job can't be assigned without user 
intervention (for example, a user calling `_stop` against a real-time 
{anomaly-job}), the numbers are ignored for that particular job.

`num_anomaly_jobs_in_queue`::
(Optional, integer)
Specifies the number of queued {anomaly-jobs} to allow. Defaults to `0`.

`num_analytics_jobs_in_queue`::
(Optional, integer)
Specifies the number of queued {dfanalytics-jobs} to allow. Defaults to `0`.

`down_scale_delay`::
(Optional, <<time-units,time value>>)
Specifies the time to delay before scaling down. Defaults to 1 hour. If a scale 
down is possible for the entire time window, then a scale down is requested. If 
the cluster requires a scale up during the window, the window is reset.


[[autoscaling-machine-learning-decider-examples]]
==== {api-examples-title}

This example creates an autoscaling policy named `my_autoscaling_policy` that 
overrides the default configuration of the {ml} decider.

[source,console]
--------------------------------------------------
PUT /_autoscaling/policy/my_autoscaling_policy
{
  "roles" : [ "ml" ],
  "deciders": {
    "ml": {
      "num_anomaly_jobs_in_queue": 5,
      "num_analytics_jobs_in_queue": 3,
      "down_scale_delay": "30m"
    }
  }
}
--------------------------------------------------
// TEST


The API returns the following result:

[source,console-result]
--------------------------------------------------
{
  "acknowledged": true
}
--------------------------------------------------


//////////////////////////

[source,console]
--------------------------------------------------
DELETE /_autoscaling/policy/my_autoscaling_policy
--------------------------------------------------
// TEST[continued]

//////////////////////////
