Time.....Obtaining Nano-Second Precision in Java

Time.....Obtaining Nano-Second Precision in Java

At TransFICC, for MiFID compliance (as explained in my previous blog) we need to obtain the time of an event within 100 microsecond accuracy with respect to UTC.

To achieve this in Java we first need to be able to obtain the time from the OS with better than millisecond precision. We can then make use of Precision Time Protocol (PTP) to ensure the system clock is synchronised to UTC with sufficient accuracy. Take a look at the excellent posts from Luke Bigum on how to achieve this.

In Java version 8 it is not possible to directly obtain the time with higher than millisecond precision. Java 8 System.currentTimeMillis() will return the time since the Unix epoch in milliseconds. Higher precision time is possible on some underlying systems such as Linux.

For details of the Linux code that OpenJDK JVM executes click here - https://wireddevelopment.blogspot.co.uk/2016/08/ob...

The Linux code makes the function call gettimeofday(). This returns the time since the Linux epoch in micro seconds however it is rounded to the nearest millisecond. On newer Linux kernels this is an alias for clock_gettime(). The POSIX spec has deprecated gettimeofday() for clock_gettime() so this should be used instead. On modern Linux systems the function call is implemented as a Virtual Dynamic Shared Object or (VDSO) as opposed to a system call for improved performance.

The accuracy and of the underlying clock is dependent on the clock source being used by the kernel.

Calling clock_gettime() to obtain a nanosecond precision time from the JVM can be achieved in Java using JNA or JNI. We implemented both clock_gettime() using JNA and JNI and performance compared with System.currentTimeMillis() as a baseline. The tests were conducted on a Intel Xeon CPU E5-1650 v3 @ 3.50GHz using the Java Benchmark Harness (JMH).

JNA has the advantage of not requiring the user to compile any native code but this comes at the cost of performance. For each call to obtain the time JNA constructs Structure objects that represent native structures. This results in a worse median latency as well as generating significant amounts of garbage degrading long tail latency. The JNA direct mapping showed improved performance past the 99.99 percentiles but was still significantly slower than JNI.


To read Judd's full post, which includes the code and benchmark results, visit - https://wireddevelopment.blogspot.co.uk/2016/08/ob...




Share
Filter by section
Most popular stories
TransFICC Confirms Intention to Bid for Fixed Income Consolidated Tapes

TransFICC Confirms Intention to Bid for Fixed Income Consolidated Tapes

TransFICC will bid to be the Consolidated Tape Provider (CTP) for the new UK and EU Consolidated Tapes. The FCA is expected to begin its tender process and criteria for the UK CTP in the next few weeks, and ESMA for the EU CTP in January 2025.


Read More Twitter LinkedIn
TransFICC Named "Best Workplace for Technologists"

TransFICC Named "Best Workplace for Technologists"

Having been shortlisted for two previous years, TransFICC has now been recognised at the "Top 1% Workplace Awards 2024"


Read More Twitter LinkedIn
New Report - Corporate Bond Dealers Focus on Trade Automation

New Report - Corporate Bond Dealers Focus on Trade Automation

Coalition Greenwich spoke with 26 bond dealers about the US corporate bond market. Sponsored by TransFICC, the report highlights key technology priorities for 2024


Read More Twitter LinkedIn
TransFICC Secures New Investment of $17 million Led by AlbionVC

TransFICC Secures New Investment of $17 million Led by AlbionVC

TransFICC has closed a Series A extension for $17 million. Led by AlbionVC, all existing institutional shareholders took part in this investment round, which follows the original Series A for $7.8 million, announced in April 2020.


Read More Twitter LinkedIn
TransFICC Named One of The Most Influential FinTech Firms of 2022

TransFICC Named One of The Most Influential FinTech Firms of 2022

Now in its 5th year, the Financial Technologist showcases leading Capital Markets FinTechs


Read More Twitter LinkedIn
TransFICC Launches Consolidated Tape Pilot For EU Fixed Income Using The AFM Regulatory Sandbox

TransFICC Launches Consolidated Tape Pilot For EU Fixed Income Using The AFM Regulatory Sandbox

Press Release - TransFICC has announced a new initiative to develop a Consolidated Tape (CT) for Fixed Income. As part of this initiative, TransFICC has developed a production ready pilot, for Banks, Asset Managers and Regulators to test.


Read More Twitter LinkedIn
Talking with The Trade about the Consolidated Tape for Fixed Income

Talking with The Trade about the Consolidated Tape for Fixed Income

Steve speaks with Kiays Khalil from The TRADE News about the need for a Consolidated Tape in Fixed Income.


Read More Twitter LinkedIn
Speaking with The Desk about Managing Fragmentation in Fixed Income

Speaking with The Desk about Managing Fragmentation in Fixed Income

A smart application of hardware, cloud and open source technology makes for efficient trading systems and reduces the inefficiency that complexity creates


Read More Twitter LinkedIn
Mob Rules - Moving to Virtual Pair Programming

Mob Rules - Moving to Virtual Pair Programming

Like all companies, lockdown has impacted the way we work at TransFICC. We have always championed Extreme Programming as our methodology of choice, so when we decided to close the office at the start of March, this raised some issues around how we would operate with everyone working remotely.


Read More Twitter LinkedIn
All Change - Technology & Efficiency Are The (Old) New Buzzwords in Fixed Income

All Change - Technology & Efficiency Are The (Old) New Buzzwords in Fixed Income

Steve writes for The Financial Technologist - published by Harrington Starr


Read More Twitter LinkedIn
Press Release - TransFICC Secures New Investment From AlbionVC, ING Ventures and HSBC

Press Release - TransFICC Secures New Investment From AlbionVC, ING Ventures and HSBC

TransFICC has closed its Series A investment round for £5.75 million. Led by AlbionVC, it included new strategic investments from ING Ventures and HSBC. The new investors join existing shareholders, Citi, Illuminate Financial, Main Incubator (the R&D unit of Commerzbank Group) and The FinLab.


Read More Twitter LinkedIn
Twitter Feed