We're updating the issue view to help you get more done. 

Generate_statistics grows QueryStatistics ConcurrentHashMap indefinitely

Description

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:

1 2 3 4 5 6 7 8 9 10 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.

Link to discourse: https://discourse.hibernate.org/t/generate-statistics-grows-querystatistics-concurrenthashmap-indefinitely/1287

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

arian

Fix versions

backPortable

Backport?

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.12

Priority

Minor