Using the "not-shared" strategy did not work as it increased the response time.
What I observe is that when the 100 simultaneous requests are fired from JMeter, the CPU utilization is is between 80-100% for executing the queries. I am using JBoss 4.2 with max heap size of 1024MB.
I have also optimized the Lucene indexes.
Here is the code for hitting and getting the list of records from Lucene index directly. The results of running this follow the code. From this it is clear that plain Lucene is much faster. How cann I find out if there is a deadlock on SegmentReader?
Code:
/**
* May 24, 2008, 1:41:55 PM
*
* TestSearchPerformance.java
*/
package lucene.performance;
import java.io.IOException;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.LockObtainFailedException;
/**
* Class to test search performance
* @author rakesh_shete
*
*/
public class TestSearchPerformance {
public IndexSearcher indexSearcher = null;
private static String queryString1 = null;
private static String indexPath = null;
private static String optimizedIndexPath = null;
static{
indexPath = new String("D:/QA_Build_20080515/LuceneIndexes/indexes");
optimizedIndexPath = new String("D:/QA_Build_20080515_optimized/LuceneIndexes/indexes");
queryString1 = new String("+((t:\"java boss\"^20.0 ((t:java* t:boss*)^18.0)) (d:\"java boss\"^2.5 ((d:java* d:boss*)^2.0)) (dd:\"java boss\"^1.8 ((dd:java* dd:boss*)^1.4)) (tg:\"java boss\"^1.2 ((tg:java* tg:boss*)^1.05))) +st:act +ntid:0");
}
public static void main(String[] args) throws CorruptIndexException, IOException {
//optimizeIndexes();
//testSearchPerformance(indexPath);
testSearchPerformance(optimizedIndexPath);
}
/**
* Function to test search performance
*/
private static void testSearchPerformance(String indexpath) throws CorruptIndexException, IOException{
TestSearchPerformance ts = new TestSearchPerformance();
// Create an instance of IndexSearcher and use it in every search
ts.indexSearcher = new IndexSearcher(indexpath);
for (int i = 1; i <= 100; i++) {
// Create a thread and invoke it
SearcherThread searcherThread = ts.new SearcherThread(i, ts.queryString1, ts.indexSearcher);
searcherThread.start();
}
}
/**
* Thread to execute search
*/
private class SearcherThread extends Thread {
private int threadId;
private String queryString;
private IndexSearcher indexsearcher;
/**
* Initialize with thread-id, querystring, indexsearcher
*/
public SearcherThread(int threadId, String queryString, IndexSearcher indexSearcher) {
this.threadId = threadId;
this.queryString = queryString;
this.indexsearcher = indexSearcher;
}
/**
* @see java.lang.Runnable#run()
*/
public void run() {
try {
QueryParser qp = new QueryParser("t",
new StandardAnalyzer());
qp.setLowercaseExpandedTerms(true);
// Parse the query
Query q = qp.parse(queryString);
if (q instanceof BooleanQuery) {
((BooleanQuery) q)
.setMaxClauseCount(Integer.MAX_VALUE);
}
long start = System.currentTimeMillis();
// Search
Hits hits = indexsearcher.search(q);
long totalTime = System.currentTimeMillis() - start;
System.out.println("[ Thread-id : " + threadId + " ] Total time taken for search is : " + totalTime + "ms with total no. of matching records : " + hits.length());
}
catch (ParseException e) {
// TODO Auto-generated catch block
System.out.println("[ Thread-id : " + threadId + " ] Parse Exception for queryString : " + queryString);
e.printStackTrace();
}
catch (IOException e) {
System.out.println("[ Thread-id : " + threadId + " ] IO Exception for queryString : " + queryString);
}
}
}
/**
* Optimize the index
*/
private static void optimizeIndexes(){
try {
IndexWriter writer = new IndexWriter(optimizedIndexPath, new StandardAnalyzer(), false);
long startTime = System.currentTimeMillis();
writer.optimize();
long totalTime = System.currentTimeMillis() - startTime;
System.out.println("Time taken for optimization: " + totalTime);
writer.close();
}
catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (LockObtainFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The results for 100 threads is as follows:
-------------------------------------------------
[ Thread-id : 95 ] Total time taken for search is : 1015ms with total no. of matching records : 428
[ Thread-id : 29 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 31 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 88 ] Total time taken for search is : 1047ms with total no. of matching records : 428
[ Thread-id : 89 ] Total time taken for search is : 1047ms with total no. of matching records : 428
[ Thread-id : 33 ] Total time taken for search is : 1156ms with total no. of matching records : 428
[ Thread-id : 12 ] Total time taken for search is : 1297ms with total no. of matching records : 428
[ Thread-id : 10 ] Total time taken for search is : 1297ms with total no. of matching records : 428
[ Thread-id : 53 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 91 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 54 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 18 ] Total time taken for search is : 1266ms with total no. of matching records : 428
[ Thread-id : 48 ] Total time taken for search is : 1125ms with total no. of matching records : 428
[ Thread-id : 47 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 87 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 55 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 40 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 51 ] Total time taken for search is : 1156ms with total no. of matching records : 428
[ Thread-id : 52 ] Total time taken for search is : 1156ms with total no. of matching records : 428
[ Thread-id : 34 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 74 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 27 ] Total time taken for search is : 1203ms with total no. of matching records : 428
[ Thread-id : 59 ] Total time taken for search is : 1125ms with total no. of matching records : 428
[ Thread-id : 75 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 90 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 80 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 92 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 32 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 37 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 97 ] Total time taken for search is : 1062ms with total no. of matching records : 428
[ Thread-id : 45 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 15 ] Total time taken for search is : 1266ms with total no. of matching records : 428
[ Thread-id : 20 ] Total time taken for search is : 1250ms with total no. of matching records : 428
[ Thread-id : 44 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 16 ] Total time taken for search is : 1266ms with total no. of matching records : 428
[ Thread-id : 38 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 39 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 73 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 66 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 3 ] Total time taken for search is : 1297ms with total no. of matching records : 428
[ Thread-id : 2 ] Total time taken for search is : 1312ms with total no. of matching records : 428
[ Thread-id : 43 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 86 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 19 ] Total time taken for search is : 1250ms with total no. of matching records : 428
[ Thread-id : 83 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 23 ] Total time taken for search is : 1250ms with total no. of matching records : 428
[ Thread-id : 35 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 46 ] Total time taken for search is : 1156ms with total no. of matching records : 428
[ Thread-id : 14 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 56 ] Total time taken for search is : 1125ms with total no. of matching records : 428
[ Thread-id : 22 ] Total time taken for search is : 1250ms with total no. of matching records : 428
[ Thread-id : 17 ] Total time taken for search is : 1266ms with total no. of matching records : 428
[ Thread-id : 49 ] Total time taken for search is : 1156ms with total no. of matching records : 428
[ Thread-id : 85 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 13 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 41 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 42 ] Total time taken for search is : 1172ms with total no. of matching records : 428
[ Thread-id : 82 ] Total time taken for search is : 1094ms with total no. of matching records : 428
[ Thread-id : 99 ] Total time taken for search is : 1062ms with total no. of matching records : 428
[ Thread-id : 96 ] Total time taken for search is : 1062ms with total no. of matching records : 428
[ Thread-id : 94 ] Total time taken for search is : 1062ms with total no. of matching records : 428
[ Thread-id : 93 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 72 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 58 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 4 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 6 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 64 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 11 ] Total time taken for search is : 1265ms with total no. of matching records : 428
[ Thread-id : 9 ] Total time taken for search is : 1265ms with total no. of matching records : 428
[ Thread-id : 62 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 63 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 7 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 65 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 5 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 1 ] Total time taken for search is : 1281ms with total no. of matching records : 428
[ Thread-id : 69 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 57 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 60 ] Total time taken for search is : 1109ms with total no. of matching records : 428
[ Thread-id : 8 ] Total time taken for search is : 1265ms with total no. of matching records : 428
[ Thread-id : 61 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 68 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 67 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 70 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 25 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 30 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 100 ] Total time taken for search is : 1046ms with total no. of matching records : 428
[ Thread-id : 71 ] Total time taken for search is : 1093ms with total no. of matching records : 428
[ Thread-id : 24 ] Total time taken for search is : 1203ms with total no. of matching records : 428
[ Thread-id : 28 ] Total time taken for search is : 1187ms with total no. of matching records : 428
[ Thread-id : 78 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 79 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 76 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 21 ] Total time taken for search is : 1234ms with total no. of matching records : 428
[ Thread-id : 81 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 84 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 98 ] Total time taken for search is : 1046ms with total no. of matching records : 428
[ Thread-id : 77 ] Total time taken for search is : 1078ms with total no. of matching records : 428
[ Thread-id : 50 ] Total time taken for search is : 1140ms with total no. of matching records : 428
[ Thread-id : 36 ] Total time taken for search is : 1171ms with total no. of matching records : 428
[ Thread-id : 26 ] Total time taken for search is : 1172ms with total no. of matching records : 428