This paper introduces DEBI-HPA, an adaptive container auto-scaling method for cloud services that integrates Bi-directional Long Short-Term Memory (BiLSTM), extreme value theory, and dynamic utilization ratios. DEBI-HPA dynamically adjusts the number of Pods based on workload changes, accurately estimates extreme load levels, and adaptively sets target utilization ratios, thereby enhancing service quality, resource utilization, and cost efficiency. It employs predictive scaling during low-load periods to anticipate growth and reactive scaling under high loads to ensure efficient resource allocation. Experimental results demonstrate that DEBI-HPA outperforms Kubernetes' native Horizontal Pod Autoscaler (HPA) by increasing resource utilization by up to 30% and reducing costs by up to 47%. Compared to other predictive scaling methods like ARIMA-HPA and LSTM-HPA, DEBI-HPA improves resource utilization by approximately 18% and lowers costs by about 37%. Additionally, DEBI-HPA achieves effective scaling with common prediction models, reducing dependency on model accuracy. This method offers a novel and robust solution for container auto-scaling in cloud environments.
针对上述问题,本文提出了一种融合双向长短期记忆网络(Bidirectional long short-term memory, BiLSTM)、极值理论(Extreme value theory, EVT)与动态目标利用率策略的自适应扩缩容优化算法。该算法(EVT-BiLSTM-HPA)在负载低时利用BiLSTM进行负载预测,提前扩容应对未来增长趋势,提高服务可靠性;在负载已处于极高水平时则采用响应式扩缩容策略,通过极值理论降低继续大幅增长的概率,避免不必要的资源浪费。
在 Kubernetes 中,Metrics Server 持续采集所有 Pod 副本的指标数据,并通过聚合 API(如 metrics.k8s.io、custom.metrics.k8s.io)为 HPA 控制器提供查询服务[19]。HPA 控制器根据用户定义的扩缩容规则,使用式(1)计算目标 Pod 副本数量:
在此基础上,DEBI-HPA 引入动态目标利用率调整算法,解决无法根据 Pod 实际运行情况和历史数据自动调整目标利用率的问题。在负载低谷阶段降低目标利用率,留出缓冲空间以减少负载上升时引发的 SLA 违约;在负载高峰且增长空间有限的情况下,提高目标利用率,提升整体资源利用率并降低成本。
DEBI-HPA 的整体流程如图6所示。系统首先从 Metrics Server 中采集当前 Pod 集合的平均 CPU 利用率负载;接着通过 BiLSTM 预测模型获取当前时刻的预测负载;随后利用极值理论算法计算超高位负载。综合、与得到最终负载,并基于此由动态目标利用率算法对 Pod 副本数进行自适应调整。
传统的固定目标利用率方法难以适应不同业务负载变化,可能导致服务质量下降或资源浪费。例如,当负载较低且稳定时,固定目标利用率可能导致 Pod 实例过多,资源利用率低下,成本增加;而在负载较高且不稳定时,固定目标利用率可能无法及时调整 Pod 数量,导致服务性能下降,引起SLA违反的可能性。为此,本文提出动态目标利用率方法:
自适应弹性扩缩容策略的整体流程包括:从 Metrics Server 采集集群当前 Pod 集合的平均 CPU 利用率负载;负载预测模块提供当前时刻预测的平均 CPU 利用率负载;超高位负载计算模块利用极值理论算法计算超高位负载;综合三个负载值,通过式(16)计算最终负载:
用户需设定基本参数:Pod 的资源请求量、Pod 的最大副本数与最小副本数、目标利用率的上限和下限。这些参数基于流量、应用性能和成本考虑,最大副本数和最小副本数分别对应最高和最低资源消耗;资源请求量决定单个 Pod 的合理资源分配;目标利用率的上限和下限确保在不同负载下 Pod 的处理能力,防止性能瓶颈导致SLA违反。动态目标利用率的设定如下:当Pod副本数=时,设定目标利用率为下限。
固定负载缓冲空间:
计算目标利用率:
整体算法框架见算法2。
算法2 动态目标利用率Pod副本数推荐值计算
输入:
输出:下一个时刻的扩缩容副本数推荐值
1.
2. if then
3. return
4. end if
5.
6. if then
7. return
8. end if
9.
10.
11.
12. for n in range,) do
13.
14.
15. if then
16.
17.
18. end if
19. end for
20. if then
21. return
22. end if
23. return
为防止 Pod 频繁变化导致服务质量下降,采用滑动窗口方法。根据前 5 min的真实负载平均利用率,计算动态目标利用率算法推荐的副本数,并与当前推荐副本数比较,选择较大者作为最终副本数。
此外,与其他策略相比,采用动态目标利用率的 HPA 算法在 Pod 数变化方面更为平稳,减少了频繁扩缩容带来的服务不稳定和容器启动、删除的额外成本。即使在频繁波动且无明显周期性的负载场景下,DEBI-HPA 仍能展现出良好的平稳性和适应性。
由图16可以看出提出的DEBI-HPA算法相比于原生HPA来说,不仅能提前预测未来的负载变化,防止由于滞后性和震荡性,导致服务延迟或资源浪费的现象,而且能根据 Pod 的实际运行情况和历史数据来自动调整目标利用率,提高资源利用率,降低成本。由表5可知,该算法相比原生HPA策略在周期性负载情况下资源利用率提升约30.79%,资源使用成本降低约47.00%。由表6可知,在平缓负载情况下,该算法相比原生HPA策略资源利用率提升约21.67%,资源使用成本降低约41.30%;由表7可知,在波动频繁且无明显周期性负载情况下,该算法相比于原生HPA策略资源利用率提升约18.6%,资源使用成本降低约36.15%;而相比于其他常见的扩缩容优化算法,该算法也能将资源利用率提升约18%,资源使用成本降低约37%。
本文针对目前HPA响应式的扩缩容,提出了一种自适应性的预测式弹性扩缩容方法,即在负载不高时采用预测式扩缩容来应对未来可能持续增长的负载,而在负载已经处于极高的情况下,采用响应式的扩缩容,因为此时负载持续增加的可能性已经极低,并且在极高负载的情况下也会有数目较多Pod来均摊增长不大的负载增量,这样既维护了应用服务的质量,也最大限度地节省了资源。在自适应预测式弹性扩缩容方法基础上创新性设计并实现了基于动态目标利用率横向容器自动扩缩容方法。Pod在副本较少时降低目标利用率以维持足够的缓冲空间,从而减少出现服务质量问题的可能性;在副本较多时提高目标利用率,从而减少了整体资源的占用并提高了资源利用率。本文提出的DEBI-HPA算法相比于原生HPA来说,不仅能提前预测未来的负载变化,防止由于滞后性和震荡性,导致服务延迟或资源浪费,而且能根据 Pod 的实际运行情况和历史数据来自动调整目标利用率,同时在不同类型负载情况下资源利用率最高提升约30%,资源使用成本最高降低约47%,而相比于其他常见的扩缩容优化算法,该算法也能将资源利用率提升约18%,资源使用成本降低约37%。而针对目前研究中的预测模型训练时间长、训练成本高,且难以自适应复杂生产环境的问题,本文算法仅使用常见的预测模型BiLSTM也能达到比较好的扩缩容效果,降低了对预测模型的依赖性,为弹性扩缩容研究提供了一种新思路。目前,本文研究重点关注提高资源利用率和降低资源使用成本。在未来,可以对服务质量保证方法做进一步深入优化,并且动态目标利用率上下限仍需要人工设置,未来可在自动化设定目标利用率上下限上做进一步研究并优化动态目标利用率算法。
CommunityKubernetes. kubernetes horizontal pod autoscaler[EB/OL]. [2024-05-06].
[2]
Google Kubernetes Engine. Google kubernetes engine vertical pod autoscaler [EB/OL]. [2024-05-06].
[3]
Google Kubernetes Engine. Google kubernetes engine multidimensional pod autoscaler[EB/OL]. [2024-05-06].
[4]
AL-HAIDARIF, SqalliM, SalahK. Impact of cpu utilization thresholds and scaling size on autoscaling cloud resources[C]∥IEEE 5th International Conference on Cloud Computing Technology and Science. IEEE, 2013, 2: 256-261.
[5]
IqbalW, DaileyM, CarreraD. SLA-driven adaptive resource management for web applications on a heterogeneous compute cloud[C]∥IEEE International Conference on Cloud Computing. Springer, Berlin, Heidelberg, 2009: 243-253.
[6]
LimH C, BabuS, ChaseJ S, et al. Automated control in cloud computing: challenges and opportunities[C]∥Proceedings of the 1st workshop on Automated control for datacenters and clouds, 2009: 13-18.
[7]
LimH C, BabuS, ChaseJ S. Automated control for elastic storage[C]∥Proceedings of the 7th international conference on Autonomic computing, New York: ACM, 2010: 1-10.
[8]
HasanM Z, MaganaE, ClemmA, et al. Integrated and autonomic cloud resource scaling[C]∥IEEE network operations and management symposium. Piscataway: IEEE, , 2012: 1327-1334.
[9]
BaresiL, GuineaS, LevaA, et al. A discrete-time feedback controller for containerized cloud applications[C]∥Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering.New York, NY: ACM Press, 2016: 217-228.
NiHai-feng. Design and implementation of container autoscaling algorithm platform based on Kubernetes [D].Shanghai: School of Electronic Information and Electrical Engineering, Shanghai Jiao Tong University, 2018.
TianYe. Study on auto scaling framework for container in cloud computing[D]. Shanghai: School of Electronic Information and Electrical Engineering,Shanghai Jiao Tong University, 2018.
ZhangSong-ling. Research on flexible scaling strategy of container resources based on Kubernetes[D]. Taiyuan: College of Electrical and Power Engineering, Taiyuan University of Technology, 2020.
LuoLiang-jie. Research on container elastic scaling technology based on load prediction [D]. Wuhan: School of Computer Science and Artificial Intelligence, Wuhan Textile University, 2021.
ImdoukhM, AhmadI, AlfailakawiM G. Machine learning-based auto-scaling for containerized applications[J]. Neural Computing and Applications, 2020, 32(13): 9745-9760.
[20]
BarrettE, HowleyE, DugganJ. Applying reinforcement learning towards automating resource allocation and application scalability in the cloud[J]. Concurrency and Computation: Practice and Experience, 2013, 25(12): 1656-1674.
[21]
TesauroG, JongN K, DasR, et al. A hybrid reinforcement learning approach to autonomic resource allocation[C]∥IEEE International Conference on Autonomic Computing. Piscataway: IEEE, 2006: 65-73.
[22]
RaoJ, BuX P, XuC Z, et al. Vconf: a reinforcement learning approach to virtual machines auto-configuration[C]∥Proceedings of the 6th international conference on Autonomic computing. New York: ACM, 2009: 137-146.
[23]
张磊. 深入剖析Kubernetes[M].北京:人民邮电出版社, 2021.
[24]
TaherizadehS, GrobelnikM. Key influencing factors of the Kubernetes auto-scaler for computing-intensive microservice-native cloud-based applications[J]. Advances in Engineering Software, 2020, 140: 102734.
LiZhi-bing, XiaoJian-mei, WangXi-huai. Transient stability assessment of power system based on multi-granularity neighborhood rough set and improved bi-directional long-short-term memory network [J]. Journal of Electrical Engineering, 2023, 18(3): 232-241.
[31]
HochreiterS, SchmidhuberJ. LSTM can solve hard long time lag problems[J]. Advances in neural information processing systems, 1996,9(8), 1735-1780.
[32]
FréchetM. Sur la loi de probabilité de l'écart maximum[J]. Annales Societatis Mathematicae Polonae, 1927, 6(1): 93-116.
GaoYu. Research on methods of anomaly detection and resource estimation for big data systems [D]. Harbin: School of Computer Science and Technology, Harbin Institute of Technology, 2020.
[36]
ColesS, BawaJ, TrennerL, et al. An Introduction to Statistical Modeling of Extreme Values[M]. Springer, 2001, 208.
[37]
GuoJ, ChangZ H, WangS, et al. Who limits the resource efficiency of my datacenter: an analysis of alibaba datacenter traces[C]∥Proceedings of the International Symposium on Quality of Service, 2019: 1-10.
[38]
PickandsIII J. Statistical inference using extreme order statistics[J]. the Annals of Statistics, 1975, 1(1): 119-131.
[39]
GrimshawS D. Computing maximum likelihood estimates for the generalized Pareto distribution[J]. Technometrics, 1993, 35(2): 185-191.
JananeeM, NimalaK. Allocation of cloud resources based on prediction and performing auto-scaling of workload[C]∥International Conference on Artificial Intelligence and Knowledge Discovery in Concurrent Engineering. Chennai, India: IEEE, 2023: 1-7.