我在批量生成service order时,report运行几个小时后,遇到out of memory exception:
<img src="https://user-images.githubusercontent.com/5669954/55127283-96be6280-514a-11e9-9309-749e7fdae8b9.png">
<img src="https://user-images.githubusercontent.com/5669954/55127284-9756f900-514a-11e9-95ea-ee40d66698cf.png">
SM04里发现我的report随着时间的推移,消耗的内存越来越多:
<img src="https://user-images.githubusercontent.com/5669954/55127285-9756f900-514a-11e9-9966-3c8f565039b8.png">
<img src="https://user-images.githubusercontent.com/5669954/55127286-9756f900-514a-11e9-957e-41c38bfad0b4.png">
<img src="https://user-images.githubusercontent.com/5669954/55127287-97ef8f80-514a-11e9-9144-d04010a7b977.png">
如何找到出现memory leak的代码的准确位置?
我的report里有个package size,类似于OPEN CURSOR和FETCH的design,比如package size是1000,那么每1000个service order创建成功后,清一次buffer,然后创建第二批1000个order,再清第二次buffer.
所以我只需要在两次清buffer之后分别创建一个memory snapshot:
<img src="https://user-images.githubusercontent.com/5669954/55127288-97ef8f80-514a-11e9-9295-35cbf16cc18a.png">
创建好之后tcode S_MEMORY_INSPECTOR, 比较两个snapshot里的delta部分,即为引起memory leak的变量。这个transaction列出了变量所在的program name,剩下的事情就是去找能清除这些变量对应的API.
<img src="https://user-images.githubusercontent.com/5669954/55127291-9920bc80-514a-11e9-87ed-c48c573522d4.png">
修改完之后成效显著,修改之前一个user session跑一个小时内存consumtpion就超过了7GB,现在跑了一下午,每个session不超过2GB了。
<img src="https://user-images.githubusercontent.com/5669954/55127292-9920bc80-514a-11e9-8337-f72e5c7348ca.png">
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
<img src="https://user-images.githubusercontent.com/5669954/61616089-2a87e180-ac9a-11e9-861d-c29c2cf897af.png">
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。