SlideShare a Scribd company logo
Peter Lawrey
CEO of Higher Frequency Trading
JAX Finance 2015
Determinism in Finance
Peter Lawrey
Java Developer/Consultant for hedge fund and trading firms for 6
years.
Most answers for Java and JVM on stackoverflow.com
Founder of the Performance Java User’s Group.
Architect of Chronicle Software
Agenda
• Lambda functions and state machines
• Record every input
• Determinism by Design
• Record every output
• Java 8 and Garbage
• Chronicle Queue demo
Lambda Functions
• No mutable state
• Easy to reason about
• Easy to componentize
• But … no mutable state.
State Machine
• Local mutable state
• Easier to reason about,
than shared state
• Easier to componentize
• Not as simple as Lambda
Functions
Lambda functions and a state machine
Record every input
• By recording every input you can recreate the state of the
system at any point and recreate bugs, test rare conditions, and
test the latency distribution of your system.
But
• This approach doesn’t support software upgrades.
• A replay facility which is implemented after the fact might not
recreate your system completely.
Determinism by design
• You want a system where producers write every event, and
consumers and continuously in replay. This way you can be
sure that you have this facility early in the development cycle
and you know that you have recorded every event/input.
• This facility can help you in the testing of your system by
allowing to you build small simple tests to huge complex data
driven tests.
Record every output
• Supports live software upgrades. By recording and replaying
outcome you can have a system which commits to any decision
the previous one made. Ie you can change the software to
make different decisions.
• This can be tested at the API level by having two state
machines, where the input of one is the output of the other.
Isn’t writing to disk slow?
• Uncommitted synchronous writes can be extremely fast.
Typically around a micro-second. The writes are synchronous
to the application so data is not lost if the application dies, but
not actually committed to disk.
• To prevent loss of data on power failure, you can use
replication.
Doesn’t the GC stop the world?
• The GC only pauses the JVM when it has some work to do.
Produce less garbage and it will pause less often
• Produce less than 1 GB/hour of garbage and you can get less
than one pause per day. (With a 24 GB Eden)
Do I need to avoid all objects?
• In Java 8 you can have very short lived objects placed on the
stack. This requires your code to be inlined and escape analysis
to kick in. When this happens, no garbage is created and the
code is faster.
• You can have very long lived objects, provided you don’t have
too much.
• The rest of your data you can place in native memory (off
heap)
• You can create 1 GB/hour of garbage and still not GC
Do I need to avoid all objects?
• In Java 8 you can have very short lived objects placed on the
stack. This requires your code to be inlined and escape analysis
to kick in. When this happens, no garbage is created and the
code is faster.
• You can have very long lived objects, provided you don’t have
too much.
• The rest of your data you can place in native memory (off
heap)
• You can create 1 GB/hour of garbage and still not GC
How does Java 8 avoid creating objects?
One way to think of Java 8 lambdas is the ability to pass behaviour
to a library. With inlining, an alternative view is the ability to
template your code. Consider this locking example
lock.lock();
try {
doSomething();
} finally {
lock.unlock();
}
How does Java 8 avoid creating objects?
This boiler place can be templated
public static void withLock(Lock lock,
Runnable runnable) {
lock.lock();
try {
runnable.run();
} finally {
lock.unlock();
}
}
How does Java 8 avoid creating objects?
This simplifies the code to be
withLock(lock, () -> doSometing());
Doesn’t using a Runnable create an object?
With inlining and escape analysis the Runnable can be placed on
the stack and eliminated (as it has no fields)
A low latency with fail over
• Data sent between
servers is half round
trip.
• Inputs are written on
both servers.
• Outputs are written on
both servers.
• The end to end latency
can be 25 µs, 99% of
the time.
Demo from http://chronicle.software/products/chronicle-queue/
Next Steps
• Chronicle is open source so you can start right away!
• Working with clients to produce Chronicle Enterprise
• Support contract for Chronicle and consultancy
Q & A
Peter Lawrey
@PeterLawrey
http://chronicle.software
http://vanillajava.blogspot.com

More Related Content

PPT
GC free coding in @Java presented @Geecon
ODP
Low level java programming
PPTX
Deterministic behaviour and performance in trading systems
ODP
Writing and testing high frequency trading engines in java
PPT
Advanced off heap ipc
PPT
High Frequency Trading and NoSQL database
PPTX
Responding rapidly when you have 100+ GB data sets in Java
PPTX
Low latency for high throughput
GC free coding in @Java presented @Geecon
Low level java programming
Deterministic behaviour and performance in trading systems
Writing and testing high frequency trading engines in java
Advanced off heap ipc
High Frequency Trading and NoSQL database
Responding rapidly when you have 100+ GB data sets in Java
Low latency for high throughput

What's hot (20)

PPTX
Low latency microservices in java QCon New York 2016
PPT
Open HFT libraries in @Java
PPTX
Microservices for performance - GOTO Chicago 2016
PPTX
Chronicle accelerate building a digital currency
PPT
Thread Safe Interprocess Shared Memory in Java (in 7 mins)
PPT
Introduction to OpenHFT for Melbourne Java Users Group
PPTX
Low latency in java 8 v5
PPT
Introduction to chronicle (low latency persistence)
PPT
Reactive programming with examples
PDF
Java in High Frequency Trading
PPTX
Low latency in java 8 by Peter Lawrey
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
PDF
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
PDF
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
PDF
Performance Tuning - Understanding Garbage Collection
PDF
Mantis qcon nyc_2015
PDF
Keeping Latency Low and Throughput High with Application-level Priority Manag...
PDF
Using eBPF to Measure the k8s Cluster Health
PDF
Using SLOs for Continuous Performance Optimizations of Your k8s Workloads
PPTX
Webinar patterns anti patterns
Low latency microservices in java QCon New York 2016
Open HFT libraries in @Java
Microservices for performance - GOTO Chicago 2016
Chronicle accelerate building a digital currency
Thread Safe Interprocess Shared Memory in Java (in 7 mins)
Introduction to OpenHFT for Melbourne Java Users Group
Low latency in java 8 v5
Introduction to chronicle (low latency persistence)
Reactive programming with examples
Java in High Frequency Trading
Low latency in java 8 by Peter Lawrey
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
Performance Tuning - Understanding Garbage Collection
Mantis qcon nyc_2015
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Using eBPF to Measure the k8s Cluster Health
Using SLOs for Continuous Performance Optimizations of Your k8s Workloads
Webinar patterns anti patterns
Ad

Viewers also liked (7)

PPT
Streams and lambdas the good, the bad and the ugly
PPTX
Legacy lambda code
PPTX
Big Data for Finance – Challenges in High-Frequency Trading
PPTX
Using MongoDB As a Tick Database
PPT
MongoDB Tick Data Presentation
PPTX
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
PDF
FPGA CEP Appliance
Streams and lambdas the good, the bad and the ugly
Legacy lambda code
Big Data for Finance – Challenges in High-Frequency Trading
Using MongoDB As a Tick Database
MongoDB Tick Data Presentation
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
FPGA CEP Appliance
Ad

Similar to Determinism in finance (20)

ODP
Java Garbage Collection, Monitoring, and Tuning
PPTX
Lambdas puzzler - Peter Lawrey
PDF
What's New in IBM Java 8 SE?
PPTX
Getting ready to java 8
PPTX
Getting ready to java 8
PPT
Optimizing your java applications for multi core hardware
PPT
Java Performance Monitoring & Tuning
PDF
Java 8 features
PPTX
Java garbage collection & GC friendly coding
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
PPTX
Java_Interview Qns
PDF
Java 8 selected updates
PPT
Reliable and Concurrent Software - RT Java
PDF
Java Concurrency Quick Guide
PDF
Demystifying Garbage Collection in Java
PDF
Java Performance and Using Java Flight Recorder
ODP
Best practices in Java
PDF
Designing and coding Series 40 Java apps for high performance
PPTX
(java2days) Is the Future of Java Cloudy?
PDF
How long can you afford to Stop The World?
Java Garbage Collection, Monitoring, and Tuning
Lambdas puzzler - Peter Lawrey
What's New in IBM Java 8 SE?
Getting ready to java 8
Getting ready to java 8
Optimizing your java applications for multi core hardware
Java Performance Monitoring & Tuning
Java 8 features
Java garbage collection & GC friendly coding
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Java_Interview Qns
Java 8 selected updates
Reliable and Concurrent Software - RT Java
Java Concurrency Quick Guide
Demystifying Garbage Collection in Java
Java Performance and Using Java Flight Recorder
Best practices in Java
Designing and coding Series 40 Java apps for high performance
(java2days) Is the Future of Java Cloudy?
How long can you afford to Stop The World?

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MIND Revenue Release Quarter 2 2025 Press Release
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Determinism in finance

  • 1. Peter Lawrey CEO of Higher Frequency Trading JAX Finance 2015 Determinism in Finance
  • 2. Peter Lawrey Java Developer/Consultant for hedge fund and trading firms for 6 years. Most answers for Java and JVM on stackoverflow.com Founder of the Performance Java User’s Group. Architect of Chronicle Software
  • 3. Agenda • Lambda functions and state machines • Record every input • Determinism by Design • Record every output • Java 8 and Garbage • Chronicle Queue demo
  • 4. Lambda Functions • No mutable state • Easy to reason about • Easy to componentize • But … no mutable state.
  • 5. State Machine • Local mutable state • Easier to reason about, than shared state • Easier to componentize • Not as simple as Lambda Functions
  • 6. Lambda functions and a state machine
  • 7. Record every input • By recording every input you can recreate the state of the system at any point and recreate bugs, test rare conditions, and test the latency distribution of your system. But • This approach doesn’t support software upgrades. • A replay facility which is implemented after the fact might not recreate your system completely.
  • 8. Determinism by design • You want a system where producers write every event, and consumers and continuously in replay. This way you can be sure that you have this facility early in the development cycle and you know that you have recorded every event/input. • This facility can help you in the testing of your system by allowing to you build small simple tests to huge complex data driven tests.
  • 9. Record every output • Supports live software upgrades. By recording and replaying outcome you can have a system which commits to any decision the previous one made. Ie you can change the software to make different decisions. • This can be tested at the API level by having two state machines, where the input of one is the output of the other.
  • 10. Isn’t writing to disk slow? • Uncommitted synchronous writes can be extremely fast. Typically around a micro-second. The writes are synchronous to the application so data is not lost if the application dies, but not actually committed to disk. • To prevent loss of data on power failure, you can use replication.
  • 11. Doesn’t the GC stop the world? • The GC only pauses the JVM when it has some work to do. Produce less garbage and it will pause less often • Produce less than 1 GB/hour of garbage and you can get less than one pause per day. (With a 24 GB Eden)
  • 12. Do I need to avoid all objects? • In Java 8 you can have very short lived objects placed on the stack. This requires your code to be inlined and escape analysis to kick in. When this happens, no garbage is created and the code is faster. • You can have very long lived objects, provided you don’t have too much. • The rest of your data you can place in native memory (off heap) • You can create 1 GB/hour of garbage and still not GC
  • 13. Do I need to avoid all objects? • In Java 8 you can have very short lived objects placed on the stack. This requires your code to be inlined and escape analysis to kick in. When this happens, no garbage is created and the code is faster. • You can have very long lived objects, provided you don’t have too much. • The rest of your data you can place in native memory (off heap) • You can create 1 GB/hour of garbage and still not GC
  • 14. How does Java 8 avoid creating objects? One way to think of Java 8 lambdas is the ability to pass behaviour to a library. With inlining, an alternative view is the ability to template your code. Consider this locking example lock.lock(); try { doSomething(); } finally { lock.unlock(); }
  • 15. How does Java 8 avoid creating objects? This boiler place can be templated public static void withLock(Lock lock, Runnable runnable) { lock.lock(); try { runnable.run(); } finally { lock.unlock(); } }
  • 16. How does Java 8 avoid creating objects? This simplifies the code to be withLock(lock, () -> doSometing()); Doesn’t using a Runnable create an object? With inlining and escape analysis the Runnable can be placed on the stack and eliminated (as it has no fields)
  • 17. A low latency with fail over • Data sent between servers is half round trip. • Inputs are written on both servers. • Outputs are written on both servers. • The end to end latency can be 25 µs, 99% of the time.
  • 19. Next Steps • Chronicle is open source so you can start right away! • Working with clients to produce Chronicle Enterprise • Support contract for Chronicle and consultancy
  • 20. Q & A Peter Lawrey @PeterLawrey http://chronicle.software http://vanillajava.blogspot.com