Fan-out case (delivery message to several recipients) is a standard task for market data routing. Such mechanism may be used for other solutions too.
FIX Antenna Java allows implementing effective fan-out solutions.
The main idea of effective implementation with FIX Antenna Java is reducing simultaneous access to outgoing sessions. Such an approach leads to getting the best performance. All outgoing sessions should be divided into few groups. Each such group is served by a separate worker thread. The original message should be copied to each target worker.
Such logic can be encapsulated into separate Dispatcher component:
You can find fan-out sample in FIX Antenna Java package (benchmarks\src\main\java\com\epam\benchmark\fanout\server\).
Dispatcher has access to queues of worker threads and can copy the original message to the necessary queues, which are related to required destinations sessions:
To reduce memory allocations, Dispatcher copy the original message to the message instance from the object pool. Such tactic provides faster processing than regular creating of new instance and helps to build 0GC applications.
In case of simplest delivering a message to all destination sessions, each working thread get own message copy from the queue and resend it to the sessions, which it is responsible for
Example of fan-out benchmark in FIXAJ
FIX Antenna package provides an example of such fan-out implementation in benchmark subdirectory. This implementation demonstrates the works of a fan-out gateway and provides mechanisms for measuring its performance.
The source code of fan-out benchmark is available in benchmarks/src/com/epam/benchmark/fanout subfolder of the package. It consists from such elements:
com.epam.benchmark.fanout.FanoutConfiguration - constants, which are used in benchmark implementation;
- com.epam.benchmark.fanout.client.MDProducerClient - producers of test FIX messages. It simulates Exchanges, which send 'W' messages to the fan-out router;
- com.epam.benchmark.fanout.client.MDConsumerClient - consumers of messages from the fan-out server. Simulates Traders, which consume 'W' messages for possible decision making;
- com.epam.benchmark.fanout.server.FanoutServer - fan-out router implementation, which receives messages from produces and route them to consumers;
- com.epam.benchmark.fanout.server.MessageDispatcher and MessageQueue - Dispatcher component implementation;
- com.epam.benchmark.fanout.BenchmarkReporter - program, which can parse pcap files and provide a performance report;
The scripts to run fan-out programs and measure performance are available in the benchmarks subfolder of the package:
- runFanoutServerWithTCPDump.sh - script to run fan-out server with pcap file recording;
- runFanoutConsumers.sh - script to run fan-out consumers;
- runFanoutProducers.sh - script to run fan-out producers;
- runFanoutReporter.sh - script to run performance report generation from pcap file;
The logger and FIXAJ configuration files for all components there are in benchmarks/etc/benchmark/fanout subfolder of the package.
The test message, which is used for routing, there is also inside the package: benchmarks/etc/benchmark/fanout/producer/snapshot.fix
How to run fan-out benchmark in FIXAJ
- Unpack FIX Antenna Java package (fixaj-engine-full-X.Y.Z.zip);
Run fan-out server (Gateway simulator):
NOTE: please make sure that user has permissions to collect TCP dumps.
- Run consumer clients (Traders simulators): ./runFanoutConsumers.sh <serverHost> <clientNum> <progressPrintRateNum>
- serverHost - fan-out server's host;
- clientNum - number of consumer clients;
- progressPrintRateNum - the rate of progress indicator in the console, e.g. "Total number of already received Snapshots(W): 45000". Optional: default value is every 1000 msgs;
Run producer clients (Exchange simulators): ./runFanoutProducer.sh <serverHost> <clientNum> <msgPerSession> <msgPerSecond> <fanoutMsgNum>
serverHost - fan-out server's host;
clientNum - the number of producer clients (Exchange FIX sessions);
msgPerSession - total number of messages to send per FIX session;
msgPerSecond - the rate of messages per session. E.g. 100 means a message every 10msec;
fanoutMsgNum - fanout setting. E.g. 50 means mark each 50th as expected to send in fan-out scenario; Optional: by default equals to clientNum;
Producer clients program uses a test message template (benchmarks/etc/benchmark/fanout/producer/snapshot.fix) to send it to the fan-out server. It needs to wait till it sends all messages to the server, stop its works and exit.
Producer clients program exits when it send all messages. Then it needs to stop manually Consumer clients program and fan-out server:
Note: Please check that no dropped packets on fan-out server. Otherwiseplease check your environment.
Run performance report generation: ./runFanoutReporter.sh <pcapFilePath> <skipNum>
pcapFilePath - path to pcap file to parse and build report;
skipNum - number of first records which should be not added to histogram (warmup period of all fan-out benchmark components); Optional: default value is 1000;