Download - Stuff I Learned About Performance
![Page 1: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/1.jpg)
Stuff I’ve learnt about software performance
@mikeb2701
learned
![Page 2: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/2.jpg)
• What is a financial exchange?
• How to lie with numbers
• Design is (almost) everything
• Everything else is about making trade-offs
![Page 3: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/3.jpg)
![Page 4: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/4.jpg)
TL;DR
1. Low Latency
2. ???
3. Profit
![Page 5: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/5.jpg)
Lies, Damed Lies and Performance Numbers
![Page 6: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/6.jpg)
320µs @ 10,000 tx/s
![Page 7: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/7.jpg)
Customer
FixGateway
LoadBalancer
ExecutionVenue
Record Latency
Parse/Encode FIX
Order MatchingReplicationJournalling
![Page 8: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/8.jpg)
320µs @ 10,000 tx/s
![Page 9: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/9.jpg)
![Page 10: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/10.jpg)
320µs @ 10,000 tx/s
![Page 11: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/11.jpg)
http://www.infoq.com/presentations/latency-pitfalls
![Page 12: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/12.jpg)
What did I learn
• Detail Matters
• Don’t oversimplify the behaviour of your system
![Page 13: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/13.jpg)
If we can really understand the problem, the answer will come out of it, because the answer is
not separate from the problem. !
- Jiddu Krishnamurti
![Page 14: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/14.jpg)
Customer
FixGateway
LoadBalancer
ExecutionVenue
Record Latency
Parse/Encode FIX
Order MatchingReplicationJournalling
![Page 15: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/15.jpg)
Instruction
ExecutionReport
Execution Venue
OrderBook
Order
Execution
![Page 16: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/16.jpg)
Execution Venueinstrument: Carrots
CreateOrderBook<Admin Instruction>
![Page 17: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/17.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
instrument: Carrots
CreateOrderBook<Admin Instruction>
![Page 18: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/18.jpg)
id : ABCinstrument: Carrotsprice : 110quantity : 5side : BID
PlaceOrder<Instruction>
Execution Venue
instrument: Carrots
OrderBook<Entity>
![Page 19: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/19.jpg)
id : ABCinstrument: Carrotsprice : 110quantity : 5side : BID
PlaceOrder<Instruction>
Execution Venue
instrument: Carrots
OrderBook<Entity>
orderId : 1id : ABCprice : 110quantity : 5side : BIDfilled : 0cancelled : 0
Order<Entity>
![Page 20: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/20.jpg)
id : ABCinstrument: Carrotsprice : 110quantity : 5side : BID
PlaceOrder<Instruction>
Execution Venue
instrument: Carrots
OrderBook<Entity>
orderId : 1id : ABCprice : 110quantity : 5side : BIDfilled : 0cancelled : 0
Order<Entity>id : ABC
Accept<ExecutionReport>
instrument: Carrotsprice : 110quantity : 5
LiquidityAdded<ExecutionReport>
![Page 21: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/21.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
orderId : 1id : ABCprice : 110quantity : 5side : BIDfilled : 0cancelled : 0
Order<Entity>
originalId: ABC
CancelOrder<Instruction>
![Page 22: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/22.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
originalId: ABC
CancelOrder<Instruction>
id : ABCinstrument: Carrotsprice : 110quantity : 5
Cancelled<ExecutionReport>
orderId : 1id : ABCprice : 110quantity : 5side : BIDfilled : 0cancelled : 5
Order<Entity>
![Page 23: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/23.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
originalId: ABC
CancelOrder<Instruction>
id : ABCinstrument: Carrotsprice : 110quantity : 5
Cancelled<ExecutionReport>
![Page 24: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/24.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
orderId : 1id : ABCprice : 110quantity : 5side : BIDfilled : 0cancelled : 0
Order<Entity>
id : DEFinstrument: Carrotsprice : 110quantity : 5side : ASK
PlaceOrder<Instruction>
![Page 25: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/25.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
id : DEFinstrument: Carrotsprice : 110quantity : 5side : ASK
PlaceOrder<Instruction>
id : DEF
Accept<ExecutionReport>
price : 110quantity : 5aggressive: DEFpassive : ABC
Trade<ExecutionReport>
orderId : 1id : ABCprice : 110quantity : 5side : BIDfilled : 5cancelled : 0
Order<Entity>
![Page 26: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/26.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
id : DEFinstrument: Carrotsprice : 110quantity : 5side : ASK
PlaceOrder<Instruction>
id : DEF
Accept<ExecutionReport>
price : 110quantity : 5aggressive: DEFpassive : ABC
Trade<ExecutionReport>
![Page 27: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/27.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
id : ABCinstrument: Bananasprice : 110quantity : 5side : BID
PlaceOrder<Instruction>
![Page 28: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/28.jpg)
Execution Venue
instrument: Carrots
OrderBook<Entity>
id : ABCinstrument: Bananasprice : 110quantity : 5side : BID
PlaceOrder<Instruction>
id : ABC
Reject<ExecutionReport>
![Page 29: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/29.jpg)
Interesting Properties
• Stable working set
• Fits in memory
• Doesn’t not grow monotonically with time
• All decisions are made from local information
![Page 30: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/30.jpg)
Event-Sourced Service
Journalling
Replication
BusinessLogicMessage Message
http://www.infoq.com/presentations/Event-Sourced-Architectures-for-High-Availability
![Page 31: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/31.jpg)
What did I learn• Enough understanding of the problem and
solutions will appear
• Pay attention to:
• Entity Life-cycles
• Number of entities - in real world scenarios
• Try to approach the problem without bias
![Page 32: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/32.jpg)
If you can’t talk about the downside and the trade offs then you’re just a fan person waiving a coffee mug around. That type of behaviour
really doesn’t benefit anyone. !
- Some guy on the Internet (charmalloc)
Source: http://allthingshadoop.com/2013/12/06/technology-decisions-are-about-trade-offs-and-solving-problems/
![Page 33: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/33.jpg)
Customer
FixGateway
LoadBalancer
ExecutionVenue
Market DataService
10K msg/sec
160K msg/sec
![Page 34: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/34.jpg)
Design for trade-offs
![Page 35: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/35.jpg)
TIMESTAMP,BID_PRICE_1,BID_QTY_1,ASK_PRICE_1,ASK_QTY_1 1405890300827,1.35263,50,1.35296,50 1405890300908,1.35263,50,1.35296,49.9 1405890300909,1.35263,50,1.35296,47.9 1405890301090,1.35263,48.2,1.35296,47.9 1405890301193,1.35263,48.2,1.35296,46.1 1405890301194,1.35263,48.2,1.35296,44.6 1405890301280,1.35263,48.2,1.35296,42.6 1405890301571,1.35263,48.1,1.35296,42.6 1405890303037,1.35263,47.1,1.35296,42.6
![Page 36: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/36.jpg)
List<String[]> lines = ! parseAsList("data.csv");!for (String[] line : lines)!{! double bid = parseDouble(line[1]);! double ask = parseDouble(line[3]);! ! // Stuff...!}!
![Page 37: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/37.jpg)
Iterable<String[]> lines = ! parseAsIterable("data.csv");!for (String[] line : lines)!{! double bid = parseDouble(line[1]);! double ask = parseDouble(line[3]);! ! // Stuff...!}!
![Page 38: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/38.jpg)
public interface CsvObservable!{! default void onError(Exception e)! {! }!! default void onComplete()! {! }!! void onEvent(! int row, int column, ! CharSequence value, boolean endOfLine);!}
![Page 39: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/39.jpg)
parse("data.csv", ! (row, column, value, endOfLine) ->!{! switch (column)! {! case 1:! bid = parseDouble(value);! case 3:! ask = parseDouble(value);! }!! // Stuff...!});
![Page 40: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/40.jpg)
Ops/sec GC Count GC Time (ms)
Iterable 8.20 104 154
Observable 16.75 0 0
![Page 41: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/41.jpg)
public class CsvObservableDelegate ! implements CsvObservable<CharSequence>!{! private CsvObservable<String> delegate;!! public CsvObservableDelegate(CsvObservable<String> delegate)! {! this.delegate = delegate;! }!! public void onEvent(! int row, int column, ! CharSequence value, boolean endOfLine)! {! delegate.onEvent(! row, column, value.toString(), endOfLine);! }!! // Other delegate methods!}!
![Page 42: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/42.jpg)
Garbage CollectionStallin’ your app since 1959
![Page 43: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/43.jpg)
![Page 44: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/44.jpg)
![Page 45: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/45.jpg)
mean 95% 99% 99.99%
JDK6 1.386 1.82 5.75 15.72
JDK7 1.44 1.79 11.75 20.66
![Page 46: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/46.jpg)
Solutions
• Don’t Generate Any • Use Zing (Azul Systems)
![Page 47: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/47.jpg)
Why Use Java? (why not C/C++/..)
![Page 48: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/48.jpg)
Source: https://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions
![Page 49: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/49.jpg)
public class Doubles !{ ! public static void sum(! double[] sum, ! double[] addendA, ! double[] addendB)! {! for (int i = 0; i < 0 + sum.length; i++)! {! sum[i] = addendA[i] + addendB[i];! }! }!}!
![Page 50: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/50.jpg)
#include <immintrin.h>!!void sum(double* c, double* a, double* b, int len)!{! __m256d rA_AVX, rB_AVX, rC_AVX;!! for (int i = 0; i < len; i += 4)! {! rA_AVX = _mm256_load_pd(&a[i]);! rB_AVX = _mm256_load_pd(&b[i]);! rC_AVX = _mm256_add_pd(rA_AVX, rB_AVX);! _mm256_store_pd(&c[i], rC_AVX);! }!}!
![Page 51: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/51.jpg)
![Page 52: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/52.jpg)
![Page 53: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/53.jpg)
More Java vs. C++
https://github.com/real-logic/simple-binary-encoding
![Page 54: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/54.jpg)
What did I learn?• Details matter (performance measurement) • Let the problem define the solution
• Design without bias • Understand the costs/benefits of trade-offs
• Design to let others make trade-offs • Some trade-offs are not technical
![Page 55: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/55.jpg)
Q&A
![Page 56: Stuff I Learned About Performance](https://reader033.vdocuments.us/reader033/viewer/2022052622/5594598b1a28ab65728b458e/html5/thumbnails/56.jpg)
Links• Measuring Latency - http://goo.gl/6bllUP
• Event Sourcing - http://goo.gl/VcZI7l
• LMAX Architecture - http://goo.gl/UI5z0T
• Source Code
• http://github.com/mikeb01/qconsf2014