4

I'm running an application that uses hibernate search for looking up 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's working smoothly but after some higher load it turns out that pages that use the FullTextEntityManager are being loaded very slowly. And in some moments the whole application is slowing down.

So it got to my mind that maybe I'm using Hibernate search incorrectly. I'm using a startup singleton to index 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 an autocomplete component of PrimeFaces:

@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 a correct usage of Hibernate Search in a Java EE application? Isn't it possible that after a while hibernate search is trying to synchronize changes of entities and the Lucene index? If so, is it possible that it causes a huge impact on performance?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
lukas
  • 545
  • 2
  • 7
  • 18

1 Answers1

2

It is correct usage of hibernate search i would say. Its the field cache that is degrading performance for you. This is actualy query dependent. Reacd through section 5.5 here ,should be of some help.

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77
  • 1
    yea, there is not just any THE way to do it. Varies from query to query. Happy to help. Regards – Mukul Goel Oct 01 '12 at 04:43
  • @lukas , curious to know if you solved your problem? and how? – Mukul Goel Oct 10 '12 at 08:59
  • I'm still having some performance issues so I didn't try. I will put this feature back once I'm certain that I have found a cause of my problems. For now it seems that Hibernate search wasn't the cause. But not sure yet – lukas Oct 11 '12 at 20:46