Java for ultra low
latency applications
Rafael Monteiro e Pereira
Software Engineer
What is Latency ?
• From the Queueing Theory
What is Latency ?
• From the Queueing Theory
- Thread Communication
- Memory Management
Thread Communication
• Just Create a Queue right ?
• You are sure that you wanna block ?
• https://github.com/real-logic/benchmarks
Thread Communication
• Burst (100 messages)
LinkedBlockingQueue 154 μs
ArrayBlockingQueue 56 μs
ConcurrentLinkedQueue 44 μs
Disruptor 3.0 20 μs
Thread Communication
• Disruptor (https://github.com/LMAX-Exchange/disruptor )
• Very fast Inter-Thread Message Library
Source: https://martinfowler.com/articles/images/lmax/arch-full.png
GC - CMS
Freeze!
GC - G1
Freeze!
Off-Heap Allocation
• Allocates memory outside the Heap
• HARD ! Really !
Off-Heap Allocation
• Copy Object outside the Heap
Off-Heap Allocation
• Use a LIB !
• Open HFT -> https://github.com/OpenHFT
• https://github.com/OpenHFT/Java-Thread-Affinity
• https://github.com/OpenHFT/Chronicle-Queue
• https://github.com/OpenHFT/Chronicle-Logger
• Some Tips
• Be careful with big Heap sizes. Usually is not a good idea to go beyond
16 GB on Hotspot.
• Big Heap == Slow GC !!! Consider using off-heap allocation if a lot of
information must be maintained in memory.
Obrigado!!!!
Feedback ? Contato ?
E-mail: rafael@monteiro.io
Github: github.com/rafamonteiro
Twitter: @monteiro_io
LinkedIn: lnked.in/rafamonteiro

Java for ultra low latency applications