3. @aalmiray
THE SETTING (1)
A customer had a working JEE application
with a mix of several technologies and
desired to consolidate everything under
one banner: JBoss.
The application relied on EclipseLink as a
JPA provider.
4. @aalmiray
THE SETTING (2)
L2C caching was enabled (super easy with
EclipseLink) resulting in fast response
times when loading medium to big sized
datasets.
Average response time with a typical
dataset was in the 2..4 seconds range.
5. @aalmiray
THE PROBLEM
Once migration to Hibernate occurred the
response times went down the drain.
Average response time was in the 40..80
seconds range.
Setting up L2C for Hibernate required more
work than EclipseLink.
6. @aalmiray
MEASUREMENTS
Response times were clocked using both
manual approach and fumbling around with
log files, which lead to:
- Human error
- Inaccurate measurements
- Unrepeatable conditions
7. @aalmiray
GOAL
Could L2C & Hibernate be configured in
such a way that it results in similar (or
better) performance as provided by
EclipseLink?
Is there a JBoss friendly alternative?
11. @aalmiray
WRITE A JUNIT TEST
What better way there is to exercise some
code than running it through a test case?
Scenario:
- Load the data using EntityManager #1
which warms up the cache.
- Run another query with EntityManager
#2 which should hit the cache.
- Profit!
12. @aalmiray
TEST CONDITIONS
- Chosen database was H2 in embedded
mode.
- Dataset comprised of 6000 entities.
- Simple parent-child relationship between
2 entities.
- All queries were read-only.
- 50 iterations.
13. @aalmiray
TEST CANDIDATES
- EclipseLink would be the control.
- Hibernate without caching would serve
as a base for all other Hibernate
measurements.
- All caching providers must use default
configuration.
14. @aalmiray
ITERATIONS
@Test
public void first_test() throws Exception {
int entityCount = ENTITY_COUNT_SMALL;
setupDataset(entityCount);
List<List<Measurement>> measurements = new ArrayList<>();
for (int i = 0; i < ITERATION_COUNT; i++) {
measurements.add(executeBenchmark(entityCount, i));
}
writeReports(measurements, getTestName());
}
19. @aalmiray
MORE PROBLEMS
- In a real world scenario concurrent
queries would be executed. Our queries
are executed in a serial way.
- Dataset is small to fit in the cache. We
did not test when cache evictions
occurred, which is also likely to happen
in the real world.
21. @aalmiray
TEST CONDITIONS
- Additional operations once L2C is
warmed up:
- Hit L1C
- Clear L1C-> L1C loaded from L2C
- Clear L1C & L2C -> loads L2C -> L1C
- Hit L1C one more time
- Same operations but in concurrent
mode.
- Bigger dataset +60K entities
22. @aalmiray
TEST CODE
- Concurrent tests rely on
ExecutorService, CountDownLatch, and
other tricks.
- Infrastructure code (measurements)
entangled with operation code (what we
want to measure).
- Not showing it due to ugliness.
25. @aalmiray
CONCLUSIONS
- Both Hazelcast and Caffeine perform
pretty well, in some cases even better
than EclipseLink.
- Infinispan is left in third.
- EhCache + default configuration + cache
eviction => pain.
27. @aalmiray
MORE PROBLEMS
- Test code is quickly becoming
unmanageable and unreadable.
- What about GC pauses and other JVM
events that may affect measurements?
- Not taking advantage of jitted code.
- Have we really achieved the fastest
setup?
29. @aalmiray
JMH TO THE RESCUE
- JMH can be used for all kind of
benchmarks, not just the tiny, micro,
pico ones.
- Decided to benchmark the simplest case
only, that is, load L2C and hit it once per
iteration.
36. @aalmiray
CONCLUSIONS
- Both Hazelcast and Caffeine perform
pretty well, again.
- Infinispan is left in third.
- EhCache + big datasets => we have to
talk
38. @aalmiray
DATA SAYS
- The winner is Hazelcast given
- Small and Big datasets
- However
- The database server was not production
quality.
- Production queries require mutation of
values, not just read-only.
- Customer would like a JBoss solution.
40. @aalmiray
INFINISPAN + JBOSS EAP
- We tested Infinispan on a production
quality environment.
- Infinispan turned out to be much better,
it even smoked EclipseLink on most
queries (20% faster on average).
42. @aalmiray
PRAGMATIC PERFORMANCE
Pragmatic: dealing with things sensibly and
realistically in a way that is based on
practical rather than theoretical
considerations.
QCon San Paulo 2015 Keynote by Gil Tene
http://qconsp.com/sp2015/system/files/keynotes-
slides/Qcon_Sao_Paulo_Keynote_March2015.pdf
43. @aalmiray
WHAT WE DID IN THE
BENCHMARK
- Stripped down the code to its bare
minimum.
- Used non production database.
- Used non production hardware.
- We basically cheated by removing
“weight” and only succeeded to obtain
an upper bound.
44. @aalmiray
TESTS VS JMH
Tests can exercise scenarios that are more
difficult to setup using benchmarks.
JMH provides a lot of infrastructure
“almost for free”.
Numbers obtained by both tests and
benchmarks serve as a guideline.
45. @aalmiray
PARTING THOUGHTS
- Beware of preconceptions and
confirmation bias.
- Be mindful of the shape of the input
data.
- Always mind the system’s environment.
- Approach results skeptically.
- Iterate, iterate, iterate.
46. @aalmiray
“If we have data, let’s look at data. If all we
have are opinions, let’s go with mine.”
Jim Barksdale