amazon-ecs-agent icon indicating copy to clipboard operation
amazon-ecs-agent copied to clipboard

Extra powerful CPU effort reported

Open workybee opened this issue 10 years ago • 15 comments

Our cloudwatch dashboard for the cluster metrics associated with our 4 instance cluster occassionally shows CPUUtilization of 10,236,791,673% (or other extremely high values I doubt are valid).

extracpu_anyone_2016-04-14

We have also been having some other issues with docker commands being slow (see #377), wondering if they might be related?

workybee avatar Apr 15 '16 21:04 workybee

@workybee Thanks for reporting this issue. We have been able to correlate this on our end as well and it seems like a bug in the ECS Agent. We will let you know if we need more details or when we have an update on this issue.

aaithal avatar Apr 22 '16 23:04 aaithal

Looks like the "fix" will prevent the bad reporting, but any idea why the toContainerStats is failing in first place? I see various instances in my 4 node cluster hitting 100% cpu at times, suspect a correlation with things being thrown off, but not sure.

workybee avatar May 03 '16 17:05 workybee

Looks like the "fix" will prevent the bad reporting, but any idea why the toContainerStats is failing in first place?

We sometimes see empty container stats from libcontainer.GetStats(), which impacted the computation in this particular case.

I see various instances in my 4 node cluster hitting 100% cpu at times, suspect a correlation with things being thrown off, but not sure.

Are you also seeing that instances' CPU utilization is not 100% when this happens?

aaithal avatar May 03 '16 17:05 aaithal

Not sure, and hard to tell from the cloudwatch graphs as when it gets a wild value all nearby stats get squashed to near zero. In general seems like one instance tends to get loaded hard than the other 3 for decent periods of time, but the load does seem to migrate occasionally. I have seen discrepancies between cluster-wide CPU usage and AMI CPU usage stats, which in my world should be "the same" but I figure that is a side effect of the sampling time differences.

workybee avatar May 03 '16 18:05 workybee

You got me motivated to look harder ;-) Found a way to see things a bit clearer, and indeed most cases seem to show non-100% CPU where the aggregate CPU is off the charts. Could be side effect of averaging? Don't have a recent enough case to see it un-averaged. Cloudwatch dashboard screenshot attached. extrapowerfullcpu_2016-05-02t1500

workybee avatar May 03 '16 18:05 workybee

@workybee Thanks for adding those :)

indeed most cases seem to show non-100% CPU where the aggregate CPU is off the charts. Could be side effect of averaging?

It does seem like that is a side-effect of the issue in question. That should be resolved once the fix goes out.

What I wanted to know with my earlier question was, if you were seeing a case where ECS Cluster metric reports that the CPU utilization in the cluster is 100%. But, if you look at individual instances' CPU utilization (from EC2 metrics), they don't add up.

aaithal avatar May 03 '16 18:05 aaithal

I'll try and catch an occurrence before averaging sets in. Using EC2 metrics directly (instead of the dashboard) was able to generate this screenshot that might not be averaged: extrapowerfullcpu_2016-05-02t1600p1800

I think it shows only one instance being near 100% CPU, and they definitely don't add up to the 1,573,935,043% that the aggregate metric shows (sorry, couldn't figure out how to capture that popup in my screenshot). The aggregate metric was 23% and 33% the 5 minutes before and after this spike respectively.

workybee avatar May 03 '16 19:05 workybee

I think it shows only one instance being near 100% CPU, and they definitely don't add up to the 1,573,935,043%

Right, and that should be resolved with the fix we submitted.

aaithal avatar May 03 '16 19:05 aaithal

Yes, I think I can see how the fix will at least mask this error from surfacing, but does it address the root cause? (And would it matter or is this purely about metrics and wouldn't effect my containers on the instances? Haven't seen issue #377 in the last week since upgrading to 2016.03.a but seemed potentially related, and deeper than just the metrics.)

workybee avatar May 03 '16 19:05 workybee

As I mentioned earlier, the root cause is ECS Agent's stats engine getting empty container stats from libcontainer.GetStats(). We submit a metric message to our backend approximately every 20 seconds. Each such message is computed by aggregating 40 * 500 millisecond samples. Dropping a faulty sample only means that, on rare occasions when we get an empty stats object from libcontainer, the sample count deteriorates by count of 1. That is, instead of 40 samples contributing to a metric, 39 samples contribute to it. So, it doesn't lead to miscalculation of metrics, only to a reduction in the sample count while computing the metric. I hope this addresses your concern about any effect it has on the metric computed for your cluster/container instances.

aaithal avatar May 03 '16 19:05 aaithal

Yes, this addresses any concerns I had about metrics nicely, thank you. Leaves me with a (very small) concern about why libcontianer.GetStats() is occasionally failing. Looking at that code seems like it could be network exhaustion error, which if it stays rare is of very little concern. Any way to get a sense of how frequently it might be happening? Maybe should keep the old mega-percent-CPUUsage behaviro as a proxy for this. ;-) I've had a few containers hang "forever" (hours, when they should take minutes to finish in worst case) and am wondering if they could be hitting some network glitch as well?

workybee avatar May 03 '16 22:05 workybee

In my test setup, where I have a 3 instance cluster, I have seen it happen 4 times in 14 days (sample count of 14 * 24 * 60 * 60 * 2 * 3 = 7257600), which means it has happened once every 1814400 samples (equivalent 1 instance, 21 days worth of samples). I am not sure why libcontainer returns empty stats in this scenario. Another thing to note is that the ECS Agent does not use the docker stats interface and moving to that interface would get rid of that altogether.

Looking at that code seems like it could be network exhaustion error, I've had a few containers hang "forever" (hours, when they should take minutes to finish in worst case) and am wondering if they could be hitting some network glitch as well?

I am not sure what's going on there. But, feel free to open a new issue for that, hopefully with docker and ECS Agent logs.

aaithal avatar May 03 '16 22:05 aaithal

Will do if I can make it into something at all cohesive. Thanks for all your help and the detailed explanations.

workybee avatar May 03 '16 22:05 workybee

@workybee Thanks for reporting this bug. We've resolved this with the 1.9.0 release.

samuelkarp avatar May 06 '16 21:05 samuelkarp

Thanks for the fix. Already deployed ecs-agent v1.9.0 and seems to be working fine (though problems were rare, so I'm being trusting ;-)

workybee avatar May 06 '16 22:05 workybee