diff --git a/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java b/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java index ef2d5bed21f..9917d93d115 100644 --- a/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java +++ b/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java @@ -30,6 +30,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import org.apache.commons.io.IOUtils; import org.apache.lucene.util.TestUtil; @@ -477,7 +478,7 @@ public class TestJavaBinCodec extends SolrTestCaseJ4 { } - private void runInThreads(int count, Runnable runnable) throws InterruptedException { + private static void runInThreads(int count, Runnable runnable) throws InterruptedException { ArrayList t =new ArrayList(); for(int i=0;i 0 ? new ConcurrentLRUCache<>(cacheSz,cacheSz-cacheSz/10,cacheSz,cacheSz/10,false,true,null) : null; // the cache in the first version of the patch was 10000,9000,10000,1000,false,true,null + JavaBinCodec.StringCache stringCache = underlyingCache==null ? null : new JavaBinCodec.StringCache(underlyingCache); + if (nThreads <= 0) { + ret += doDecode(buffers, iter, stringCache); + } else { + runInThreads(nThreads, new Runnable() { + @Override + public void run() { + try { + doDecode(buffers, iter, stringCache); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + } + long end = System.currentTimeMillis(); + + long n = iter * Math.max(1,nThreads); + System.out.println("ret=" + ret + " THROUGHPUT=" + (n*1000 / (end-start))); + if (underlyingCache != null) System.out.println("cache: hits=" + underlyingCache.getStats().getCumulativeHits() + " lookups=" + underlyingCache.getStats().getCumulativeLookups() + " size=" + underlyingCache.getStats().getCurrentSize()); + } + + public static int doDecode(byte[][] buffers, long iter, JavaBinCodec.StringCache stringCache) throws IOException { + int ret = 0; + int bufnum = -1; + byte[] tmp = new byte[8192]; + + InputStream empty = new InputStream() { + @Override + public int read() throws IOException { + return -1; + } + }; + + while (--iter >= 0) { + if (++bufnum >= buffers.length) bufnum = 0; + byte[] buf = buffers[bufnum]; + JavaBinCodec javabin = new JavaBinCodec(null, stringCache); + FastInputStream in = new FastInputStream(empty, buf, 0, buf.length); + Object o = javabin.unmarshal( in ); + if (o instanceof SolrDocument) { + ret += ((SolrDocument) o).size(); + } + } + return ret; } } + +