Giter Club home page Giter Club logo

falcon's Introduction

Falcon

Falcon is a high performance, low latency FIX engine for the JVM. It provides an API that enables FIX connectivity for both buy side and sell side applications such as trading systems and order management systems.

The engine is designed to avoid heap allocations on the TX and RX paths to avoid GC pauses that are disastrous for low-latency applications. The engine is packed with other optimizations such as avoiding querying the system clock for every message and open-coding formatting and parsing functions where the JRE allocates memory implicitly.

Falcon is able to achieve 8 µs RTT on when running the latency tester client and server on the same machine.

Features

  • Zero-copy, non-blocking, low-latency NIO networking
  • Low heap allocation rate in the FIX engine core
  • Small memory footprint for session and message data structures

Example

An example application that sends 100000 NewOrderSingle messages looks like this:

import static java.net.StandardSocketOptions.*;
import java.nio.channels.*;
import java.net.*;
import java.nio.*;

import static falcon.fix.MessageTypes.*;
import static falcon.fix.Versions.*;
import static falcon.fix.Tags.*;
import falcon.fix.*;

public class Example {
  public static void main(String[] args) throws Exception {
    SocketChannel socket = connect("localhost", 7070);

    Session session = new Session(socket, FIX_4_2, "HERMES", "INET");

    session.updateTime();

    session.send(new Message.Builder(Logon)
        .add(new Field(EncryptMethod, "0" ))
        .add(new Field(HeartBtInt,    "30"))
        .build());

    Message newOrder =
      new Message.Builder(NewOrderSingle)
          .add(new Field(EncryptMethod, "0" ))
          .add(new Field(HeartBtInt,    "30"))
          .build();

    for (int i = 0; i < 100000; i++) {
      if ((i % 10000) == 0) {
        session.updateTime();
      }
      session.send(newOrder);
    }

    session.updateTime();

    session.send(new Message.Builder(Logout).build());

    socket.close();
  }

  private static SocketChannel connect(String host, int port) throws Exception {
    InetSocketAddress addr = new InetSocketAddress(host, port);
    SocketChannel socket = SocketChannel.open();
    socket.configureBlocking(false);
    socket.setOption(TCP_NODELAY, true);
    socket.connect(addr);
    socket.finishConnect();
    return socket;
  }
}

Performance

The FIX engine has been measured to have 8 µs RTT for a loopback ping-pong test where client sends a NewOrderSingle message and waits for an ExecutionReport message to arrive. The numbers include the time spent in Linux TCP/IP stack and the loopback device.

To reproduce the results, first download and build Libtrading. Then start the FIX performance test server:

$ taskset -c 0 tools/fix/fix_server -m 1 -p 7070

Finally, run the Falcon latency tests:

$ ./falcon-perf-test/bin/falcon-perf-test 1000000
87693.5 messages/second
min/avg/max = 9.8/11.4/19935.3 µs
Percentiles:
  1.00%: 10.15 µs
  5.00%: 10.51 µs
 10.00%: 10.61 µs
 50.00%: 11.12 µs
 90.00%: 11.90 µs
 95.00%: 13.27 µs
 99.00%: 14.53 µs

License

Copyright © 2013-2015 Pekka Enberg and contributors

Falcon is distributed under the 2-clause BSD license.

falcon's People

Contributors

jheusser avatar jvirtanen avatar penberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

falcon's Issues

No specific subclasses for fields?

Hi!

There are no Field subclasses for Field for specific fieldsm like NoRelatedSym, MDReqID etc?
Is this intentionally, so you have to use new Field( , ) ?
Make the sources no very usable, I think? I wrote me a simple code generator in Python to create subclasses from a simple text file.
Maybe this costs some performance, but creates nicer sources?

Ciao,
Andreas

Session.recv() are not working

I checked the code and see that recv() just return a empty Message. Is the method supposed to run or it's just a temp place holder?

Also the Session class are littered with System.out.println?

Missing message types

Hi!

Thanks for your great work!

Maybe you could add 2 message types?

public static final MessageType OrderCancelRequest = new MessageType("F");
public static final MessageType MarketDataRequest = new MessageType("V");

I created a subclass of the MessageTypes just to add these 2. So I could remove this class.

about get msg fields in Session.recv()

Hi,
In the recv() method(Session.java), parse a step message and get it's fields. The code is below:
while (rxBuf.position() < checksumOffset) {
int tag = Protocol.parseInt(rxBuf, (byte)'=');
ByteString value = Protocol.parseString(rxBuf, (byte)0x01);
fields.add(new Field(tag, value));
}
Maybe there is a bug in while loop:
parseString(ByteBuffer buf, byte delimiter) {
int start = buf.position();
for (;;) {
byte ch = buf.get();
if (ch == delimiter) {
break;
}
}
//buffer's posion is one after delimiter
//the end is pointer to delimiter
int end = buf.position() - 1;
buf.position(start);
return ByteString.of(buf, end-start);
}
after return ,the buffer's postion is pointer to delimiter. If next call parseInt(), the tag is error.
I think it should add rxBuf.get() before fields.add().
And I submit a SessionTest for this. Please check it. Thanks.

Add groups to messages?

Hi!

I'm struggling with groups in messages at the moment. I guess it would be useful to write a Group class to make adding a group to a message more easy?

Ciao,
Andreas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.