AWS ECS内存利用率过高问题排查及处理
1. 问题: 由于服务长时间没有新的发布,ECS服务的内存利用率,飙升到90%,并长时间维持,收到相关服务报警。
2. 问题排查过程
2. 1 通过下面ECS 内存详情截图可知,这里的内存利用率过高,并不是所有的host的内存利用率都这么高,而是最大内存利用率的服务器达到90%,其他服务器并不存在这个问题。
2.2 下图是内存的具体是用情况,其中HeapMemoryUse接近60%, 但HeapMemoryAfterGCUse不到10%(Q1中介绍两者的差别),也就是说大部分是无用的object没有被GC回收,所以为避免影响大促,决定采取保守策略,保持观察。
2. 3 大促期间,未见异常,但长期存在对服务风险,故考虑解决问题,再check ECS中的task发现6个task中有两个task的创建时常超过内存出问题的时间,故必定是其中一个内存出现问题

2.4 解决方案是需要重启相关的Task,操作之前需要先评估下剩余task是否能承担相关的流量,避免对线上服务产生负面影响,评估发现只要三个task就足够承担整个服务,只是因为内存利用率过高,导致ECS自动扩容,大部分资源都是不必要的,所以可以安全关闭task。
2.5 由于这是一种尝试性操作,所以我考虑先手动重启时间最长的一台host,先观察下内存情况,发现,最大内存利用率并没有下降,但平均利用率下降了,这说明当前关闭的host并不是内存利用率最大的host,我也并未急于关闭第二台host,而是考虑多观察了一段时间


2.6 等一段时间之后,有意思的事情发生了,内存利用率自己降低到合理范围内了

2.7 check ECS的task发现是由于ECS在做缩容操作,将创建比较久的task关闭掉了,最终只保留了3个task,此时,问题得以解决。
3. Root Cause/Resolution
The root cause was identified as high memory usage on some older tasks, potentially due to the presence of dead objects that were not being collected by the garbage collector (GC). The resolution involved stopping and replacing the older tasks with high memory usage, allowing the cluster to scale down and operate within normal memory utilization levels.
推断是ECS的某些bug导致高内存利用率的host内存无法回收,也无法做host替换,导致ECS一直扩容,通过手动重启其中一台host之后,ECS处理流程恢复正常,并自动缩容,解决相关问题。
Q1: The difference between HeapMemoryUse and HeapMemoryAfterGCUse
A from AZA: The key difference between HeapMemoryUse and HeapMemoryAfterGCUse is that HeapMemoryUse measures the instantaneous heap occupancy, including both live and dead objects, while HeapMemoryAfterGCUse measures the live object heap occupancy over the long term.
HeapMemoryAfterGCUse consists of the used memory space from the survivor spaces and old generation space after a garbage collection (GC) run, while HeapMemoryUse includes the eden space which is filled and then completely emptied by young collections, effectively containing only dead objects on a long-term basis.
Therefore, the two metrics are not directly comparable, as HeapMemoryAfterGCUse provides a more accurate representation of the long-term live object heap occupancy.
更多推荐


所有评论(0)