[hibernate-commits] Hibernate SVN: r16310 - in search/trunk/src: main/java/org/hibernate/search/backend/impl and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Apr 13 18:37:42 EDT 2009


Author: sannegrinovero
Date: 2009-04-13 18:37:42 -0400 (Mon, 13 Apr 2009)
New Revision: 16310

Added:
   search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/
   search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
   search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java
Modified:
   search/trunk/src/main/docbook/en-US/modules/configuration.xml
   search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
Log:
HSEARCH-347 adding the "blackhole" backend as a tool to tweak indexing process

Modified: search/trunk/src/main/docbook/en-US/modules/configuration.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/configuration.xml	2009-04-13 17:46:22 UTC (rev 16309)
+++ search/trunk/src/main/docbook/en-US/modules/configuration.xml	2009-04-13 22:37:42 UTC (rev 16310)
@@ -367,7 +367,7 @@
 
             <entry>Out of the box support for the Apache Lucene back end and
             the JMS back end. Default to <literal>lucene</literal>. Supports
-            also <literal>jms</literal>.</entry>
+            also <literal>jms</literal> and <literal>blackhole</literal>.</entry>
           </row>
 
           <row>
@@ -852,6 +852,24 @@
         </tbody>
       </tgroup>
     </table>
+    
+    <para>To tune the indexing speed it might be useful to time the
+    object loading from database in isolation from the writes to the index.
+    To achieve this set the <literal>blackhole</literal> as worker backend and start
+    you indexing routines.
+    This backend does not disable Hibernate Search: it will still generate the needed
+    changesets to the index, but will discard them instead of flushing them to the index.
+    As opposite to setting the <literal>hibernate.search.indexing_strategy</literal>
+    to <literal>manual</literal> when using <literal>blackhole</literal> it will possibly load
+    more data to rebuild the index from associated entities.</para>
+    
+    <programlisting>hibernate.search.worker.backend blackhole</programlisting>
+    
+    <para>The recommended approach is to focus first on optimizing the object loading, and then
+    use the timings you achieve as a baseline to tune the indexing process.</para>
+    <para>The <literal>blackhole</literal> backend is not meant to be used in production, only
+    as a tool to identify indexing bottlenecks.</para>
+    
   </section>
 
   <section id="search-configuration-directory-lockfactories" revision="1">

Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java	2009-04-13 17:46:22 UTC (rev 16309)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java	2009-04-13 22:37:42 UTC (rev 16310)
@@ -23,6 +23,7 @@
 import org.hibernate.search.backend.WorkQueue;
 import org.hibernate.search.backend.WorkType;
 import org.hibernate.search.backend.configuration.ConfigurationParseHelper;
+import org.hibernate.search.backend.impl.blackhole.BlackHoleBackendQueueProcessorFactory;
 import org.hibernate.search.backend.impl.jms.JMSBackendQueueProcessorFactory;
 import org.hibernate.search.backend.impl.lucene.LuceneBackendQueueProcessorFactory;
 import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
@@ -83,6 +84,9 @@
 		else if ( "jms".equalsIgnoreCase( backend ) ) {
 			backendQueueProcessorFactory = new JMSBackendQueueProcessorFactory();
 		}
+		else if ( "blackhole".equalsIgnoreCase( backend ) ) {
+			backendQueueProcessorFactory = new BlackHoleBackendQueueProcessorFactory();
+		}
 		else {
 			try {
 				Class processorFactoryClass = ReflectHelper.classForName( backend, BatchedQueueingProcessor.class );

Added: search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java	                        (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java	2009-04-13 22:37:42 UTC (rev 16310)
@@ -0,0 +1,51 @@
+// $Id$
+package org.hibernate.search.backend.impl.blackhole;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.util.LoggerFactory;
+import org.slf4j.Logger;
+
+/**
+ * This backend does not do anything: the Documents are not
+ * sent to any index but are discarded.
+ * Useful to identify the bottleneck in indexing performance problems,
+ * fully disabling the backend system but still building the Documents
+ * needed to update an index (loading data from DB).
+ *
+ * @author Sanne Grinovero
+ */
+public class BlackHoleBackendQueueProcessorFactory implements BackendQueueProcessorFactory {
+	
+	private static final Logger log = LoggerFactory.make();
+	
+	private final NoOp noOp = new NoOp();
+	
+	public Runnable getProcessor(List<LuceneWork> queue) {
+		return noOp;
+	}
+
+	public void initialize(Properties props, SearchFactoryImplementor searchFactory) {
+		// no-op
+		log.warn( "initialized \"blackhole\" backend. Index changes will be prepared but discarded!" );
+	}
+	
+	public void close() {
+		// no-op
+		log.info( "closed \"blackhole\" backend." );
+	}
+	
+	private static class NoOp implements Runnable {
+
+		public void run() {
+			// no-op
+			log.debug( "Discarding a list of LuceneWork" );
+		}
+		
+	}
+
+}


Property changes on: search/trunk/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java	                        (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java	2009-04-13 22:37:42 UTC (rev 16310)
@@ -0,0 +1,39 @@
+// $Id$
+package org.hibernate.search.test.configuration;
+
+import junit.framework.TestCase;
+
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.blackhole.BlackHoleBackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.lucene.LuceneBackendQueueProcessorFactory;
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.test.util.FullTextSessionBuilder;
+
+/**
+ * @author Sanne Grinovero
+ */
+public class CustomBackendTest extends TestCase {
+	
+	public void test() {
+		verifyBackendUsage( "blackhole", BlackHoleBackendQueueProcessorFactory.class );
+		verifyBackendUsage( "lucene", LuceneBackendQueueProcessorFactory.class );
+		verifyBackendUsage( BlackHoleBackendQueueProcessorFactory.class );
+		verifyBackendUsage( LuceneBackendQueueProcessorFactory.class );
+	}
+	
+	private void verifyBackendUsage(String name, Class<? extends BackendQueueProcessorFactory> backendType) {
+		FullTextSessionBuilder builder = new FullTextSessionBuilder();
+		FullTextSession ftSession = builder
+			.setProperty( "hibernate.search.worker.backend", name )
+			.build();
+		SearchFactoryImpl searchFactory = (SearchFactoryImpl) ftSession.getSearchFactory();
+		assertEquals( backendType, searchFactory.getBackendQueueProcessorFactory().getClass() );
+		builder.close();
+	}
+
+	public void verifyBackendUsage(Class<? extends BackendQueueProcessorFactory> backendType) {
+		verifyBackendUsage( backendType.getName(), backendType );
+	}
+
+}


Property changes on: search/trunk/src/test/java/org/hibernate/search/test/configuration/CustomBackendTest.java
___________________________________________________________________
Name: svn:keywords
   + Id




More information about the hibernate-commits mailing list