Lucene IndexSearcher

We launched a new version of one of our websites that was rewritten in Java (formerly in Perl).

The site drains quite a lot of traffic and I had made very few benchmarks during development phase. When I finally started load testing I realized that the site was performing well in the beginning but after a few minutes it was getting slower and slower ..

I isolated the problem in the Lucene search section. After reading a little more about the IndexSearcher object it finally hit me.

A new IndexSearcher object was created for every search which is definately not the correct way of using it. IndexSearcher is a heavy object and can (and should) be shared by multiple clients (it is threadsafe). The only thing you should of course, is recreate it when the index changes (on index updates and deletes).

After this little incident, I must say I am really amazed at the overall performance of the site, it runs like a charm on Tomcat 5.5 with MySQL behind using a classical JSP 2.0 Struts – IBatis – stack, nothing fancy, no spring, no hibernate, etc ..

P.

Leave a comment

Your email will not be published. Required fields are marked *.