cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Worker starvation on AMD EPYC k8s cluster

Open pdo400 opened this issue 5 years ago • 5 comments

I have had a strange thing happen to a CE 3.2.1 / 3.2.5 service. In one particular k8s cluster out of many where we run this service, it often failed to become ready within our boot timeout. This cluster is backed by large AMD epyc nodes, and our service is configured to see and use 216 cpus.

In researching the problem, it seemed that only 1 or 2 cores would be active during startup, during which many inputs are processed in parallel, with semaphores used to prevent duplicate work and memoize results as these calculations are very expensive in both memory and time.

At first we thought there must be something wrong with the environment, and while diagnosing the problem I ran a simple JVM app that started many threads that calculated fibonaccis just to determine if somehow processes were being thread throttled.

This program worked fine, so as another test I proceeded to run fibonacci calculations in our actual service... and lo and behold, for whatever reason, having even one IO fiber running these calculations somehow caused the boot fibers to run on other threads and use the available cores...

--

I confirmed that this behavior exists on both 3.2.1 and 3.2.5.

What we see is low core usage, implying that the fibers are not spreading out across the available threads, so the work eventually completes, but takes a very long time.

Why this only happens on this particular cluster, specifically of large AMD EPYC nodes is a mystery. On other clusters of what should be the same machine types, as well as on "standard" non-NUMA x64 machines, lots of cores are active and throughput is high. This cluster is on a different version of kubernetes than the working EPYC clusters, so there definitely could be environmental differences inside the container.

Or why staring a dummy recursive IO that just calculates fibonaccis seems to "unclog" the scheduler and fan out the work across cores as expected.

pdo400 avatar Sep 01 '21 22:09 pdo400

This behavior was witnessed on a recent openJDK 8.

Interestingly, in the course of investigating this I realized that calls to String.intern were quite slow, and removing them solves the issue...

Edit:

Oh, my.

Inside these fibers it seems a library we use was doing things with java ConcurrentMap s. These potential calls were removed along with the String.intern calls in the build that boots quickly without a dummy fibonacci fiber.

pdo400 avatar Sep 01 '21 23:09 pdo400

Sorry, I'm a bit confused, does removing the code that interracts with the ConcurrentMap and the String#intern calls cause the slow boot issue to go away?

vasilmkd avatar Sep 02 '21 06:09 vasilmkd

Looking at the thread dumps, I'm pretty sure this is an intern issue. There are about 20 workers busy in each, all stuck in intern.

djspiewak avatar Sep 02 '21 14:09 djspiewak

Removing the String#intern makes things boot fast, yes. But I am still puzzled as to why this cluster in particular is the only place we noticed this (something environmental making the intern calls extra slow?), and on the CE3 side, why starting the fibonacci fiber greatly increases throughput.

pdo400 avatar Sep 05 '21 00:09 pdo400