4

json序列化内存高问题

 1 year ago
source link: https://studygolang.com/articles/35948?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

json序列化内存高问题

coderyw · 大约6小时之前 · 133 次点击 · 预计阅读时间 1 分钟 · 大约8小时之前 开始浏览    

最近一个ws服务,出现内存高问题。通过pprof查看了一下是json在序列化时候内存很高。后来我换成了easyjson,也没有解决这个问题,我想是不是我分配对象过多,然后我使用了对象池,问题依旧没有得到解决。这个服务数据量是很大,推送出去的数据大小也不固定,小到几b,大到十几kb,一两Mb的都有。看了一下easyjson源码,底层也是维护了一个缓冲池,会根据分配的不用size给出对应的缓冲池。但是我就没想通为什么内存会这么高。下面是一些高内存图片:

image.png
这是heap图片
image.png

这个是监控的内存数据,每个一段时间就几百MB的涨。

问题是,其他类型的ws服务没有这问题,就这个数据量大点的服务有问题。

有人遇到同样的情况吗?


有疑问加站长微信联系(非本文作者))

280

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK