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

feat(Jprotobuf): Avoid create lot of CodedOutputStream instance! #185

Merged
merged 3 commits into from
Oct 12, 2022

Conversation

qiunet
Copy link
Contributor

@qiunet qiunet commented Aug 12, 2022

压测在线3K. 每秒每人发30包 收20包. 每次ygc(11秒). 会创建两千万的CodedOutputStream 和 ByteArrayOutputStream. 和大量的字节数组对象

   2:      23799859      951994360  com.google.protobuf.CodedOutputStream$OutputStreamEncoder
   3:      23800055      571201320  java.io.ByteArrayOutputStream

因为处理序列化和反序列化没有切换线程, 可以使用ThreadLocal做对象缓存优化. 优化后, 几乎可以忽略. 我这固定是160个对象. YGC时间也延长到18秒.

   388:           160           6400  com.google.protobuf.CodedOutputStream$OutputStreamEncoder
   361:           421          10104  java.io.ByteArrayOutputStream

但是使用ByteBuffer构造CodedOutputStream 以及 CodedInputStream ,我没有找到好的优化方案

@qiunet
Copy link
Contributor Author

qiunet commented Aug 19, 2022

现在使用Netty的ByteBufOutputStream参考类似方法, 也可以实现对象缓存. 可以不用在堆内存里面产生大量的byte[]了!

@jhunters jhunters merged commit 302e46b into jhunters:master Oct 12, 2022
@jhunters
Copy link
Owner

合入到2.4.17版本发布

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

Successfully merging this pull request may close these issues.

2 participants