Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hessian2Input _sbuf memory leak #56

Open
1 task done
wallaceyoung opened this issue Feb 9, 2022 · 5 comments
Open
1 task done

Hessian2Input _sbuf memory leak #56

wallaceyoung opened this issue Feb 9, 2022 · 5 comments
Labels

Comments

@wallaceyoung
Copy link

wallaceyoung commented Feb 9, 2022

  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.9
  • Operating System version: linux
  • Java version: 1.8

Steps to reproduce this issue

1.dubbo线程数设置为250
2.偶尔序列化大对象,约18M
3.dump文件发现单个dubbo线程占用heap空间过大,导致频繁full gc,且full gc后内存回收很少。
3.Hessian2Input对象被ThreadLoacal复用,无法回收。成员变量_sbuf重置方法为_sbuf.setLength(0),StringBuilder底层char数组只会重置指针,不会清空数据,如果序列化过大对象,char数组里面会保留很多无效数据,建议Hessian2Input#reset时调用_sbuf.trimToSize方法清理。
image

@CrazyHZM CrazyHZM transferred this issue from apache/dubbo Feb 10, 2022
@wallaceyoung
Copy link
Author

wallaceyoung commented Apr 17, 2022

目前的解决方案是对Hessian2Serialization打了补丁
Hessian2Input#reset
_sbufMaxLength是在启动参数指定

private static int _sbufMaxLength = 3_000_000;

//启动参数增加-Dsbuf.max.length=5000000
            String sbufMaxLength = System.getProperty("sbuf.max.length");
            if (sbufMaxLength != null && sbufMaxLength.length() > 0) {
                _sbufMaxLength = Integer.parseInt(sbufMaxLength);
            }

public void reset() {
        this.resetReferences();
        if (this._classDefs != null) {
            this._classDefs.clear();
        }

        if (this._types != null) {
            this._types.clear();
        }

        this._offset = 0;
        this._length = 0;
        if (this._sbuf != null && this._sbuf.capacity() > _sbufMaxLength) {
            this._sbuf = new StringBuilder();
        }

    }

@gongxianshengjiadexiaohuihui

请问,这个有修复版本吗,我遇到了同样的问题,因为是固定线程数,而且数量比较大,导致了OOM

@AlbumenJ
Copy link
Member

Hessian2Input 的 ThreadLocal 在 Dubbo 高版本已经移除,可以升级 3.1.7 版本看下

@gongxianshengjiadexiaohuihui

这是生产的应用,涉及的老应用较多,大版本升级估计不太可能,不考虑出修复版本吗

@AlbumenJ
Copy link
Member

这是生产的应用,涉及的老应用较多,大版本升级估计不太可能,不考虑出修复版本吗

2.7.x 版本目前已经是仅安全维护状态了,而且将在下个月发布正式 EOL。目前最新的开发版本是 3.2.0。
发版规划请参考:https://cn.dubbo.apache.org/zh-cn/blog/2022/10/22/%E8%81%9A%E7%84%A6%E7%A8%B3%E5%AE%9A%E6%80%A7dubbo-java-%E5%8F%91%E7%89%88%E8%A7%84%E5%88%92%E5%85%AC%E5%B8%83/

如果升级过程中有任何问题可以提交 issue,对于大规模集群也可以联系我们提供专门的协助。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants