I am writing a Play 2.2.1 application to display the content of very large postgres tables (at least O(10^8)). To do this I modified the the computer database sample database.
My page method is almost directly taken from the computer class in the example:
public static Page<Lemma> page(int page, int pageSize, String sortBy, String order, String filter) {
if(filter.isEmpty()) {
return
find.where()
.findPagingList(pageSize)
.setFetchAhead(true)
.getPage(page);
} else {
return
find.where()
.ilike("name", "%" + filter + "%")
.orderBy(sortBy + " " + order)
.findPagingList(pageSize)
.setFetchAhead(true)
.getPage(page);
}
}
If the filter is empty, for performance issues I avoid any ordering. I my toy DB with 20,000,000 entries it works well, but with a more realistic example of 200,000,000 documents I always got timed-out connections.
The "name" column is indexed, and querying directly the database is very fast. I always run with the "-Xmx4096m" option for JVM.
What I am missing? What I am doing wrong? Any suggestion?
Update
The bottleneck seems to be the query SELECT COUNT(*) FROM lemma t0 ...
, that is sent to display the number of documents found. Any idea to improve performance? Any suggestion for implementing a cursor in ebean as suggested by Peter?