0

Small question regarding a Java 11 Spring Webflux 2.6.6+ web app, containerized and deployed using Kubernetes please.

From the web app application logs, I am seeing things such as:

INFO [service,1bcce5941c742568,22c0ab2133c63a77] 11 --- [or-http-epoll-2] a.b.c.SomeClass  : Some message from the reactive pipeline.
INFO [service,67cb40974712b3f4,15285d01bce9dfd5] 11 --- [or-http-epoll-4] a.b.c.SomeClass  : Some message from the reactive pipeline.
INFO [service,5011dc5e09de30b7,f58687695bda20f2] 11 --- [or-http-epoll-3] a.b.c.SomeClass  : Some message from the reactive pipeline.
INFO [service,8046bdde07b13261,5c30a56a4a603f4d] 11 --- [or-http-epoll-1] a.b.c.SomeClass  : Some message from the reactive pipeline.

And always, I can only see [or-http-epoll-1] [or-http-epoll-2] [or-http-epoll-3] [or-http-epoll-4] which I think stands for: [reactor-http-epoll-N]

The problem is, no matter how much CPU I allocate from Kubernetes, it is always those 4, no less, no more.

I tried:

  resources:
            requests:
              cpu: 1
              memory: 1G
            limits:
              cpu: 2
              memory: 2G

  resources:
            requests:
              cpu: 4
              memory: 4G
            limits:
              cpu: 6
              memory: 6G

  resources:
            requests:
              cpu: 10
              memory: 10G
            limits:
              cpu: 10
              memory: 10G

But again, always only those 4.

I am having a hard time understanding what is the problem here, and why am I stuck with only/always 4 "or-http-epoll-".

Thank you

PatPanda
  • 3,644
  • 9
  • 58
  • 154
  • Does this answer your question? [WebFlux - Reactor Http Epoll threads](https://stackoverflow.com/questions/63675128/webflux-reactor-http-epoll-threads) – Alex May 07 '22 at 22:30
  • I had a chance to look at the link. Especially the answer: "The number of default threads is dependent on the core count of the host system." This is why I am asking my question. I do configured different variation of number of core count, but still seeing the same – PatPanda May 07 '22 at 23:14

1 Answers1

1

By default WebFlux uses Netty as an underlining web server. Here is how Netty determine number of threads in the pool Netty - LoopResources

/**
* Default worker thread count, fallback to available processor
* (but with a minimum value of 4)
*/
int DEFAULT_IO_WORKER_COUNT = Integer.parseInt(System.getProperty(
    ReactorNetty.IO_WORKER_COUNT,
    "" + Math.max(Runtime.getRuntime().availableProcessors(), 4)));

The next question, what is the current Runtime.getRuntime().availableProcessors()?

It depends on Java version. Until Java version 10, application on Docker sees CPU on the machine and not inside the container.

You could create a simple Java application to validate

class TestCpu {
    public static void main(String[] args) {
       int processors = Runtime.getRuntime().availableProcessors();
       System.out.println("CPU cores: " + processors);
  }
}
Alex
  • 4,987
  • 1
  • 8
  • 26
  • This is indeed the correct answer. For some reason, this piece of code always shows the same number no mater how many CPU I allocate from Kubernetes side. I believe it is more of a Kubernetes issue rather than a Spring issue. Thanks you – PatPanda May 09 '22 at 12:28
  • what java version are you using for containers? – Alex May 09 '22 at 14:22
  • I am using a regular alpine java 11 as base image, and as for Kubernetes, using AKS – PatPanda May 09 '22 at 14:40