hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r521913 - in /lucene/hadoop/trunk: ./ src/java/org/apache/hadoop/record/
Date Fri, 23 Mar 2007 21:49:18 GMT
Author: cutting
Date: Fri Mar 23 14:49:17 2007
New Revision: 521913

URL: http://svn.apache.org/viewvc?view=rev&rev=521913
Log:
HADOOP-1094.  Optimize the generated Writable implementations for records to not allocate
a new BinaryOutputArchive or BinaryInputArchive per call.  Contributed by Milind.

Removed:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/record/InputArchive.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/record/OutputArchive.java
Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordInput.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordOutput.java
    lucene/hadoop/trunk/src/java/org/apache/hadoop/record/Record.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=521913&r1=521912&r2=521913
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri Mar 23 14:49:17 2007
@@ -27,6 +27,10 @@
  8. HADOOP-1137.  Fix StatusHttpServer to work correctly when
     resources are in a jar file.  (Benjamin Reed via cutting)
 
+ 9. HADOOP-1094.  Optimize generated Writable implementations for
+    records to not allocate a new BinaryOutputArchive or
+    BinaryInputArchive per call.  (Milind Bhandarkar via cutting)
+
 
 Release 0.12.2 - 2007-23-17
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordInput.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordInput.java?view=diff&rev=521913&r1=521912&r2=521913
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordInput.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordInput.java Fri Mar 23
14:49:17 2007
@@ -29,7 +29,7 @@
  */
 public class BinaryRecordInput implements RecordInput {
     
-    final private DataInput in;
+    private DataInput in;
     
     static private class BinaryIndex implements Index {
         private int nelems;
@@ -42,6 +42,29 @@
         public void incr() {
             nelems--;
         }
+    }
+    
+    private BinaryRecordInput() {}
+    
+    private void setDataInput(DataInput inp) {
+      this.in = inp;
+    }
+    
+    private static ThreadLocal bIn = new ThreadLocal() {
+      protected synchronized Object initialValue() {
+        return new BinaryRecordInput();
+      }
+    };
+    
+    /**
+     * Get a thread-local record input for the supplied DataInput.
+     * @param inp data input stream
+     * @return binary record input corresponding to the supplied DataInput.
+     */
+    public static BinaryRecordInput get(DataInput inp) {
+      BinaryRecordInput bin = (BinaryRecordInput) bIn.get();
+      bin.setDataInput(inp);
+      return bin;
     }
     
     /** Creates a new instance of BinaryRecordInput */

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordOutput.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordOutput.java?view=diff&rev=521913&r1=521912&r2=521913
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordOutput.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/BinaryRecordOutput.java Fri Mar
23 14:49:17 2007
@@ -33,6 +33,29 @@
     
     private DataOutput out;
     
+    private BinaryRecordOutput() {}
+    
+    private void setDataOutput(DataOutput out) {
+      this.out = out;
+    }
+    
+    private static ThreadLocal bOut = new ThreadLocal() {
+      protected synchronized Object initialValue() {
+        return new BinaryRecordOutput();
+      }
+    };
+    
+    /**
+     * Get a thread-local record output for the supplied DataOutput.
+     * @param out data output stream
+     * @return binary record output corresponding to the supplied DataOutput.
+     */
+    public static BinaryRecordOutput get(DataOutput out) {
+      BinaryRecordOutput bout = (BinaryRecordOutput) bOut.get();
+      bout.setDataOutput(out);
+      return bout;
+    }
+    
     /** Creates a new instance of BinaryRecordOutput */
     public BinaryRecordOutput(OutputStream out) {
         this.out = new DataOutputStream(out);

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/Record.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/Record.java?view=diff&rev=521913&r1=521912&r2=521913
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/Record.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/Record.java Fri Mar 23 14:49:17
2007
@@ -67,13 +67,13 @@
   
   // inherit javadoc
   public void write(final DataOutput out) throws java.io.IOException {
-    BinaryRecordOutput bout = new BinaryRecordOutput(out);
+    BinaryRecordOutput bout = BinaryRecordOutput.get(out);
     this.serialize(bout);
   }
   
   // inherit javadoc
   public void readFields(final DataInput din) throws java.io.IOException {
-    BinaryRecordInput rin = new BinaryRecordInput(din);
+    BinaryRecordInput rin = BinaryRecordInput.get(din);
     this.deserialize(rin);
   }
 }



Mime
View raw message