Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose per-region statistics for Hibernate L2 cache #2097

Closed
kennymacleod opened this issue May 15, 2020 · 4 comments · Fixed by #2108
Closed

Expose per-region statistics for Hibernate L2 cache #2097

kennymacleod opened this issue May 15, 2020 · 4 comments · Fixed by #2108
Labels
enhancement A general enhancement
Milestone

Comments

@kennymacleod
Copy link
Contributor

kennymacleod commented May 15, 2020

As of Micrometer 1.5, the HibernateMetrics binder exposes L2 cache statistics from the org.hibernate.stat.Statistics interface. This is useful, but it would be better if this were done on a per-cache-region basis, giving us more fine-grained per-entity and per-collection information.

This can be done by using getSecondLevelCacheRegionNames and getSecondLevelCacheStatistics, giving you a SecondLevelCacheStatistics object.

As well as providing the same hit/miss/put stats you get from the higher-level Statistics interface, you also get cache size and memory usage stats. These can then be tagged with the region name.

@jkschneider
Copy link
Contributor

Nice! Let's do this.

@jkschneider jkschneider added this to the 1.x milestone May 15, 2020
@jkschneider jkschneider added enhancement A general enhancement help wanted An issue that a contributor can help us with labels May 15, 2020
kennymacleod added a commit to kennymacleod/micrometer that referenced this issue May 17, 2020
@shakuzen
Copy link
Member

I'm not familiar with L2 cache regions. Are these static or dynamic? Will we know at binding time what all the regions are, or could they change?

@shakuzen shakuzen modified the milestones: 1.x, 1.6.0 May 20, 2020
@kennymacleod
Copy link
Contributor Author

Good question, @shakuzen. My assumption was that once the SessionFactory is up and running, the set of regions is immutable. I just had a rummage through the Hibernate 5.2 codebase, and this does indeed seem to be the case. While the set of regions is mutable (for addition only) in the Statistics implementation class, this only occurs in the SessionFactoryImpl constructor. After that, there's no way to change them.

kennymacleod added a commit to kennymacleod/micrometer that referenced this issue May 26, 2020
@shakuzen shakuzen changed the title Expose per-region statistics for Hibernate 2 cache Expose per-region statistics for Hibernate L2 cache Oct 29, 2020
shakuzen pushed a commit that referenced this issue Oct 29, 2020
This tags the L2 cache stats counters by region so more fine-grained information is available (per entity/collection). The totals available before are the sum of all the regions, and therefore still available with summing.

Resolves #2097
@shakuzen
Copy link
Member

Looks like the method getSecondLevelCacheStatistics has been deprecated since Hibernate 5.3. I have switched to the recommended non-deprecated replacement getDomainDataRegionStatistics in e6ae7ba and things appear to work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants