代码之家  ›  专栏  ›  技术社区  ›  PatPanda

Kubernetes上的Java Spring Webflux:always[or-http-epoll-1]、[or-http-epoll-2]、[or-http-epoll-3]、[or-http-epoll-4],尽管配置了资源

  •  0
  • PatPanda  · 技术社区  · 4 年前

    关于Java 11 Spring Webflux 2.6.6+web应用程序的小问题,请使用Kubernetes进行容器化和部署。

    从web应用程序日志中,我看到了以下情况:

    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.
    

    我总是只能看到 [or-http-epoll-1] [or-http-epoll-2] [or-http-epoll-3] [or-http-epoll-4] 我认为这代表: [reactor-http-epoll-N]

    问题是,无论我从Kubernetes分配多少CPU,它总是这4个,不更少,不更多。

    我试过:

      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
    
    

    但是,总是只有这4个。

    我很难理解这里的问题是什么,为什么我只能/总是使用4“或http epoll-”。

    非常感谢。

    0 回复  |  直到 4 年前
        1
  •  1
  •   Alex    4 年前

    默认情况下,WebFlux使用Netty作为底层web服务器。下面是Netty如何确定池中的线程数 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)));
    

    下一个问题,电流是多少 Runtime.getRuntime().availableProcessors()

    这取决于Java版本。在Java版本10之前,Docker上的应用程序看到的是机器上的CPU,而不是容器内的CPU。

    class TestCpu {
        public static void main(String[] args) {
           int processors = Runtime.getRuntime().availableProcessors();
           System.out.println("CPU cores: " + processors);
      }
    }