| We've encountered a problem with the generate_statistics configuration in production. The ConcurrentStatisticsImpl uses a ConcurrentHashMap that saves the statistics for all the HQL queries that are executed. However from our application we generate a lot of unique query HQL queries because we use the JPA query builder, and something like this: {{ public void query(int id, int userId) { // ... CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery<InboxMessage> query = builder.createQuery(InboxMessage.class); Root<InboxMessage> root = query.from(InboxMessage.class); query.where(builder.and( builder.equal(root.get(InboxMessage_.id), id)), builder.equal(root.get(InboxMessage_.inboxUser).get("id"), userId)); // ... } }} creates a new query string for each new input. This is problematic because the map only grows, and after a couple of days our application consumes too much memory. It seems possible to clear the stats periodically, however:
- the default behavior 'leaks' memory
- it's not documented
So perhaps it'd be better to have a default max_size option or something to limit the size of the queryStatistics. |