Skip to content

Commit d944232

Browse files
author
Fabian Baumeister
committed
feat: Add performance rules for persistence layer
1 parent 4119344 commit d944232

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

modules/ROOT/nav.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Persistence
1313
** Relational Databases
1414
*** xref:persistence/jpa.adoc[]
15+
*** xref:persistence/performance.adoc[]
1516
*** xref:persistence/transactional.adoc[]
1617
1718
* Cross cutting
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
= Performance
2+
3+
When doing performance optimization, it's important to keep the following rules in mind.
4+
5+
== Rule 0: Measure, don't think
6+
7+
[quote,Donald E. Knuth]
8+
Premature optimization is the root of all evil.
9+
10+
Before starting to optimize any database operation, it's important to analyse the root cause by measuring the execution times.
11+
12+
== Rule 1: The performance of a use case is proportional to the number of SQL statements it generates
13+
14+
* Typical values of a query execution are `5 to 100 msec`
15+
* It has shown, that performance problems are in most cases the result of a high the number of repeated query executions (e.g. in loops) and not the queries themselfs
16+
* Before optimizing a single queries, check and if possible reduce the number of executions of it
17+
* In some rare cases the executionTime of query causes the problem and tuning the SQL or the DB is helpful
18+
* Always consider Rule 0 before applying any action
19+
20+
21+
== Rule 2: The performance of a use case is the product of objects in a session with the number of flush operations
22+
23+
In case a Object Relational Mapper (like JPA) is used and a high number of objects are in the session, then the flush operations can become a problem.
24+
25+
The default configuration read/write auto flush of JPA makes sure that prior of any query the current session is flushed, to ensure, that the query gets the latest updates from the DB.
26+
27+
If there are big datasets in the session, the flush operation can take an relativ huge amount of time. E.g. in an analytics (read only) application with lots of data, the flush would be not necessary, becasuse no data was changed. Nonetheless, it flushes the session with all data prior to any other query.
28+
29+
* In case the number of objects in the session is < 1000 there's usually not an issue
30+
* Check if the number of objects in the session is necessary, missused eager loading
31+
* Check if the flush mode can be adjusted, as in the mentioned analytics application example
32+
* Always consider Rule 0 before applying any action
33+

0 commit comments

Comments
 (0)