apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.39k stars 8.79k forks source link

高配服务器出现OutOfDirectMemoryError异常 #2164

Closed HongKing closed 4 years ago

HongKing commented 4 years ago

Ⅰ. Issue Description

seata-server 在开发、测试阶段都一切正常,昨天准备部署生产试运行环境时出现的。eureka注册中心,mysql数据库,启动参数及脚本采用默认的(-XX:MaxDirectMemorySize=1024m)。 出现错误后,尝试修改-XX:MaxDirectMemorySize 为2G,3G,4G都会出问题,大概接入了5个左右的微服务就爆。

能否给出一个服务器推荐配置?

Ⅱ. Describe what happened

错误日志:

2020-01-10 10:35:09.728 INFO [NettyServerNIOWorker_1_64]io.seata.core.rpc.netty.RpcServer.exceptionCaught:377 -channel exx:failed to allocate 134217728 byte(s) of direct memory (used: 1073741824, max: 1073741824),channel:[id: 0x5f464337, L:/112.128.4.29:8091 - R:/112.128.4.62:44292]2020-01-10 10:35:09.728 ERROR[NettyServerNIOWorker_1_64]io.seata.core.rpc.netty.AbstractRpcRemoting.exceptionCaught:437 -0318
io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 134217728 byte(s) of direct memory (used: 1073741824, max: 1073741824)
    at io.netty.util.internal.PlatformDependent.incrementMemoryCounter(PlatformDependent.java:652)
    at io.netty.util.internal.PlatformDependent.allocateDirectNoCleaner(PlatformDependent.java:606)
    at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:764)
    at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:740)
    at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:244)
    at io.netty.buffer.PoolArena.allocate(PoolArena.java:214)
    at io.netty.buffer.PoolArena.allocate(PoolArena.java:146)
    at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:324)
    at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:185)
    at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:176)
    at io.netty.buffer.AbstractByteBufAllocator.ioBuffer(AbstractByteBufAllocator.java:137)
    at io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator$MaxMessageHandle.allocate(DefaultMaxMessagesRecvByteBufAllocator.java:114)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:147)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:745)

Ⅲ. Describe what you expected to happen

网上都是给的netty内存溢出方案,我怀疑跟JVM内存管理有关,暂时还没有用jps详细跟踪。

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. 服务器高配(32vCPU,64G内存)
  2. seata-server 1.0.0
  3. 5个以上的微服务

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

服务器配置: 开发测试:4核8G(一切正常,10多个微服务连接也没有问题) 生产试运行:32核64G(5个微服务就报错) seata-server的配置参数都一致

HongKing commented 4 years ago

补充:seata-server所在服务器为centos7的最小化安装,仅关闭了防火墙,其他未做任何调整

zjinlei commented 4 years ago

Known issues are being investigated. The recommended configuration has been implemented by default.

zhang379988125 commented 4 years ago

配置不能解决问题,我用类似 http://www.jiangxinlingdu.com/practice/2018/09/04/netty-outofheap.html 文中的方法跟踪了代码, 问题差不多,netty建立链接时,内存统计器,做了累加,断开链接时,不会减,再重新建立链接,继续累加,默认每次分配256M,所以配置多大都不行,异常只是时间问题,本人能力有限,跟踪了断开链接的代码,没能找到解决问题的入口,期待问题得到解决
image

zjinlei commented 4 years ago

We have provided a new server startup package, please help verify it. Can be downloaded from qq group (254657148), Dingding 2 group (http://seata.io/zh-cn/community/index.html).

slievrly commented 4 years ago

@HongKing Can you verify if this pr fixes the problem you encountered? #2175

HongKing commented 4 years ago

@slievrly 已解决,强!