The document provides a comprehensive guide on Hibernate performance tuning, covering topics such as measuring performance, optimizing JDBC connections, and utilizing various fetching strategies. It suggests best practices like using native queries, effective batching, and managing entity states to enhance performance. Additionally, it offers links to resources, tools, and further readings for developers looking to improve their understanding and implementation of Hibernate.
Introduction to Hibernate performance tuning presented by Mikalai Alimenkou and Igor Dmitriev. Personal experience disclaimer and code samples available on GitHub.
Introduction to Hibernate performance tuning presented by Mikalai Alimenkou and Igor Dmitriev. Personal experience disclaimer and code samples available on GitHub.
Insights into what Hibernate does and its full execution chain are discussed, setting the foundation for performance tuning.
Measuring performance using Hibernate statistics and benchmarks with JMH. Understanding and tracing through datasource proxies and SQL logging are key techniques.
Tips for JDBC tuning include using a robust connection pool and addressing N + 1 lazy loading issues with various fetching strategies.
Batching operations to manage memory and enhance performance, leveraging the second-level cache, and discussing cache strategies is essential.
Batching operations to manage memory and enhance performance, leveraging the second-level cache, and discussing cache strategies is essential.
Strategies for optimizing transactions include marking requests appropriately and using DTOs. Avoid updating all columns and managing ID generation effectively.
Strategies for optimizing transactions include marking requests appropriately and using DTOs. Avoid updating all columns and managing ID generation effectively.
Strategies for optimizing transactions include marking requests appropriately and using DTOs. Avoid updating all columns and managing ID generation effectively.
Strategies for optimizing transactions include marking requests appropriately and using DTOs. Avoid updating all columns and managing ID generation effectively.
Recommendations for using native queries strategically, implementing CQRS, and additional resources and reading materials to further explore Hibernate performance.
Recommendations for using native queries strategically, implementing CQRS, and additional resources and reading materials to further explore Hibernate performance.
JDBC tuning
• Usegood implementation of connection pool
• Batching, fetching
• Switch to native queries where performance is
critical
• Do direct JDBC stuff with Session doWork
Operations batching
• FlushSession state to avoid memory issues
• Use JDBC batching options
in order to mix statements for different tables
• Deletes are batched only for the same table
Mark lightweight requests
•Read-only flag for transactions
• Choose appropriate transaction isolation level
• Annotate entity as immutable if it is not
updated anywhere
• Use StatelessSession for some operations
25.
Don’t use entitieseverywhere
• ResultTransformer and Transformers
• Fields map instead of object
• @SqlResultSetMapping
• Direct mapping on DTO
27.
Don’t update allcolumns
• Dynamic insert, update
• Update only changed columns
• Be careful with number of PreparedStatement
29.
Slow ID generation
•Id generator mapping
• Don’t use GenerationType.AUTO, use
GenerationType.SEQUENCE instead
• Try to generate ID/PK in the
code, not delegate to Hibernate
30.
Other advices
• Usenative queries if really helpful:
– “ORDER BY NULL” or “DELETE with JOIN” in
MySQL
– Effective data removal
• Don’t use lists, arrays and ordering in
Hibernate
#7 TODO: поставить правильную ссылку и перегенерить QR код
#14 На демо показываем:
как сконфигурировать и показывать статистику
как контролировать количество запросов в тестах
#17 На демо показываем:
N + 1 проблему
разные стратегии вычитки (join, subselect, batching)
применение графов сущностей
blind guess loading (несколько наперед чтобы экономить запросы)
применение фетча для одного запроса !!! объяснить
#23 На демо показываем:
как настроить second level кэш !!! не показывыем
как работает second level кэш
как что кешируется (сущности, коллекции) !!! не показываем
query cache и его взаимодействие с second level cache
#25 На демо показываем:
как отключается dirty checking
пример работы через StatelessSession !!! не показывать
#27 На демо показываем:
примеры трансформации результов
маппинг на DTO прямой
#29 На демо показываем:
- вставку и обновление сущности с включенными флагами