runzhiwang opened a new pull request #76:
URL: https://github.com/apache/incubator-ratis/pull/76
**What's the problem ?**
As the image shows, there are 1885 instances of RaftServerImpl, most of
them are Closed, and should be GC, but actually not. You can find from the
image
1513 RaftServerImpl were held by
ManagermentFactory->jxmMBeanServer->HashMap, 372 RaftServerImpl were held by
Datanode ReportManager Thread -> prometheus -> HashMap. So 1513 RaftServerImpl
leak in ratis, and 372 leak in ozone. If RaftServerImpl can not GC, there are a
lot of related resource can not be GC, such as the
[DirectByteBuffer](https://github.com/apache/incubator-ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java#L150)
in SegmentRaftLogWorker, which result 1GB memory leak out of heap.
**1. 1885 instances of RaftServerImpl**

**2. 1513 RaftServerImpl were held by
ManagermentFactory->jxmMBeanServer->HashMap, 372 RaftServerImpl were held by
Datanode ReportManager Thread -> prometheus -> HashMap**

**3. 1513 RaftServerImpl were held by
ManagermentFactory->jxmMBeanServer->HashMap**

**4. 372 RaftServerImpl were held by Datanode ReportManager Thread ->
prometheus -> HashMap**

5. 2038 DirectByteBuffer, and 1885 held by RaftServerImpl

6. 1033 DirectByteBuffer were held by ManagermentFactory, 802
DirectByteBuffer were held by Datanode ReportManager Thread, total 1885.

7. The reason RaftServerImpl held by
ManagermentFactory->jxmMBeanServer->HashMap is ratis start
[JmxReporter](https://github.com/apache/incubator-ratis/blob/master/ratis-metrics/src/main/java/org/apache/ratis/metrics/MetricsReporting.java#L47),
but does not stop it.
8. The reason RaftServerImpl held by Datanode ReportManager Thread ->
prometheus -> HashMap is ozone call the ratis function to
[register](https://github.com/apache/hadoop-ozone/blob/master/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java#L189)
metric in prometheus, but does not unregister it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]