Blog Low Latency Technology

Peer 2 Peer Trading Demo

            SMR is building a peer 2 peer trading platform for trading on foreign exchange. This video shows two traders buy and selling from each other. For technically minded the app is built as an AngularJS single page app with web socket REST API Scala / Java server with Cassandra as the data store.


You can also see in on YouTube


Java Low Latency Technology

Cost of Locks, CAS and Memory Access

            The absolute numbers below will change as technology progresses but the relative numbers should stay the same.

According to LMAX the relative cost of locks and CAS is as follows (May 2011):-

Operation (500 million times) Cost (ms) Relative Cost
Single thread 300 1
Single thread with lock 10000 33
Two threads with lock 224000 747
Single thread with CAS 5700 19
Two threads with CAS 30000 100
Single thread with volatile write 4700 16
And according to Pinku Surana (Handwaving), here are the numbers for memory access (Jan 2009):-
Operation Cost (ns) Relative Cost
L1 cache reference 0.5 1
Branch mispredict 5 10
L2 cache reference 7 14
Mutex lock/unlock 100 200
Main memory reference 100 200
Compress 1K bytes with Zippy 10,000 20,000
Send 2K bytes over 1 Gbps network 20,000 40,000
Read 1 MB sequentially from memory 250,000 500,000
Round trip within same datacenter 500,000 1,000,000
Disk seek 10,000,000 20,000,000
Read 1 MB sequentially from network 10,000,000 20,000,000
Read 1 MB sequentially from disk 30,000,000 60,000,000
Send packet CA->Netherlands->CA 150,000,000 300,000,000
Low Latency Technology

Performance Testing Low Latency Systems

            <div title="Page 1">

Statistical Tests to Assess Randomized Algorithms A useful article saying that 30 runs (the behavioural science number) is not enough and 1000 runs should be used. Based on central limit theorem. For a useful video and a tool to play with the sizes for CL theorem.

Java Low Latency Technology

Floating Point Numbers in Low Latency Applications

            Clearly there are lots of issues with using <a href="">float and double</a> and using BigDecimal is not going to cut it an low latency financial world unless you are not really that low latency.  So what is the answer. As usual it depends, but here are some suggestions.
  • Look after the pennies rather than the pounds. That is use cents rather than dollars, or what ever is the lowest precision in your world.
  • Ensure intermediate calculations are as exact as possible so that rounding errors are not accumulated.
  • Build or borrow a maths library to compare floating point numbers for instance (i.e float and double) with an epsilon value, i.e. a nearly equals method so that you can hide all the gory details in a library. Also add rounding and precision to the laundry list. Slightly surprised Java’s core libraries don’t cover this better.
  • Use string representations on the wire rounded to appropriate levels of precision. Sure there is an overhead in conversion but at least its accurate.
  • A reminder of sizes:-
    • Integer = 32 bits, 4 bytes = 2^31 =+- 2147483648 = 2.14748E+9
    • Long = 64 bits, 8 byes = 2^63 = +-9.22337E+18
    • Float = 32 bits, 4 bytes = +-3.5E+38 and +-1.4E-45, about 7 digits
    • Double = 64 bits, 8 bytes = +-1.7E+308 and +-4.9E-324, about 15 digits
    • String = words, 2 bytes, short


Java theory and practice: Where’s your point?
Java’s new math, Part 2: Floating-point numbers
Java float / double comparison

Java Low Latency Technology

Low Latency Java Blogs and Websites

            Here are some interesting low latency blogs and websites I've been reading:-
Java Low Latency Technology

Low Latency Java Techniques

            Here are a list of web pages I've been reading recently:-

In due course I will be adding posts for each of these topics.