Kaynağa Gözat

MAPREDUCE-4565. Backport MR-2855 to branch-1: ResourceBundle lookup during counter name resolution takes a lot of time. (Contributed by Karthik Kambatla)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1375835 13f79535-47bb-0310-9956-ffa450edef68
Siddharth Seth 13 yıl önce
ebeveyn
işleme
1448cb7f2e

+ 3 - 0
CHANGES.txt

@@ -84,6 +84,9 @@ Release 1.2.0 - unreleased
 
     MAPREDUCE-4511. Add IFile readahead (ahmed via tucu)
 
+    MAPREDUCE-4565. Backport MR-2855 to branch-1: ResourceBundle lookup during
+    counter name resolution takes a lot of time. (Karthik Kambatla via sseth)
+
   OPTIMIZATIONS
 
     HDFS-2533. Backport: Remove needless synchronization on some FSDataSet

+ 2 - 10
src/mapred/org/apache/hadoop/mapred/Counters.java

@@ -36,6 +36,7 @@ import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableUtils;
+import org.apache.hadoop.mapreduce.CounterGroup;
 import org.apache.hadoop.util.StringUtils;
 
 /**
@@ -167,7 +168,7 @@ public class Counters implements Writable, Iterable<Counters.Group> {
     
     Group(String groupName) {
       try {
-        bundle = getResourceBundle(groupName);
+        bundle = CounterGroup.getResourceBundle(groupName);
       }
       catch (MissingResourceException neverMind) {
       }
@@ -384,15 +385,6 @@ public class Counters implements Writable, Iterable<Counters.Group> {
    */
   private Map<Enum, Counter> cache = new IdentityHashMap<Enum, Counter>();
 
-  /**
-   * Returns the specified resource bundle, or throws an exception.
-   * @throws MissingResourceException if the bundle isn't found
-   */
-  private static ResourceBundle getResourceBundle(String enumClassName) {
-    String bundleName = enumClassName.replace('$','_');
-    return ResourceBundle.getBundle(bundleName);
-  }
-
   /**
    * Returns the names of all counter classes.
    * @return Set of counter names.

+ 7 - 2
src/mapred/org/apache/hadoop/mapreduce/CounterGroup.java

@@ -22,10 +22,12 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import java.util.TreeMap;
 
+import org.apache.hadoop.classification.InterfaceAudience.Private;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableUtils;
@@ -45,9 +47,12 @@ public class CounterGroup implements Writable, Iterable<Counter> {
    * Returns the specified resource bundle, or throws an exception.
    * @throws MissingResourceException if the bundle isn't found
    */
-  private static ResourceBundle getResourceBundle(String enumClassName) {
+  @Private
+  public static ResourceBundle getResourceBundle(String enumClassName)
+      throws MissingResourceException {
     String bundleName = enumClassName.replace('$','_');
-    return ResourceBundle.getBundle(bundleName);
+    return ResourceBundle.getBundle(bundleName, Locale.getDefault(), Thread
+        .currentThread().getContextClassLoader());
   }
 
   protected CounterGroup(String name) {