hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r924991 - in /hadoop/mapreduce/trunk: CHANGES.txt src/tools/org/apache/hadoop/tools/rumen/RandomSeedGenerator.java
Date Thu, 18 Mar 2010 21:00:57 GMT
Author: mahadev
Date: Thu Mar 18 21:00:56 2010
New Revision: 924991

URL: http://svn.apache.org/viewvc?rev=924991&view=rev
Log:
MAPREDUCE-1593.  [Rumen] Improvements to random seed generation (tamas via mahadev)

Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/tools/org/apache/hadoop/tools/rumen/RandomSeedGenerator.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=924991&r1=924990&r2=924991&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Thu Mar 18 21:00:56 2010
@@ -214,6 +214,9 @@ Trunk (unreleased changes)
     MAPREDUCE-1482. Truncate state string and diagnostic information in
     TaskStatus. (Amar Kamat via szetszwo)
 
+    MAPREDUCE-1593.  [Rumen] Improvements to random seed generation (tamas via
+    mahadev)
+
   OPTIMIZATIONS
 
     MAPREDUCE-270. Fix the tasktracker to optionally send an out-of-band

Modified: hadoop/mapreduce/trunk/src/tools/org/apache/hadoop/tools/rumen/RandomSeedGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/tools/org/apache/hadoop/tools/rumen/RandomSeedGenerator.java?rev=924991&r1=924990&r2=924991&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/tools/org/apache/hadoop/tools/rumen/RandomSeedGenerator.java
(original)
+++ hadoop/mapreduce/trunk/src/tools/org/apache/hadoop/tools/rumen/RandomSeedGenerator.java
Thu Mar 18 21:00:56 2010
@@ -43,6 +43,20 @@ import org.apache.commons.logging.LogFac
 public class RandomSeedGenerator {
   private static Log LOG = LogFactory.getLog(RandomSeedGenerator.class);
   
+  /** MD5 algorithm instance, one for each thread. */
+  private static final ThreadLocal<MessageDigest> md5Holder =
+      new ThreadLocal<MessageDigest>() {
+        @Override protected MessageDigest initialValue() {
+          MessageDigest md5 = null; 
+          try {
+            md5 = MessageDigest.getInstance("MD5");
+          } catch (NoSuchAlgorithmException nsae) {
+            throw new RuntimeException("Can't create MD5 digests", nsae);
+          }
+          return md5;
+        }
+      };
+      
   /**
    * Generates a new random seed.
    *
@@ -52,12 +66,8 @@ public class RandomSeedGenerator {
    *         (vastly) different random seeds.
    */   
   public static long getSeed(String streamId, long masterSeed) {
-    MessageDigest md5 = null; 
-    try {
-      md5 = MessageDigest.getInstance("MD5");
-    } catch (NoSuchAlgorithmException nsae) {
-      throw new RuntimeException("Can't create MD5 digests", nsae);
-    }
+    MessageDigest md5 = md5Holder.get();
+    md5.reset();
     //'/' : make sure that we don't get the same str from ('11',0) and ('1',10)
     // We could have fed the bytes of masterSeed one by one to md5.update()
     // instead



Mime
View raw message