Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current Restore this Version View Page History

« Previous Version 5 Next »

Overview

Fabric3 provides support for ring buffer channels based on the LMAX Disruptor. Ring buffer channels are particularly useful in latency-sensitive applications as they reduce contention an unnecessary object allocation. The default channel implementation uses the runtime ExecutorService to schedule asynchronous event dispatch on a pooled thread. Placing work on the ExecutorService pool can result in contention and object creation, which can be prohibitive in the most demanding high performance applications.

 

Ring buffer channels are designed to avoid contention by placing events on a circular buffer implementation, in this case the LMAX Disruptor. Consumers running on different threads receive events from the buffer. Using Disruptor-based channels is simple. All that needs to be done is to specify the ring.buffer channel type as shown below:

 

<composite ...>
   <channel name="OrderChannel" type="ring.buffer"/>
</composite> 

No special coding is required for producers and consumers:

public void class OrderPlacer ... {
 
   @Producer
   protected OrderChannel channel;
 
   public void placeOrder(Order order) {
      channel.publish(order);
   }
 
} 
public void class OrderTaker ... {
 
   @Consumer
  public void onOrder(Order order) {
      ....
   }
 
} 

Configuration

Ring buffer channels have the following configuration options:

  • ring.size - The number of elements (slots) to create in the ring buffer. 
  • wait.strategy - The consumer wait strategy. Valid values are LOCKING, YIELDING, SLEEPING, BACKOFF, SPIN, and TIMEOUT.
  • blocking.timeout - The consumer blocking timeout in nanoseconds.
  • spin.timeout - The consumer spin timeout in nanoseconds.
  • yield.timeout - The consumer yield timeout in nanoseconds.
  • phased.blocking.type - The phased blocking type. Valid values are LOCK and SLEEP.

For more information on these values, refer to the LMAX Disruptor site.

Bindings

Disruptor-based channels may be combined with messaging technologies such as The ZeroMQ Binding to create high performance distributed services. The FastQuote sample application demonstrates using ring buffer channels in conjunction with ZeroMQ and Google Protocol Buffers in a trading application that achieves microsecond processing times. For more details, see the respective binding sections.

 

Performance Tuning

By default, Fabric3 uses JDK proxies to create producer proxies. JDK proxies are less performant than handwritten code and allocate objects during invocation (for example, an array to create parameter values). Fabric3 provides an optional extension that uses bytecode generation to create proxies. This results in proxies that are as fast as handwritten code and do not allocate objects during invocation. To enable bytecode generation, the fabric3-bytecode-proxy module must be installed in the runtime. Its maven coordinates are org.codehaus.fabric3:fabric3-bytecode-proxy.