avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scottca...@apache.org
Subject svn commit: r1068045 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
Date Mon, 07 Feb 2011 18:37:17 GMT
Author: scottcarey
Date: Mon Feb  7 18:37:16 2011
New Revision: 1068045

URL: http://svn.apache.org/viewvc?rev=1068045&view=rev
Log:
AVRO-743 Java: Performance Regression and memory pressure with GenericDatumReader

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1068045&r1=1068044&r2=1068045&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Feb  7 18:37:16 2011
@@ -150,6 +150,9 @@ Avro 1.5.0 (unreleased)
 
   BUG FIXES
 
+    AVRO-743. Java: Performance Regression and memory pressure with 
+    GenericDatumReader. (scottcarey)
+
     AVRO-675. C: Bytes and fixed setters don't update datum size.
     (Douglas Creager via massie)
 

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java?rev=1068045&r1=1068044&r2=1068045&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
Mon Feb  7 18:37:16 2011
@@ -37,6 +37,9 @@ public class GenericDatumReader<D> imple
   private GenericData data;
   private Schema actual;
   private Schema expected;
+  
+  private ResolvingDecoder creatorResolver = null;
+  private final Thread creator;
 
   public GenericDatumReader() {
     this(null, null, GenericData.get());
@@ -56,6 +59,7 @@ public class GenericDatumReader<D> imple
     this.actual = writer;
     this.expected = reader;
     this.data = data;
+    this.creator = Thread.currentThread();
   }
 
   @Override
@@ -64,18 +68,15 @@ public class GenericDatumReader<D> imple
     if (expected == null) {
       expected = actual;
     }
-    threadResolver.set(null);
+    creatorResolver = null;
   }
 
   /** Set the reader's schema. */
   public void setExpected(Schema reader) throws IOException {
     this.expected = reader;
-    threadResolver.set(null);
+    creatorResolver = null;
   }
 
-  private final ThreadLocal<ResolvingDecoder> threadResolver =
-    new ThreadLocal<ResolvingDecoder>();
-
   private static final ThreadLocal<Map<Schema,Map<Schema,ResolvingDecoder>>>
     RESOLVER_CACHE =
     new ThreadLocal<Map<Schema,Map<Schema,ResolvingDecoder>>>() {
@@ -86,9 +87,11 @@ public class GenericDatumReader<D> imple
 
   private ResolvingDecoder getResolver(Schema actual, Schema expected)
     throws IOException {
-    ResolvingDecoder resolver = threadResolver.get();
-    if (resolver != null)
-      return resolver;
+    Thread currThread = Thread.currentThread();
+    ResolvingDecoder resolver;
+    if (currThread == creator && creatorResolver != null) {
+      return creatorResolver;
+    } 
 
     Map<Schema,ResolvingDecoder> cache = RESOLVER_CACHE.get().get(actual);
     if (cache == null) {
@@ -101,7 +104,11 @@ public class GenericDatumReader<D> imple
                                       expected, null);
       cache.put(expected, resolver);
     }
-    threadResolver.set(resolver);
+    
+    if (currThread == creator){
+      creatorResolver = resolver;
+    }
+
     return resolver;
   }
 



Mime
View raw message