Repository: hadoop Updated Branches: refs/heads/branch-2.7 c10bf788e -> cb3aa41f5
HDFS-9724. Degraded performance in WebHDFS listing as it does not reuse ObjectMapper. Contributed by Akira Ajisaka. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/cb3aa41f Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/cb3aa41f Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/cb3aa41f Branch: refs/heads/branch-2.7 Commit: cb3aa41f53029d2b543b578f5506db4ccd26d414 Parents: c10bf78 Author: Haohui Mai <hao...@uber.com> Authored: Thu Feb 4 11:28:45 2016 -0800 Committer: Haohui Mai <hao...@uber.com> Committed: Thu Feb 4 11:36:12 2016 -0800 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../org/apache/hadoop/hdfs/web/JsonUtil.java | 23 ++++++++++---------- .../hadoop/hdfs/web/WebHdfsFileSystem.java | 6 +++-- 3 files changed, 19 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/cb3aa41f/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 17561f0..1d8d7a0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -89,6 +89,9 @@ Release 2.7.3 - UNRELEASED HDFS-9730. Storage ID update does not happen when there is a layout change (Tsz Wo Nicholas Sze via kihwal) + HDFS-9724. Degraded performance in WebHDFS listing as it does not reuse + ObjectMapper. (Akira AJISAKA via wheat9) + Release 2.7.2 - 2016-01-25 INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/cb3aa41f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java index bd0a5e6..12a4ed4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java @@ -50,6 +50,12 @@ public class JsonUtil { private static final Object[] EMPTY_OBJECT_ARRAY = {}; private static final DatanodeInfo[] EMPTY_DATANODE_INFO_ARRAY = {}; + // Reuse ObjectMapper instance for improving performance. + // ObjectMapper is thread safe as long as we always configure instance + // before use. We don't have a re-entrant call pattern in WebHDFS, + // so we just need to worry about thread-safety. + private static final ObjectMapper MAPPER = new ObjectMapper(); + /** Convert a token object to a Json string. */ public static String toJsonString(final Token<? extends TokenIdentifier> token ) throws IOException { @@ -120,9 +126,8 @@ public class JsonUtil { public static String toJsonString(final String key, final Object value) { final Map<String, Object> m = new TreeMap<String, Object>(); m.put(key, value); - ObjectMapper mapper = new ObjectMapper(); try { - return mapper.writeValueAsString(m); + return MAPPER.writeValueAsString(m); } catch (IOException ignored) { } return null; @@ -185,10 +190,9 @@ public class JsonUtil { m.put("fileId", status.getFileId()); m.put("childrenNum", status.getChildrenNum()); m.put("storagePolicy", status.getStoragePolicy()); - ObjectMapper mapper = new ObjectMapper(); try { return includeType ? - toJsonString(FileStatus.class, m) : mapper.writeValueAsString(m); + toJsonString(FileStatus.class, m) : MAPPER.writeValueAsString(m); } catch (IOException ignored) { } return null; @@ -644,9 +648,8 @@ public class JsonUtil { new TreeMap<String, Map<String, Object>>(); finalMap.put(AclStatus.class.getSimpleName(), m); - ObjectMapper mapper = new ObjectMapper(); try { - return mapper.writeValueAsString(finalMap); + return MAPPER.writeValueAsString(finalMap); } catch (IOException ignored) { } return null; @@ -713,8 +716,7 @@ public class JsonUtil { final XAttrCodec encoding) throws IOException { final Map<String, Object> finalMap = new TreeMap<String, Object>(); finalMap.put("XAttrs", toJsonArray(xAttrs, encoding)); - ObjectMapper mapper = new ObjectMapper(); - return mapper.writeValueAsString(finalMap); + return MAPPER.writeValueAsString(finalMap); } public static String toJsonString(final List<XAttr> xAttrs) @@ -723,11 +725,10 @@ public class JsonUtil { for (XAttr xAttr : xAttrs) { names.add(XAttrHelper.getPrefixName(xAttr)); } - ObjectMapper mapper = new ObjectMapper(); - String ret = mapper.writeValueAsString(names); + String ret = MAPPER.writeValueAsString(names); final Map<String, Object> finalMap = new TreeMap<String, Object>(); finalMap.put("XAttrNames", ret); - return mapper.writeValueAsString(finalMap); + return MAPPER.writeValueAsString(finalMap); } public static byte[] getXAttr(final Map<?, ?> json, final String name) http://git-wip-us.apache.org/repos/asf/hadoop/blob/cb3aa41f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index b738050..a72fa27 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -88,6 +88,7 @@ import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSelect import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.StringUtils; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.ObjectReader; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -125,6 +126,8 @@ public class WebHdfsFileSystem extends FileSystem private InetSocketAddress nnAddrs[]; private int currentNNAddrIndex; private boolean disallowFallbackToInsecureCluster; + private static final ObjectReader READER = + new ObjectMapper().reader(Map.class); /** * Return the protocol scheme for the FileSystem. @@ -329,8 +332,7 @@ public class WebHdfsFileSystem extends FileSystem + "\" (parsed=\"" + parsed + "\")"); } } - ObjectMapper mapper = new ObjectMapper(); - return mapper.reader(Map.class).readValue(in); + return READER.readValue(in); } finally { in.close(); }