Index: src/java/org/apache/lucene/store/FSDirectoryPool.java =================================================================== --- src/java/org/apache/lucene/store/FSDirectoryPool.java (revision 0) +++ src/java/org/apache/lucene/store/FSDirectoryPool.java (revision 0) @@ -0,0 +1,88 @@ +package org.apache.lucene.store; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +public class FSDirectoryPool extends FSDirectory { + + final ThreadLocal byThread = new ThreadLocal(); + + public FSDirectoryPool() { + } + + public static FSDirectory getDirectory(File file, LockFactory lockFactory) + throws IOException { + FSDirectoryPool pool = (FSDirectoryPool) getDirectory(file, lockFactory, FSDirectoryPool.class); + return pool; + } + + public IndexInput openInput(String name) throws IOException { + return openInput(name, BufferedIndexInput.BUFFER_SIZE); + } + + public IndexInput openInput(String name, int bufferSize) throws IOException { + HashMap myThread = (HashMap) byThread.get(); + if (myThread == null) { + myThread = new HashMap(); + byThread.set(myThread); + } + FSIndexInputPool input = (FSIndexInputPool) myThread.get(name); + if (input != null) + return input; + + final File path = new File(directory, name); + input = new FSIndexInputPool(name, path, bufferSize); + myThread.put(name, input); + System.out.println("openInput thread=" + Thread.currentThread().getName() + " name=" + name + " file=" + input.file); + + return input; + } + + protected class FSIndexInputPool extends FSDirectory.FSIndexInput { + final String name; + final int bufferSize; + + public FSIndexInputPool(String name, File path, int bufferSize) throws IOException { + super(path, bufferSize); + this.name = name; + this.bufferSize = bufferSize; + } + + public Object clone() { + + // Get thread private file + FSIndexInputPool perThread; + try { + perThread = (FSIndexInputPool) openInput(name, bufferSize); + } catch (IOException ioe) { + ioe.printStackTrace(System.out); + perThread = this; + } + + // Then clone it + return perThread.copy(); + } + + public Object copy() { + return super.clone(); + } + } +} Index: src/java/org/apache/lucene/store/FSDirectory.java =================================================================== --- src/java/org/apache/lucene/store/FSDirectory.java (revision 677553) +++ src/java/org/apache/lucene/store/FSDirectory.java (working copy) @@ -165,6 +165,12 @@ public static FSDirectory getDirectory(File file, LockFactory lockFactory) throws IOException { + return getDirectory(file, lockFactory, IMPL); + } + + static FSDirectory getDirectory(File file, LockFactory lockFactory, Class impl) + throws IOException + { file = new File(file.getCanonicalPath()); if (file.exists() && !file.isDirectory()) @@ -179,7 +185,7 @@ dir = (FSDirectory)DIRECTORIES.get(file); if (dir == null) { try { - dir = (FSDirectory)IMPL.newInstance(); + dir = (FSDirectory)impl.newInstance(); } catch (Exception e) { throw new RuntimeException("cannot load FSDirectory class: " + e.toString(), e); } @@ -249,7 +255,8 @@ lockFactory.clearLock(IndexWriter.WRITE_LOCK_NAME); } - private File directory = null; + // nocommit - was private + protected File directory = null; private int refCount; protected FSDirectory() {}; // permit subclassing @@ -570,7 +577,8 @@ } } - private final Descriptor file; + // nocommit -- was private + final Descriptor file; boolean isClone; public FSIndexInput(File path) throws IOException { Index: contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java =================================================================== --- contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java (revision 677555) +++ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java (working copy) @@ -30,6 +30,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.FSDirectoryPool; import org.apache.lucene.store.RAMDirectory; import java.io.File; @@ -126,7 +127,10 @@ FileUtils.fullyDelete(indexDir); } indexDir.mkdirs(); - directory = FSDirectory.getDirectory(indexDir); + if (config.get("pool","false").equals("false")) + directory = FSDirectory.getDirectory(indexDir); + else + directory = FSDirectoryPool.getDirectory(indexDir, null); } else { directory = new RAMDirectory(); }