'Unusually high CPU stats while deploying service on AWS

I am deploying my yml files on AWS and using below snippet to calculate cpu utilization. To add context I have my service coded in go/python and I am using similar code snippet to do util calculation. NOTE: If running the below snippet from bash inside a container, please make sure tstart and tstop are in nanosec.

'''

tstart=$(date +%s%N)
cstart=$(cat /sys/fs/cgroup/cpu/$cgroup/cpuacct.usage)

sleep 5

tstop=$(date +%s%N)
cstop=$(cat /sys/fs/cgroup/cpu/$cgroup/cpuacct.usage)

bc -l <<EOF
($cstop - $cstart) / ($tstop - $tstart) * 100

'''

My deployment files have cpu resource request: 1 and limit: 2 (base images are alpine). I have tested this on k8s and Openshift clusters and I do get the correct cpu utilization values. However, on AWS I am seeing extremely high values ranges from 800-20000.

I would really appreciate if someone could help me understand what might be causing this.

I found these threads discussing something similar: https://github.com/kubernetes/kubernetes/issues/97445 https://engineering.indeedblog.com/blog/2019/12/unthrottled-fixing-cpu-limits-in-the-cloud/



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source