Top Banner
(c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey
20

(c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

Dec 17, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Introduction to Chronicle

Micro second latency persistence

Higher Frequency Trading(c) Peter Lawrey

Page 2: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

What is Chronicle?

Very fast embedded persistence for Java.

Functionality is simple and low level by design

Page 3: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Where does Chronicle come from

Low latency, high frequency trading

– Applications which are sub 100 micro-second external to the system.

Page 4: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Where does Chronicle come from

High throughput trading systems

– Hundreds of thousand of events per second

Page 5: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Where does Chronicle come from

Modes of use

– GC free

– Lock-less

– Shared memory

– Text or binary

– Replicated over TCP

Page 6: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Use for Chronicle

Synchronous text logging Synchronous binary data logging

Page 7: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Use for Chronicle

Messaging between processesvia shared memory

Messaging across systems

Page 8: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Use for Chronicle

Supports recording micro-second timestamps across the systems

Replay for production data in test

Page 9: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Writing to Chronicle

IndexedChronicle ic = new IndexedChronicle(basePath);Excerpt excerpt = ic.createExcerpt();

for (int i = 1; i <= runs; i++) { excerpt.startExcerpt(17); excerpt.writeUnsignedByte('M'); // message type excerpt.writeLong(i); // e.g. time stamp excerpt.writeDouble(i); excerpt.finish();}ic.close();

Page 10: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Reading from ChronicleIndexedChronicle ic = new IndexedChronicle(basePath);ic.useUnsafe(true); // for benchmarksExcerpt excerpt = ic.createExcerpt();for (int i = 1; i <= runs; i++) { while (!excerpt.nextIndex()) { // busy wait } char ch = (char) excerpt.readUnsignedByte(); long l = excerpt.readLong(); double d = excerpt.readDouble(); assert ch == 'M'; assert l == i; assert d == i; excerpt.finish();}ic.close();

Page 11: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

How does it perform

With one thread writing and another readingMessage

si7 PC (SSD)

i5 laptop (HDD)

10 million

1.5 seconds

4.3 seconds

100 million

13.7 seconds

53 seconds

200 million

26 seconds

308 seconds

500 million

53 seconds

1000 million

101 seconds

2000 million

199 seconds

Page 12: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

How does it recover?

Once finish() returns, the OS will do the rest.

If an excerpt is incomplete, it will be pruned.

Page 13: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Cache friendly

Data is laid out continuously, naturally packed. You can compress some types. One entry starts in the next byte to the previous one.

Page 14: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

How does it collect garbage?

There is an assumption that your application has a daily or weekly maintenance cycle.

This is implemented by closing the files and creating new ones. i.e. the whole lot is moved, compressed or deleted.

Anything which must be retained can be copied to the new Chronicle

Page 15: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Is there a higher level API?

You can hide the low level details with an interface.

Page 16: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Is there a higher level API?

There is a demo program with a simple interface.

This models a “hub” process which take in events, processes them and publishes results.

Page 17: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Is there a higher level API?

The interfaces look like this

public interface Gw2PeEvents {

public void small(MetaData metaData, SmallCommand command);

}

public interface Pe2GwEvents {

public void report(MetaData metaData, SmallReport smallReport);

}

On this laptop, it performs around 400K msg/sin and out, persisted.

Page 18: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

What does Chronicle need

More documentation

More tutorials

More use case examples

Page 19: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

What is planned

Make it easier to use

Text logging support

Low latency XML and FIX parser and writer

Page 20: (c) Higher Frequency Trading Introduction to Chronicle Micro second latency persistence Higher Frequency Trading (c) Peter Lawrey.

(c) Higher Frequency Trading

Q & A