[
https://issues.apache.org/jira/browse/HDFS-11832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16017598#comment-16017598
]
Hui Xu commented on HDFS-11832:
-------------------------------
Hi Akira Ajisaka and Chen Liang,
Would you refer to the official link as follows?
https://www.slf4j.org/faq.html#logging_performance
Better yet, use parameterized messages
There exists a very convenient alternative based on message formats. Assuming
entry is an object, you can write:
Object entry = new SomeObject();
logger.debug("The entry is {}.", entry);
After evaluating whether to log or not, and only if the decision is
affirmative, will the logger implementation format the message and replace the
'{}' pair with the string value of entry. In other words, this form does not
incur the cost of parameter construction in case the log statement is disabled.
The following two lines will yield the exact same output. However, the second
form will outperform the first form by a factor of at least 30, in case of a
disabled logging statement.
logger.debug("The new entry is "+entry+".");
logger.debug("The new entry is {}.", entry);
And this is the source code:
public void debug(String format, Object arg) {
if(this.logger.isDebugEnabled()) {
FormattingTuple ft = MessageFormatter.format(format, arg);
this.logger.log(FQCN, Level.DEBUG, ft.getMessage(),
ft.getThrowable());
}
}
public static final FormattingTuple format(String messagePattern, Object
arg) {
return arrayFormat(messagePattern, new Object[]{arg});
}
So, Arrays.asList(blocks) will not new the object until the format function.
Looking forward to your next discussion.
> Switch leftover logs to slf4j format in BlockManager.java
> ---------------------------------------------------------
>
> Key: HDFS-11832
> URL: https://issues.apache.org/jira/browse/HDFS-11832
> Project: Hadoop HDFS
> Issue Type: Improvement
> Components: namenode
> Affects Versions: 2.7.0, 2.8.0, 3.0.0-alpha1
> Reporter: Hui Xu
> Assignee: Chen Liang
> Priority: Minor
> Attachments: HDFS-11832.001.patch, HDFS-11832.002.patch,
> HDFS-11832.003.patch, HDFS-11832.004.patch
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> HDFS-7706 Switch BlockManager logging to use slf4j. But the logging formats
> were not modified appropriately. For example:
> if (LOG.isDebugEnabled()) {
> LOG.debug("blocks = " + java.util.Arrays.asList(blocks));
> }
> These codes should be modified to:
> LOG.debug("blocks = {}", java.util.Arrays.asList(blocks));
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]