Java 11 + Docker Based App = `java.lang.OutOfMemoryError: Direct buffer memory`

Java 11 + Docker Based App = `java.lang.OutOfMemoryError: Direct buffer memory`

在 Kubernetes 上使用 flink:1.14.3-scala_2.12-java11 Docker 图像的 Flink 1.14.3 应用程序 运行,我收到此 Java 内存错误:

Caused by: java.lang.OutOfMemoryError: Direct buffer memory
    at java.base/java.nio.Bits.reserveMemory(Unknown Source)
    at java.base/java.nio.DirectByteBuffer.<init>(Unknown Source)
    at java.base/java.nio.ByteBuffer.allocateDirect(Unknown Source)
    at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:648)
    at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:623)
    at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:202)
    at io.netty.buffer.PoolArena.tcacheAllocateSmall(PoolArena.java:172)
    at io.netty.buffer.PoolArena.allocate(PoolArena.java:134)
    at io.netty.buffer.PoolArena.allocate(PoolArena.java:126)
    at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:394)
    at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188)
    at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179)
    at io.netty.buffer.AbstractByteBufAllocator.ioBuffer(AbstractByteBufAllocator.java:140)
    at io.netty.handler.codec.dns.DatagramDnsQueryEncoder.allocateBuffer(DatagramDnsQueryEncoder.java:82)
    at io.netty.handler.codec.dns.DatagramDnsQueryEncoder.encode(DatagramDnsQueryEncoder.java:60)
    at io.netty.handler.codec.dns.DatagramDnsQueryEncoder.encode(DatagramDnsQueryEncoder.java:33)
    at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89)
    ... 52 more

这尤其发生在使用 Netty 异步 http 引擎的 VertX 版本 4.2.4 异步 Postgresql 客户端上。

java的具体版本是:

java --version
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment 18.9 (build 11.0.13+8)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8, mixed mode, sharing)

是否有任何 JVM 或 Docker 或 Kubernetes 参数我应该尝试调整以解决此问题?

https://nightlies.apache.org/flink/flink-docs-release-1.14/docs/deployment/memory/mem_setup_tm/ 中描述了任务管理器内存布局和配置选项。