4. @vlad_mihalcea vladmihalcea.com
Google Ranking
βLike us, our users place a lot of value in speed β
that's why we've decided to take site speed
into account in our search rankingsβ
https://webmasters.googleblog.com/2010/04/using-site-speed-in-web-search-ranking.html
5. @vlad_mihalcea vladmihalcea.com
Performance and Revenue
βIt has been reported that every 100ms of latency
costs Amazon 1% of profitβ
http://radar.oreilly.com/2008/08/radar-theme-web-ops.html
8. @vlad_mihalcea vladmihalcea.com
Response Time
β’ connection acquisition time
β’ statement submit time
β’ statement execution time
β’ result set fetching time
β’ idle time prior to releasing database connection
π = π‘ πππ + π‘ πππ + π‘ ππ₯ππ + π‘ πππ + π‘ππππ
26. @vlad_mihalcea vladmihalcea.com
IDENTITY
β’ In Hibernate, IDENTITY generator disables JDBC batch inserts
β’ MySQL 8.0 does not offer support for database SEQUENCE
β’ MariaDB 10.3 adds support for SEQUENCE objects
27. @vlad_mihalcea vladmihalcea.com
SEQUENCE
β’ Oracle, PostgreSQL, and even SQL Server 2012
β’ May use roundtrip optimizers: hi/lo, pooled, pooled-lo
β’ By default, Hibernate 5 uses the enhanced sequence generators
<property
name="hibernate.id.new_generator_mappings"
value="true"/>
28. @vlad_mihalcea vladmihalcea.com
The pooled optimizer
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "pooled"
)
@SequenceGenerator(
name = "pooled",
allocationSize = 3
)
private Long id;
35. @vlad_mihalcea vladmihalcea.com
TABLE
β’ Uses row-level locks and a separate transaction/connection
β’ May use roundtrip optimizers: hi/lo, pooled, pooled-lo
β’ By default, Hibernate 5 uses the enhanced sequence generators
<property
name="hibernate.id.new_generator_mappings"
value="true"/>
37. @vlad_mihalcea vladmihalcea.com
IDENTITY vs TABLE (100 rows)
β’ IDENTITY makes no use of batch inserts
β’ TABLE generator using a pooled optimizer with an increment size of
100
39. @vlad_mihalcea vladmihalcea.com
AUTO: IDENTITY vs TABLE?
β’ Prior to Hibernate 5, AUTO would resolve to IDENTITY if the
database supports this feature
β’ Hibernate 5 uses TABLE generator if the database does not support
sequences
β’ So, pay attention when using MySQL or MariaDB (prior to 10.3)
53. @vlad_mihalcea vladmihalcea.com
Batching β @Version
<property
name="hibernate.jdbc.batch_versioned_data"
value="true"/>
β’ Enabled by default in Hibernate 5
β’ Disabled in Hibernate 3.x, 4.x, and for Oracle 8i, 9i, and 10g
dialects
61. @vlad_mihalcea vladmihalcea.com
Fetching β Pagination
β’ Hibernate uses OFFSET pagination
β’ Keyset pagination scales better when navigating large result sets
β’ http://use-the-index-luke.com/no-offset
62. @vlad_mihalcea vladmihalcea.com
Fetching β Entity vs Projection
β’ Selecting all columns vs a custom projection
SELECT *
FROM post_comment pc
INNER JOIN post p ON p.id = pc.post_id
INNER JOIN post_details pd ON p.id = pd.id
SELECT pc.version
FROM post_comment pc
INNER JOIN post p ON p.id = pc.post_id
INNER JOIN post_details pd ON p.id = pd.id
69. @vlad_mihalcea vladmihalcea.com
Fetching β Temporary Session Anti-Pattern
β’ βBand aidβ for LazyInitializationException
β’ One temporary Session/Connection for every lazily fetched
association
<property
name="hibernate.enable_lazy_load_no_trans"
value="true"/>
73. @vlad_mihalcea vladmihalcea.com
Caching β Why 2nd - Level Caching
βThere are only two hard things in Computer
Science: cache invalidation and naming things.β
Phil Karlton