You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Sangjin Lee (JIRA)" <ji...@apache.org> on 2015/06/20 00:42:01 UTC
[jira] [Commented] (HADOOP-12107) long running apps may have a huge
number of StatisticsData instances under FileSystem
[ https://issues.apache.org/jira/browse/HADOOP-12107?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14594054#comment-14594054 ]
Sangjin Lee commented on HADOOP-12107:
--------------------------------------
The key method in clearing this memory is in {{Statistics.visitAll()}}:
{code}
private synchronized <T> T visitAll(StatisticsAggregator<T> visitor) {
visitor.accept(rootData);
if (allData != null) {
for (Iterator<StatisticsData> iter = allData.iterator();
iter.hasNext(); ) {
StatisticsData data = iter.next();
visitor.accept(data);
if (data.owner.get() == null) {
/*
* If the thread that created this thread-local data no
* longer exists, remove the StatisticsData from our list
* and fold the values into rootData.
*/
rootData.add(data);
iter.remove();
}
}
}
return visitor.aggregate();
}
{code}
As part of running the visitor, it checks to see if the underlying thread is gone, and if so, adds the data for that thread to {{rootData}} and removes the instance from the list.
This pattern almost literally cries out for using a {{PhantomReference}}. That way, we can perform this operation as soon as the garbage collector clears up the threads. I'll draw up a patch based on that idea soon.
> long running apps may have a huge number of StatisticsData instances under FileSystem
> -------------------------------------------------------------------------------------
>
> Key: HADOOP-12107
> URL: https://issues.apache.org/jira/browse/HADOOP-12107
> Project: Hadoop Common
> Issue Type: Bug
> Components: fs
> Affects Versions: 2.7.0
> Reporter: Sangjin Lee
> Assignee: Sangjin Lee
> Priority: Minor
>
> We observed with some of our apps (non-mapreduce apps that use filesystems) that they end up accumulating a huge memory footprint coming from {{FileSystem$Statistics$StatisticsData}} (in the {{allData}} list of {{Statistics}}).
> Although the thread reference from {{StatisticsData}} is a weak reference, and thus can get cleared once a thread goes away, the actual {{StatisticsData}} instances in the list won't get cleared until any of these following methods is called on {{Statistics}}:
> - {{getBytesRead()}}
> - {{getBytesWritten()}}
> - {{getReadOps()}}
> - {{getLargeReadOps()}}
> - {{getWriteOps()}}
> - {{toString()}}
> It is quite possible to have an application that interacts with a filesystem but does not call any of these methods on the {{Statistics}}. If such an application runs for a long time and has a large amount of thread churn, the memory footprint will grow significantly.
> The current workaround is either to limit the thread churn or to invoke these operations occasionally to pare down the memory. However, this is still a deficiency with {{FileSystem$Statistics}} itself in that the memory is controlled only as a side effect of those operations.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)