Home > Software engineering >  Java Spring Webflux on Kubernetes: always [or-http-epoll-1], [or-http-epoll-2], [or-http-epoll-3], [
Java Spring Webflux on Kubernetes: always [or-http-epoll-1], [or-http-epoll-2], [or-http-epoll-3], [

Time:05-10

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

CodePudding user response:

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);
  }
}
  • Related