The High-Performance Java Persistence book

A book in the making It’s been a year since I started the quest for a highly-effective Data Knowledge Stack and the Hibernate Master Class contains over fifty articles already. Now that I covered many aspects of database transactions, JDBC and Java Persistence, it’s time to assemble all the pieces together into the High-Performance Java Persistence book.

How to monitor a Java EE DataSource

Introduction FlexyPool is an open-source framework that can monitor a DataSource connection usage. This tool come out of necessity, since we previously lacked support for provisioning connection pools. FlexyPool was initially designed for stand-alone environments and the DataSource proxy configuration was done programmatically. Using Spring bean aliases, we could even substitute an already configured DataSource with the FlexyPool Metrics-aware proxy alternative.

How to optimize unidirectional collections with JPA and Hibernate

Introduction Hibernate supports three data mapping types: basic (e.g String, int), Embeddable and Entity. Most often, a database row is mapped to an Entity, each database column being associated to a basic attribute. Embeddable types are more common when combining several field mappings into a reusable group (the Embeddable being merged into the owning Entity mapping structure). Both basic types and Embeddables can be associated to an Entity through the @ElementCollection, in a one-Entity-many-non-Entity relationship. Although we are going to explain these optimizations using an @ElementCollection, the same rules apply to any… Read More

JDBC Statement fetchSize property

Introduction In this article, we are going to see how the JDBC Statement fetchSize property works when using Oracle, SQL Server, PostgreSQL, or MySQL. JDBC ResultSet fetching The JDBC ResultSet offers a client-side cursor for fetching the current statement return data. When the statement gets executed, the result must be transferred from the database cursor to the client-side one. This operation can either be done at once or on demand.

How to batch DELETE statements with Hibernate

Introduction In my previous post, I explained the Hibernate configurations required for batching INSERT and UPDATE statements. This post will continue this topic with DELETE statements batching. Domain model entities We’ll start with the following entity model:

How to batch INSERT and UPDATE statements with Hibernate

Introduction JDBC has long been offering support for DML statement batching. By default, all statements are sent one after the other, each one in a separate network round-trip. Batching allows us to send multiple statements in one-shot, saving unnecessary socket stream flushing. Hibernate hides the database statements behind a transactional write-behind abstraction layer. An intermediate layer allows us to hide the JDBC batching semantics from the persistence layer logic. This way, we can change the JDBC batching strategy without altering the data access code. Configuring Hibernate to support JDBC batching is not… Read More

Java Performance Workshop with Peter Lawrey

Peter Lawrey at IT Days I’ve just come back from a Java Performance Workshop held by Peter Lawrey at Cluj-Napoca IT Days. Peter Lawrey is a well-known Java StackOverflow user and the creator of Java Chronicle open-source library. Of Java and low latency Little’s Law defines concurrency as: To increase throughput we can either: increase server resources (scaling vertically or horizontally) decrease latency (improve performance) While enterprise applications are usually designed for scaling, trading systems focus on lowering latencies. As surprising as it may sound, most trading systems, I’ve heard of, are… Read More

How does the bytecode enhancement dirty checking mechanism work in Hibernate 4.3

Introduction Now that you know the basics of Hibernate dirty checking, we can dig into enhanced dirty checking mechanisms. While the default graph-traversal algorithm might be sufficient for most use-cases, there might be times when you need an optimized dirty checking algorithm and instrumentation is much more convenient than building your own custom strategy. Using Ant Hibernate Tools Traditionally, The Hibernate Tools have been focused on Ant and Eclipse. Bytecode instrumentation has been possible since Hibernate 3, but it required an Ant task to run the CGLIB or Javassist bytecode enhancement routines.

The simple scalability equation

Queuing Theory The queueing theory allows us to predict queue lengths and waiting times, which is of paramount importance for capacity planning. For an architect, this is a very handy tool since queues are not just the appanage of messaging systems. To avoid system over loading we use throttling. Whenever the number of incoming requests surpasses the available resources, we basically have two options: discarding all overflowing traffic, therefore decreasing availability queuing requests and wait (for as long as a time out threshold) for busy resources to become available This behavior applies… Read More

Professional connection pool sizing with FlexyPool

Introduction I previously wrote about the benefits of connection pooling and why monitoring it is of crucial importance. This post will demonstrate how FlexyPool can assist you in finding the right size for your connection pools. Know your connection pool The first step is to know your connection pool settings. My current application uses XA transactions, therefore we use Bitronix transaction manager, which comes with its own connection pooling solution. Accord to the Bitronix connection pool documentation we need to use the following settings: minPoolSize: the initial connection pool size maxPoolSize: the… Read More