SlideShare uma empresa Scribd logo
1 de 50
Java for low latency
You’ve got to be joking!
QCon London 2015
by
John Davies | CTO
@JTDavies
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/java-low-latency
Presented at QCon London
www.qconlondon.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•“The time interval between the stimulation and response”
•Or delay
•It is NOT the same as bandwidth or bandwidth
•Think of latency as the length of a road where as bandwidth/
throughput is the width
•Obviously all cars on this road travel at the speed of electrons or photons /
waves of light
•Traffic lights will add to latency but may improve overall bandwidth
•Reducing latency does not always improve bandwidth, in many
cases it has the reverse effect
Latency
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
c = 299,792,458 m/s
•186,282.397mph or just over 1 billion km/h
•Every 300m of cable/fibre/microwave etc. adds at least 1µS of
latency
•300km (about 200 miles) will add at least 1 milliSecond
•1mS is worth about $100m in the trading world
The ultimate speed limit
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•If your packet size/message is large then the bandwidth can effect
the latency
•It still takes the same amount of time to get the first bit but if you
need 10k bytes before you can start processing then bandwidth
matters too
•So measuring latency can be complex and reducing it can be even
more complex
Bandwidth can effect latency
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Very simply, if you know something before someone else that
information can have value
•$100m per mS
•Trading or betting for example - OK almost the same thing!
•Todays low-latency traders measure latency to 3 significant figures
of micro-seconds
•Remember that there is no second place in trading, you either get
the deal or you don’t
•So every fraction of a micro-second counts (and costs)
Why do we care?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Hardware vs. Software - FPGA vs C/C++
Latency on the trading floor
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•And Java? - Minimum 4µS, mean 10µS, tail goes into 10s of mS!!!
Latency on the trading floor
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•And Java? - Minimum 4µS, mean 10µS, tail goes into 10s of mS!!!
Latency on the trading floor
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Objects basically
•Objects get created everywhere in Java, they’re

good for OOP but crap if you’re trying to get

performance out of your machine
•Every time you create an object something has come along and
tidy it up - The GC
•So read a network buffer, parse it into it’s elements and you’ve
created dozens or even hundreds of objects
•Each one will need to be garbage collected
Why is Java not working here?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Java is very inefficient at storing data in memory
•It was designed specifically to abstract the hardware
•Why should you need to know, write once - run anywhere!
•Take the string “ABC”, typically it needs just 4 bytes
•Three if you know the length won’t change
•Even less if “ABC” is an enumeration
•Java takes 48 bytes to store “ABC” as

a String
•You could argue that we don’t need to run down the entire length of the
String to execute length() but it’s a big price to pay
Java IS the problem!
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•If it was just String then we could use byte[] or char[] but Java
bloating is endemic
•Double
•BigDecimal
•Date
•ArrayList
•Use just one or two and we’re OK but write a class with a few of
these and we really start to see the problem
•A class with 10 minimum sized Objects can be over 500 bytes in
size - for each instance
•What’s worse is that each object requires 11 separate memory allocations
•All of which need managing
•Which is why we have the garbage collector(s)
It’s not just String
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Simple data we’re going to be referring to for the next few
slides…
Start Simple…
ID TradeDate BuySell Currency1 Amount1
Exchange
Rate
Currency2 Amount2
Settlement
Date
1 21/07/2014 Buy EUR 50,000,000 1.344 USD 67,200,000.00 28/07/2014
2 21/07/2014 Sell USD 35,000,000 0.7441 EUR 26,043,500.00 20/08/2014
3 22/07/2014 Buy GBP 7,000,000 172.99 JPY 1,210,930,000.00 05/08/2014
4 23/07/2014 Sell AUD 13,500,000 0.9408 USD 12,700,800.00 22/08/2014
5 24/07/2014 Buy EUR 11,000,000 1.2148 CHF 13,362,800.00 31/07/2014
6 24/07/2014 Buy CHF 6,000,000 0.6513 GBP 3,907,800.00 31/07/2014
7 25/07/2014 Sell JPY 150,000,000 0.6513 EUR 97,695,000.00 08/08/2014
8 25/07/2014 Sell CAD 17,500,000 0.9025 USD 15,793,750.00 01/08/2014
9 28/07/2014 Buy GBP 7,000,000 1.8366 CAD 12,856,200.00 27/08/2014
10 28/07/2014 Buy EUR 13,500,000 0.7911 GBP 10,679,850.00 11/08/2014
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Each line is relatively efficient
ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date
1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014
2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014
3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014

•But it’s in human-readable format not CPU readable
•At least not efficient CPU readable
•We could store the lines as they are but in order to work with
the data we need it in something Java can work with
•The same goes for any other language, C, C++, PHP, Scala etc.
•So typically we parse it into a Java class and give it a self-
documenting name - Row
Start with the CSV
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•This seems like a reasonably good implementation
•From this…
ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date
1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014
2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014
3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014
•We get this…
public class ObjectTrade {

private long id;

private Date tradeDate;

private String buySell;

private String currency1;

private BigDecimal amount1;

private double exchangeRate;

private String currency2;

private BigDecimal amount2;

private Date settlementDate;
}
CSV to Java
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•With very simple getters and setters, something to parse the CSV
and a custom toString() we’re good
public BasicTrade parse( String line ) throws ParseException {
String[] fields = line.split(",");
setId(Long.parseLong(fields[0]));
setTradeDate(DATE_FORMAT.get().parse(fields[1]));
setBuySell(fields[2]);
setCurrency1(fields[3]);
setAmount1(new BigDecimal(fields[4]));
setExchangeRate(Double.parseDouble(fields[5]));
setCurrency2(fields[6]);
setAmount2(new BigDecimal(fields[7]));
setSettlementDate(DATE_FORMAT.get().parse(fields[8]));
return this;
}
•What could possibly go wrong?
Everything’s fine
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•In fact everything works really well, this is how Java was designed
to work
•There are a few “fixes” to add for SimpleDateFormat due to it not being
thread safe but otherwise we’re good
•Performance is good, well it seems good and everything is well
behaved
•As the years go on and the volumes increase, we now have 100
million of them
•Now we start to see some problems
•To start with we don’t have enough memory - GC is killing performance
•When we distribute the size of the objects are killing performance too
This is Java
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•A simple CSV can grow by over 4 times…
ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date
1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014
2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014
3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014

•From roughly 70 bytes per line as CSV to around 328 in Java
•And 10 objects per row
•That means you get over 4 times less data when

stored in Java
•Or need over 4 times more RAM, network

capacity and disk
•Serialized objects are even bigger!
Why is Java one of the problems?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Think this is just a Java problem?
•It’s all the same, every time you create objects you’re blasting huge
holes all over your machine’s RAM
•And someone’s got to clean all the garbage up too!
•Great for performance-tuning consultants :-)
This isn’t just Java
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•This is how we’d typically code this simple CSV example…
ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date
1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014
2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014
3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014
public class ObjectTrade {

private long id;

private Date tradeDate;

private String buySell;

private String currency1;

private BigDecimal amount1;

private double exchangeRate;

private String currency2;

private BigDecimal amount2;

private Date settlementDate;
}
•It’s easy to write the code and fast to execute, retrieve, search
and query data BUT it needs a lot of RAM and it slow to manage
Classic Java Binding…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•We could just store each row
ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date
1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014
2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014
3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014
public class StringTrade {

private String row;
}
•But every time we wanted a date or amount we’d need to parse it
and that would slow down analysis
•If the data was XML it would be even worse
•We’d need a SAX (or other) parser every time
Just store the original data?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
public class StringTrade {

private String row;
}
•Allocation of new StringTrades are faster as we allocate just 2
Objects
•Serialization and De-Serialization are improved for the same
reason
•BUT over all we lose out when we’re accessing the data
•We need to find what we’re looking each time
•This is sort of OK with a CSV but VERY expensive for XML
public class XmlTrade {

private String xml;
}
Just store the original data?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•OK, a lot of asks, why don’t we just use compression?
•Well there are many reasons, mainly that it’s slow, slow to
compress and slow to de-compress, the better it is the slower it
is
•Compression is the lazy person’s tool, a good protocol or codec
doesn’t compress well, try compressing your MP3s or videos
•It has it’s place but we’re looking for more, we want compaction
not compression, then we get performance too
Compression or Compaction?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•This is what our binary version looks like…
ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date
1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014
2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014
3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014
public class ObjectTrade extends SDO {

private byte[] data;
}
•Just one object again so fast to allocate
•If we can encode the data in the binary then it’s fast to query too
•And serialisation is just writing out the byte[]
Now in binary…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Classic getter and setter vs. binary implementation
•Identical API
Same API, just binary
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
Just an example…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•This is a key point, we’re changing the implementation not the API
•This means that Spring, in-memory caches and other tools work
exactly as they did before
•Let’s look at some code and

a little demo of this…
Did I mention … The Same API
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•A quick demo, I’ve created a Trade interface and two
implementations, one “classic” and the other binary
•We’ll create a List of a few million trades (randomly but quite cleverly
generated)
•We’ll serialize them one by one and then…
•de-serialize them to create a new List
•We then do the same again but with the List rather than individually
•Finally with the binary version we just write out the raw data
•Finally for the binary version we’ll write out the entire list via
NIO and read it in again to a new List
Time to see some code
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Compare classic Java binding to binary…
•These are just indicative, the more complex the data the better the
improvement, this is about the worse case (i.e. least impressive)
How does it perform?
Classic Java
version
Binary Java
version
Improvement
Bytes used 328 39 840%
Serialization size 668 85 786%
Custom
Serialization
668 40 1,670%
Time to Serialize/
Deserialize
41.1µS 4.17µS 10x
Batched Serialize/
Deserialize
12.3µS 44nS 280x
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Compare classic Java binding to binary…
•These are just indicative, the more complex the data the better the
improvement, this is about the worse case (i.e. least impressive)
How does it perform?
Classic Java
version
Binary Java
version
Improvement
Bytes used 328 39 840%
Serialization size 668 85 786%
Custom
Serialization
668 40 1,670%
Time to Serialize/
Deserialize
41.1µS 4.17µS 10x
Batched Serialize/
Deserialize
12.3µS 44nS 280x
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•You probably noticed that the actual byte[] size was 39 but Java
used 48 bytes per instance
•By batching and creating batch classes that handle the large
numbers of instances not as a List or Array but more tightly we
can get further improvements in memory and performance
•1 million messages or 39 bytes should be exactly 39,000,000 bytes
•As things get more complex the message size varies and we often have to
compromise with a larger batch quanta
•We usually have to stick to 8 byte chunks too
•To do this safely we’d probably have to use something like 48
bytes per instance in this example
Batching & Mechanical sympathy
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Knowing how your disk (HDD or SSD) works, knowing how you
network works means we can make further optimisations
•A typical network packet it about 1.5k in size, if we can avoid
going over that size we see considerable network performance
improvements
•What Java set out to do was to abstract the programmer from
the hardware, the memory, CPU architecture and network, that
abstraction has cost us dearly
•With binary encoding we can keep Java but take advantage of the lower-level
memory usage and batching
Batching & Mechanical sympathy
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•While the shapes look the same you can clearly see the
differences on both axis
•The Object version is a lot slower
•And the Object version uses significantly more memory
•Note that the left side (objects) has a heap size of 8GB, the right
(binary) has a heap size of just 2GB
Comparing…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•While the shapes look the same you can clearly see the
differences on both axis
•The Object version is a lot slower
•And the Object version uses significantly more memory
•Note that the left side (objects) has a heap size of 8GB, the right
(binary) has a heap size of just 2GB
Comparing…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•These two graphs show the GC pause time during message
creation and serialisation
•Left is “classic” Java
•Right is the binary version
•The top of the right hand graph is lower than the first rung of the
left (50ms)
Comparing…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•These two graphs show the GC pause time during message
creation and serialisation
•Left is “classic” Java
•Right is the binary version
•The top of the right hand graph is lower than the first rung of the
left (50ms)
Comparing…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•The C24 generated code for the Trade example is actually smaller,
it averages around 33 bytes
•It uses run-length encoding so we can represent the 64 bit long by
as little as a single byte for small numbers
•This means the size of the binary message varies slightly but for
more complex models/message
•This is probably not a huge advantage for this CSV example but
makes a huge difference with more complex XML
Generated code
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•It worked for a simple CSV how about more complex models like
XML or JSON?
•Once we have a mapping of types to binary and code we can
extend this to any type of model
•But it gets a lot more complex as we have optional elements,
repeating elements and a vast array of different types
Beyond the CSV file…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
<resetFrequency>

<periodMultiplier>6</periodMultiplier>

<period>M</period>

</resetFrequency>
•JAXB, JIBX, Castor etc. generate something like …
public class ResetFrequency {
private BigInteger periodMultiplier; // Positive Integer
private Object period; // Enum of D, W, M, Q, Y
public BigInteger getPeriodMultiplier() {
return this.periodMultiplier;
}
// constructors & other getters and setters

•In memory - 3 objects - at least 144 bytes
•The parent, a positive integer and an enumeration for Period
•3 Java objects at 48 bytes is 144 bytes and it becomes fragmented in memory
Standard Java Binding
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
<resetFrequency>

<periodMultiplier>6</periodMultiplier>

<period>M</period>

</resetFrequency>
•Using C24’s SDO binary codec we generate …
ByteBuffer data; // From the root object
public BigInteger getPeriodMultiplier() {
int byteOffset = 123; // Actually a lot more complex
return BigInteger.valueOf( data.get(byteOffset) & 0x1F );
}
// constructors & other getters

•In memory -1 byte for all three fields
•The root contains one ByteBuffer which is a wrapper for byte[]
•The getters use bit-fields, Period is just 3 bits for values D,W, M, Q orY
Our Java Binding
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Take some raw XML (an FpML derivative, about 7.4k of XML)
•Parse it, mutate a few variables and then compact each one to its
binary version - We do this 1 million times
•This takes about 100 seconds
•Now the test begins
•We take a look at the binary version (just 370 bytes)
•We search through the 1 million trades for data and aggregate the results
•Then we try it multi-threaded (using parallelStream())
•A few more similar operations (I will discuss)
•Finally we’ll write all 1 million to disk and then read them back
into another array (comparing to make sure it worked)
•This will be a test of serialisation
Another demo…
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•C/C++ is with kernel bypass libraries is now faster than the FPGA
cards but we’re unlikely to see Java being used low-latency trading
Where now?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•C/C++ is with kernel bypass libraries is now faster than the FPGA
cards but we’re unlikely to see Java being used low-latency trading
Where now?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•C/C++ is with kernel bypass libraries is now faster than the FPGA
cards but we’re unlikely to see Java being used low-latency trading
Where now?
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•What we’re doing is processing streams (packets and messages)
without creating any objects
•This is exactly how we did it in C and C++
•The message is smaller
•It’s received faster
•The CPU is not creating objects
•Processed faster
•The CPU is not garbage collecting
•Less jitter
•All of the message is in one place and not spread around the
memory space
•We get better CPU cache hits
Smaller and Faster
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Take a store (database) of 1 billion trades (a decade’s worth)
•Each one is about 5k in size (so  5TB)
•Convert them to Java with binding and we hit 25k each (25TB)
•Now add some indices and we’re looking at 40+TB
•Compact them with to SDOs and we now have 500GB
•Put it into Oracle CoherenceV12.2.1 with lambdas and we can do
cache.filter(predicate).map(price).reduce(…);
Map Reduce without Hadoop
© 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd.
•Latency at one end of the architecture is not the only place it
matters
•By reducing object creation we can dramatically improve latency
and throughput
•And of course reduce the impact of the GC
•Java was designed to abstract us from all of this but we can
program around the abstraction
•With a simple change to a small part of the code we see
impressive impacts across the entire architecture
What we’ve achieved
•Thank you
•Twitter: @jtdavies
•John.Davies@C24.biz
•Thank you to Kirk Pepperdine,Andrew Elmore and the C24 team
Watch the video with slide synchronization
on InfoQ.com!
http://www.infoq.com/presentations/java-
low-latency

Mais conteúdo relacionado

Destaque

MongoDB as Message Queue
MongoDB as Message QueueMongoDB as Message Queue
MongoDB as Message QueueMongoDB
 
Top10 Salesforce.com Admin Tools
Top10 Salesforce.com Admin ToolsTop10 Salesforce.com Admin Tools
Top10 Salesforce.com Admin Toolsdebm_madronasg
 
Marketing & business plan
Marketing & business planMarketing & business plan
Marketing & business planswati_iyer05
 
100 Sales Tips for 2014 Salesforce ebook
100 Sales Tips for 2014 Salesforce ebook100 Sales Tips for 2014 Salesforce ebook
100 Sales Tips for 2014 Salesforce ebookMiguel Spencer
 
Performance Monitoring and Testing in the Salesforce Cloud
Performance Monitoring and Testing in the Salesforce CloudPerformance Monitoring and Testing in the Salesforce Cloud
Performance Monitoring and Testing in the Salesforce CloudSalesforce Developers
 
End of Cold War - Poland's Solidarity, Gorbachev, Fall of USSR
End of Cold War - Poland's Solidarity, Gorbachev, Fall of USSREnd of Cold War - Poland's Solidarity, Gorbachev, Fall of USSR
End of Cold War - Poland's Solidarity, Gorbachev, Fall of USSRJoanie Yeung
 
6 maxillary osteotomies
6  maxillary osteotomies6  maxillary osteotomies
6 maxillary osteotomiesvasanramkumar
 
The Radiology of Malrotation
The Radiology of MalrotationThe Radiology of Malrotation
The Radiology of Malrotationtboulden
 
The Marketing Models
The Marketing ModelsThe Marketing Models
The Marketing ModelsJohn Webb
 
Scale-up and scale-down of chemical processes
Scale-up and scale-down of chemical processesScale-up and scale-down of chemical processes
Scale-up and scale-down of chemical processesSeppo Karrila
 
Dreamforce '16 Agenda Builder Guide
Dreamforce '16 Agenda Builder GuideDreamforce '16 Agenda Builder Guide
Dreamforce '16 Agenda Builder GuideDreamforce
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsSteven Francia
 

Destaque (14)

What is an Sms Hub
What is an Sms HubWhat is an Sms Hub
What is an Sms Hub
 
MongoDB as Message Queue
MongoDB as Message QueueMongoDB as Message Queue
MongoDB as Message Queue
 
Top10 Salesforce.com Admin Tools
Top10 Salesforce.com Admin ToolsTop10 Salesforce.com Admin Tools
Top10 Salesforce.com Admin Tools
 
Marketing & business plan
Marketing & business planMarketing & business plan
Marketing & business plan
 
100 Sales Tips for 2014 Salesforce ebook
100 Sales Tips for 2014 Salesforce ebook100 Sales Tips for 2014 Salesforce ebook
100 Sales Tips for 2014 Salesforce ebook
 
Performance Monitoring and Testing in the Salesforce Cloud
Performance Monitoring and Testing in the Salesforce CloudPerformance Monitoring and Testing in the Salesforce Cloud
Performance Monitoring and Testing in the Salesforce Cloud
 
End of Cold War - Poland's Solidarity, Gorbachev, Fall of USSR
End of Cold War - Poland's Solidarity, Gorbachev, Fall of USSREnd of Cold War - Poland's Solidarity, Gorbachev, Fall of USSR
End of Cold War - Poland's Solidarity, Gorbachev, Fall of USSR
 
6 maxillary osteotomies
6  maxillary osteotomies6  maxillary osteotomies
6 maxillary osteotomies
 
The Radiology of Malrotation
The Radiology of MalrotationThe Radiology of Malrotation
The Radiology of Malrotation
 
The Marketing Models
The Marketing ModelsThe Marketing Models
The Marketing Models
 
Digital Self Service Trends & Innovations
Digital Self Service Trends & InnovationsDigital Self Service Trends & Innovations
Digital Self Service Trends & Innovations
 
Scale-up and scale-down of chemical processes
Scale-up and scale-down of chemical processesScale-up and scale-down of chemical processes
Scale-up and scale-down of chemical processes
 
Dreamforce '16 Agenda Builder Guide
Dreamforce '16 Agenda Builder GuideDreamforce '16 Agenda Builder Guide
Dreamforce '16 Agenda Builder Guide
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and Transactions
 

Mais de C4Media

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoC4Media
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileC4Media
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020C4Media
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 

Mais de C4Media (20)

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy Mobile
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Java for Low Latency - You’ve Got to Be Joking!

  • 1. Java for low latency You’ve got to be joking! QCon London 2015 by John Davies | CTO @JTDavies
  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /java-low-latency
  • 3. Presented at QCon London www.qconlondon.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 4. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •“The time interval between the stimulation and response” •Or delay •It is NOT the same as bandwidth or bandwidth •Think of latency as the length of a road where as bandwidth/ throughput is the width •Obviously all cars on this road travel at the speed of electrons or photons / waves of light •Traffic lights will add to latency but may improve overall bandwidth •Reducing latency does not always improve bandwidth, in many cases it has the reverse effect Latency
  • 5. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. c = 299,792,458 m/s •186,282.397mph or just over 1 billion km/h •Every 300m of cable/fibre/microwave etc. adds at least 1µS of latency •300km (about 200 miles) will add at least 1 milliSecond •1mS is worth about $100m in the trading world The ultimate speed limit
  • 6. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •If your packet size/message is large then the bandwidth can effect the latency •It still takes the same amount of time to get the first bit but if you need 10k bytes before you can start processing then bandwidth matters too •So measuring latency can be complex and reducing it can be even more complex Bandwidth can effect latency
  • 7. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Very simply, if you know something before someone else that information can have value •$100m per mS •Trading or betting for example - OK almost the same thing! •Todays low-latency traders measure latency to 3 significant figures of micro-seconds •Remember that there is no second place in trading, you either get the deal or you don’t •So every fraction of a micro-second counts (and costs) Why do we care?
  • 8. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Hardware vs. Software - FPGA vs C/C++ Latency on the trading floor
  • 9. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •And Java? - Minimum 4µS, mean 10µS, tail goes into 10s of mS!!! Latency on the trading floor
  • 10. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •And Java? - Minimum 4µS, mean 10µS, tail goes into 10s of mS!!! Latency on the trading floor
  • 11. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Objects basically •Objects get created everywhere in Java, they’re
 good for OOP but crap if you’re trying to get
 performance out of your machine •Every time you create an object something has come along and tidy it up - The GC •So read a network buffer, parse it into it’s elements and you’ve created dozens or even hundreds of objects •Each one will need to be garbage collected Why is Java not working here?
  • 12. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Java is very inefficient at storing data in memory •It was designed specifically to abstract the hardware •Why should you need to know, write once - run anywhere! •Take the string “ABC”, typically it needs just 4 bytes •Three if you know the length won’t change •Even less if “ABC” is an enumeration •Java takes 48 bytes to store “ABC” as
 a String •You could argue that we don’t need to run down the entire length of the String to execute length() but it’s a big price to pay Java IS the problem!
  • 13. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •If it was just String then we could use byte[] or char[] but Java bloating is endemic •Double •BigDecimal •Date •ArrayList •Use just one or two and we’re OK but write a class with a few of these and we really start to see the problem •A class with 10 minimum sized Objects can be over 500 bytes in size - for each instance •What’s worse is that each object requires 11 separate memory allocations •All of which need managing •Which is why we have the garbage collector(s) It’s not just String
  • 14. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Simple data we’re going to be referring to for the next few slides… Start Simple… ID TradeDate BuySell Currency1 Amount1 Exchange Rate Currency2 Amount2 Settlement Date 1 21/07/2014 Buy EUR 50,000,000 1.344 USD 67,200,000.00 28/07/2014 2 21/07/2014 Sell USD 35,000,000 0.7441 EUR 26,043,500.00 20/08/2014 3 22/07/2014 Buy GBP 7,000,000 172.99 JPY 1,210,930,000.00 05/08/2014 4 23/07/2014 Sell AUD 13,500,000 0.9408 USD 12,700,800.00 22/08/2014 5 24/07/2014 Buy EUR 11,000,000 1.2148 CHF 13,362,800.00 31/07/2014 6 24/07/2014 Buy CHF 6,000,000 0.6513 GBP 3,907,800.00 31/07/2014 7 25/07/2014 Sell JPY 150,000,000 0.6513 EUR 97,695,000.00 08/08/2014 8 25/07/2014 Sell CAD 17,500,000 0.9025 USD 15,793,750.00 01/08/2014 9 28/07/2014 Buy GBP 7,000,000 1.8366 CAD 12,856,200.00 27/08/2014 10 28/07/2014 Buy EUR 13,500,000 0.7911 GBP 10,679,850.00 11/08/2014
  • 15. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Each line is relatively efficient ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date 1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014 2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014 3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014
 •But it’s in human-readable format not CPU readable •At least not efficient CPU readable •We could store the lines as they are but in order to work with the data we need it in something Java can work with •The same goes for any other language, C, C++, PHP, Scala etc. •So typically we parse it into a Java class and give it a self- documenting name - Row Start with the CSV
  • 16. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •This seems like a reasonably good implementation •From this… ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date 1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014 2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014 3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014 •We get this… public class ObjectTrade {
 private long id;
 private Date tradeDate;
 private String buySell;
 private String currency1;
 private BigDecimal amount1;
 private double exchangeRate;
 private String currency2;
 private BigDecimal amount2;
 private Date settlementDate; } CSV to Java
  • 17. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •With very simple getters and setters, something to parse the CSV and a custom toString() we’re good public BasicTrade parse( String line ) throws ParseException { String[] fields = line.split(","); setId(Long.parseLong(fields[0])); setTradeDate(DATE_FORMAT.get().parse(fields[1])); setBuySell(fields[2]); setCurrency1(fields[3]); setAmount1(new BigDecimal(fields[4])); setExchangeRate(Double.parseDouble(fields[5])); setCurrency2(fields[6]); setAmount2(new BigDecimal(fields[7])); setSettlementDate(DATE_FORMAT.get().parse(fields[8])); return this; } •What could possibly go wrong? Everything’s fine
  • 18. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •In fact everything works really well, this is how Java was designed to work •There are a few “fixes” to add for SimpleDateFormat due to it not being thread safe but otherwise we’re good •Performance is good, well it seems good and everything is well behaved •As the years go on and the volumes increase, we now have 100 million of them •Now we start to see some problems •To start with we don’t have enough memory - GC is killing performance •When we distribute the size of the objects are killing performance too This is Java
  • 19. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •A simple CSV can grow by over 4 times… ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date 1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014 2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014 3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014
 •From roughly 70 bytes per line as CSV to around 328 in Java •And 10 objects per row •That means you get over 4 times less data when
 stored in Java •Or need over 4 times more RAM, network
 capacity and disk •Serialized objects are even bigger! Why is Java one of the problems?
  • 20. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Think this is just a Java problem? •It’s all the same, every time you create objects you’re blasting huge holes all over your machine’s RAM •And someone’s got to clean all the garbage up too! •Great for performance-tuning consultants :-) This isn’t just Java
  • 21. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •This is how we’d typically code this simple CSV example… ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date 1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014 2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014 3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014 public class ObjectTrade {
 private long id;
 private Date tradeDate;
 private String buySell;
 private String currency1;
 private BigDecimal amount1;
 private double exchangeRate;
 private String currency2;
 private BigDecimal amount2;
 private Date settlementDate; } •It’s easy to write the code and fast to execute, retrieve, search and query data BUT it needs a lot of RAM and it slow to manage Classic Java Binding…
  • 22. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •We could just store each row ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date 1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014 2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014 3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014 public class StringTrade {
 private String row; } •But every time we wanted a date or amount we’d need to parse it and that would slow down analysis •If the data was XML it would be even worse •We’d need a SAX (or other) parser every time Just store the original data?
  • 23. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. public class StringTrade {
 private String row; } •Allocation of new StringTrades are faster as we allocate just 2 Objects •Serialization and De-Serialization are improved for the same reason •BUT over all we lose out when we’re accessing the data •We need to find what we’re looking each time •This is sort of OK with a CSV but VERY expensive for XML public class XmlTrade {
 private String xml; } Just store the original data?
  • 24. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •OK, a lot of asks, why don’t we just use compression? •Well there are many reasons, mainly that it’s slow, slow to compress and slow to de-compress, the better it is the slower it is •Compression is the lazy person’s tool, a good protocol or codec doesn’t compress well, try compressing your MP3s or videos •It has it’s place but we’re looking for more, we want compaction not compression, then we get performance too Compression or Compaction?
  • 25. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •This is what our binary version looks like… ID,TradeDate,BuySell,Currency1,Amount1,Exchange Rate,Currency2,Amount2,Settlement Date 1,21/07/2014,Buy,EUR,50000000.00,1.344,USD,67200000.00,28/07/2014 2,21/07/2014,Sell,USD,35000000.00,0.7441,EUR,26043500.00,20/08/2014 3,22/07/2014,Buy,GBP,7000000.00,172.99,JPY,1210930000,05/08/2014 public class ObjectTrade extends SDO {
 private byte[] data; } •Just one object again so fast to allocate •If we can encode the data in the binary then it’s fast to query too •And serialisation is just writing out the byte[] Now in binary…
  • 26. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Classic getter and setter vs. binary implementation •Identical API Same API, just binary
  • 27. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. Just an example…
  • 28. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •This is a key point, we’re changing the implementation not the API •This means that Spring, in-memory caches and other tools work exactly as they did before •Let’s look at some code and
 a little demo of this… Did I mention … The Same API
  • 29. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •A quick demo, I’ve created a Trade interface and two implementations, one “classic” and the other binary •We’ll create a List of a few million trades (randomly but quite cleverly generated) •We’ll serialize them one by one and then… •de-serialize them to create a new List •We then do the same again but with the List rather than individually •Finally with the binary version we just write out the raw data •Finally for the binary version we’ll write out the entire list via NIO and read it in again to a new List Time to see some code
  • 30. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Compare classic Java binding to binary… •These are just indicative, the more complex the data the better the improvement, this is about the worse case (i.e. least impressive) How does it perform? Classic Java version Binary Java version Improvement Bytes used 328 39 840% Serialization size 668 85 786% Custom Serialization 668 40 1,670% Time to Serialize/ Deserialize 41.1µS 4.17µS 10x Batched Serialize/ Deserialize 12.3µS 44nS 280x
  • 31. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Compare classic Java binding to binary… •These are just indicative, the more complex the data the better the improvement, this is about the worse case (i.e. least impressive) How does it perform? Classic Java version Binary Java version Improvement Bytes used 328 39 840% Serialization size 668 85 786% Custom Serialization 668 40 1,670% Time to Serialize/ Deserialize 41.1µS 4.17µS 10x Batched Serialize/ Deserialize 12.3µS 44nS 280x
  • 32. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •You probably noticed that the actual byte[] size was 39 but Java used 48 bytes per instance •By batching and creating batch classes that handle the large numbers of instances not as a List or Array but more tightly we can get further improvements in memory and performance •1 million messages or 39 bytes should be exactly 39,000,000 bytes •As things get more complex the message size varies and we often have to compromise with a larger batch quanta •We usually have to stick to 8 byte chunks too •To do this safely we’d probably have to use something like 48 bytes per instance in this example Batching & Mechanical sympathy
  • 33. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Knowing how your disk (HDD or SSD) works, knowing how you network works means we can make further optimisations •A typical network packet it about 1.5k in size, if we can avoid going over that size we see considerable network performance improvements •What Java set out to do was to abstract the programmer from the hardware, the memory, CPU architecture and network, that abstraction has cost us dearly •With binary encoding we can keep Java but take advantage of the lower-level memory usage and batching Batching & Mechanical sympathy
  • 34. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •While the shapes look the same you can clearly see the differences on both axis •The Object version is a lot slower •And the Object version uses significantly more memory •Note that the left side (objects) has a heap size of 8GB, the right (binary) has a heap size of just 2GB Comparing…
  • 35. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •While the shapes look the same you can clearly see the differences on both axis •The Object version is a lot slower •And the Object version uses significantly more memory •Note that the left side (objects) has a heap size of 8GB, the right (binary) has a heap size of just 2GB Comparing…
  • 36. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •These two graphs show the GC pause time during message creation and serialisation •Left is “classic” Java •Right is the binary version •The top of the right hand graph is lower than the first rung of the left (50ms) Comparing…
  • 37. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •These two graphs show the GC pause time during message creation and serialisation •Left is “classic” Java •Right is the binary version •The top of the right hand graph is lower than the first rung of the left (50ms) Comparing…
  • 38. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •The C24 generated code for the Trade example is actually smaller, it averages around 33 bytes •It uses run-length encoding so we can represent the 64 bit long by as little as a single byte for small numbers •This means the size of the binary message varies slightly but for more complex models/message •This is probably not a huge advantage for this CSV example but makes a huge difference with more complex XML Generated code
  • 39. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •It worked for a simple CSV how about more complex models like XML or JSON? •Once we have a mapping of types to binary and code we can extend this to any type of model •But it gets a lot more complex as we have optional elements, repeating elements and a vast array of different types Beyond the CSV file…
  • 40. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. <resetFrequency>
 <periodMultiplier>6</periodMultiplier>
 <period>M</period>
 </resetFrequency> •JAXB, JIBX, Castor etc. generate something like … public class ResetFrequency { private BigInteger periodMultiplier; // Positive Integer private Object period; // Enum of D, W, M, Q, Y public BigInteger getPeriodMultiplier() { return this.periodMultiplier; } // constructors & other getters and setters
 •In memory - 3 objects - at least 144 bytes •The parent, a positive integer and an enumeration for Period •3 Java objects at 48 bytes is 144 bytes and it becomes fragmented in memory Standard Java Binding
  • 41. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. <resetFrequency>
 <periodMultiplier>6</periodMultiplier>
 <period>M</period>
 </resetFrequency> •Using C24’s SDO binary codec we generate … ByteBuffer data; // From the root object public BigInteger getPeriodMultiplier() { int byteOffset = 123; // Actually a lot more complex return BigInteger.valueOf( data.get(byteOffset) & 0x1F ); } // constructors & other getters
 •In memory -1 byte for all three fields •The root contains one ByteBuffer which is a wrapper for byte[] •The getters use bit-fields, Period is just 3 bits for values D,W, M, Q orY Our Java Binding
  • 42. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Take some raw XML (an FpML derivative, about 7.4k of XML) •Parse it, mutate a few variables and then compact each one to its binary version - We do this 1 million times •This takes about 100 seconds •Now the test begins •We take a look at the binary version (just 370 bytes) •We search through the 1 million trades for data and aggregate the results •Then we try it multi-threaded (using parallelStream()) •A few more similar operations (I will discuss) •Finally we’ll write all 1 million to disk and then read them back into another array (comparing to make sure it worked) •This will be a test of serialisation Another demo…
  • 43. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •C/C++ is with kernel bypass libraries is now faster than the FPGA cards but we’re unlikely to see Java being used low-latency trading Where now?
  • 44. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •C/C++ is with kernel bypass libraries is now faster than the FPGA cards but we’re unlikely to see Java being used low-latency trading Where now?
  • 45. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •C/C++ is with kernel bypass libraries is now faster than the FPGA cards but we’re unlikely to see Java being used low-latency trading Where now?
  • 46. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •What we’re doing is processing streams (packets and messages) without creating any objects •This is exactly how we did it in C and C++ •The message is smaller •It’s received faster •The CPU is not creating objects •Processed faster •The CPU is not garbage collecting •Less jitter •All of the message is in one place and not spread around the memory space •We get better CPU cache hits Smaller and Faster
  • 47. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Take a store (database) of 1 billion trades (a decade’s worth) •Each one is about 5k in size (so  5TB) •Convert them to Java with binding and we hit 25k each (25TB) •Now add some indices and we’re looking at 40+TB •Compact them with to SDOs and we now have 500GB •Put it into Oracle CoherenceV12.2.1 with lambdas and we can do cache.filter(predicate).map(price).reduce(…); Map Reduce without Hadoop
  • 48. © 2014 C24 TechnologiesConfidential Information of C24 Technologies Ltd. •Latency at one end of the architecture is not the only place it matters •By reducing object creation we can dramatically improve latency and throughput •And of course reduce the impact of the GC •Java was designed to abstract us from all of this but we can program around the abstraction •With a simple change to a small part of the code we see impressive impacts across the entire architecture What we’ve achieved
  • 49. •Thank you •Twitter: @jtdavies •John.Davies@C24.biz •Thank you to Kirk Pepperdine,Andrew Elmore and the C24 team
  • 50. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/java- low-latency