title: How to properly downscale a spark cluster using dynamic allocation?
body: <p>I am running spark on k8s using the spark k8s operator. I want to run a spark streaming application which auto scales.
  I have figured out how to slowly scale up the cluster using</p>
  <pre><code>    &quot;spark.dynamicAllocation.executorAllocationRatio&quot;: &quot;0.1&quot;
      &quot;spark.dynamicAllocation.schedulerBacklogTimeout&quot;: &quot;20&quot;
  </code></pre>
  <p>The cluster scales up correctly when resources are needed but does not downscale.</p>
  <p>According to the official <a href="https://spark.apache.org/docs/3.2.1/job-scheduling.html#remove-policy" rel="nofollow noreferrer">docs</a></p>
  <blockquote>
  <p>A Spark application removes an executor when it has been idle for more than spark.dynamicAllocation.executorIdleTimeout seconds</p>
  </blockquote>
  <p>Since I'm running a streaming application, this condition is almost never true (the executorIdleTimeout would have to be &lt; 1 second). The only way my cluster down scales is if any of the executor gets OOMKilled.</p>
  <p>Is there any proper way to downscale the cluster? Like killing executors based on the average CPU used? Or is there any way to give priority to an executor instead of distributing tasks over all the available executors?</p>