I am launching an application that uses sleep search to search for people in the system. I run it on JBoss AS 7.1.1, and the application is based on Seam 3, Weld, and JSF 2.1. It works smoothly, but after some higher load it turns out that pages that use the FullTextEntityManager load very slowly. And at some points the whole application slows down.
Therefore, it seemed to me that maybe I'm using Hibernate incorrectly. I use singleton to start the database:
@Singleton @Startup public class Initializer implements Serializable { private static final long serialVersionUID = 1L; @PersistenceContext private EntityManager entityManager; @PostConstruct public void startup() throws Exception { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); fullTextEntityManager.createIndexer().startAndWait(); } }
And then I use the FullTextEntityManager in the method that is used in the PrimeFaces autocomplete component:
@Session Scoped public class ... { private QueryBuilder queryBuilder; @Inject private EntityManager entityManager; @PostConstruct public void initFulltext() { fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager); queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get(); } @Override @SuppressWarnings("unchecked") public List<Person> autocomplete(Object event) throws Exception { if (event.toString() != null && !event.toString().trim().isEmpty()) { org.apache.lucene.search.Query query = queryBuilder.keyword() .onFields("username", "firstname", "lastname").matching(event.toString()) .createQuery(); FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Person.class); persistenceQuery.setMaxResults(MAX_RESULTS_ON_PAGE); return persistenceQuery.getResultList(); } return null; } }
Is this the correct use of Hibernate Search in a Java EE application? Is it not possible that after a while, a sleep search tries to synchronize changes to objects and the Lucene index? If so, is it possible that this has a huge impact on performance?
lukas source share