# Handling Long running request during HPA Scale-down

**URL:** <https://discuss.kubernetes.io/t/handling-long-running-request-during-hpa-scale-down/20554>\
**Category:** General Discussions\
**Created:** [July 7, 2022, 9:16am UTC](https://discuss.kubernetes.io/t/handling-long-running-request-during-hpa-scale-down/20554 "2022-07-07T09:16:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoorva\_kamath](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/apoorva_kamath/32/10180_2.png) [@apoorva\_kamath](https://discuss.kubernetes.io/u/apoorva_kamath)\
**Post date:** [July 7, 2022, 9:16am UTC](https://discuss.kubernetes.io/t/handling-long-running-request-during-hpa-scale-down/20554/1 "2022-07-07T09:16:41Z")

</div>

I am exploring HPA using custom pod metrics.  
HPA is able to scale-up and scale-down based on metrics exposed by the application.

During the scale-down triggered by HPA, the pods are terminated randomly is metrics falls below the average targetvalue.

How are long-running requests handled in the field during the scale-down?

I know there exists prestop and terminationGracePeriodSeconds, but these are values that are pre-defined.  
If the long-running request exceeds the terminationGracePeriodSeconds the request gets terminated, this is what I am trying to avoid.

Is there a way for HPA to scale-down based on a different counter, something like active connections. Only when active connections reach 0, the pod is deleted.

I did find custom pod autoscaler operator [custom-pod-autoscaler/example at master · jthomperoo/custom-pod-autoscaler · GitHub](https://github.com/jthomperoo/custom-pod-autoscaler/tree/master/example), not really sure if I can achieve my use case with this.

Any help/direction is highly appreciated.

---

<div class="post-metadata">

**Author:** ![eperaza](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/eperaza/32/16167_2.png) [@eperaza](https://discuss.kubernetes.io/u/eperaza)\
**Post date:** [October 31, 2024, 4:02am UTC](https://discuss.kubernetes.io/t/handling-long-running-request-during-hpa-scale-down/20554/2 "2024-10-31T04:02:15Z")

</div>

I have the same problem… did you find a solution?

---

<div class="post-metadata">

**Author:** ![fox-md](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/fox-md/32/10613_2.png) [@fox-md](https://discuss.kubernetes.io/u/fox-md)\
**Post date:** [October 31, 2024, 10:26am UTC](https://discuss.kubernetes.io/t/handling-long-running-request-during-hpa-scale-down/20554/3 "2024-10-31T10:26:17Z")

</div>

Hi,  
Have a look at [https://keda.sh/](https://keda.sh/). It might be what you are looking for.  
HTH
