This is a FAST coder benchmark application.
Item | Description |
---|---|
conf/sample/FastBenchmark.properties | sample configuration |
conf/sample/cmeTemplate.xml | CME templates |
conf/logback.xml | Logback logging facility configuration |
conf/sample/fixDialect.xml | FIX dialects |
conf/sample/*.bin | test data |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import biz.onixs.fix.dictionary.Version; import biz.onixs.fix.engine.Engine; import biz.onixs.fix.fast.FastVersion; import biz.onixs.util.settings.PropertyBasedSettings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class FastBenchmarkRunner { private static final Logger LOG = LoggerFactory.getLogger(FastBenchmarkRunner. class ); public void run() { // Init FIX Engine final PropertyBasedSettings settings = new PropertyBasedSettings( "sample/FastBenchmark.properties" ); final Engine engine = Engine.init(settings); // final Benchmarker benchmarker = new Benchmarker(); // final DecodeBenchmark benchmark = new DecodeBenchmark(); benchmark.setId( "FastDec-0" ); benchmark.setFastTemplates( "sample/cmeTemplate.xml" ); benchmark.setFastVersion(FastVersion.FAST_1_1); benchmark.setFixEngineProperties( "sample/FastBenchmark.properties" ); benchmark.setFixVersion(Version.getById( "CmeFix50" )); benchmark.setIterationNumber(500000L); benchmark.setInputFile( "sample/cmeSecurityDefinition_2007-11-21.txt" ); benchmarker.run(benchmark); // benchmark.setId( "FastDec-1" ); benchmark.setInputFile( "sample/cmeBinaryFastMessage2.txt" ); benchmarker.run(benchmark); // benchmark.setId( "FastDec-2" ); benchmark.setInputFile( "sample/CmeSnapshotFullRefresh.txt" ); benchmarker.run(benchmark); // // Shutdown FIX Engine engine.shutdown(); } public static void main( final String[] args) { try { final FastBenchmarkRunner benchmarkRunner = new FastBenchmarkRunner(); benchmarkRunner.run(); } catch ( final Throwable throwable) { LOG.error(throwable.getMessage(), throwable); } } } |
The following classes are used in the sample:
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | import biz.onixs.util.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Benchmarker { private static final Logger LOG = LoggerFactory.getLogger(Benchmarker. class ); public Benchmarker() { LOG.debug(Utils.systemProperties2String()); } public void run( final Benchmark benchmark) { boolean statusOK = true ; LOG.info( "Benchmark begin: {}" , benchmark); final long iterationNum = benchmark.getIterationNumber(); LOG.info( "Iteration number: {}" , iterationNum); try { benchmark.setUp(); } catch ( final Exception e) { LOG.error( "Exception during 'setUp' step, stopping benchmark." , e); statusOK = false ; } long startTime = 0L; long stopTime = 0L; if (statusOK) { long l = 0L; try { startTime = System.nanoTime(); while (l < iterationNum) { benchmark.doAction(); l++; } stopTime = System.nanoTime(); } catch ( final Exception e) { LOG.error( "Exception on the iteration #{}, stopping benchmark." , l, e); statusOK = false ; } } try { benchmark.tearDown(); } catch ( final Exception e) { LOG.error( "Exception during 'tearDown' step." , e); statusOK = false ; } if (statusOK) { final long deltaTime = stopTime - startTime; if (0L == deltaTime) { LOG.warn( "Delta time is 0, please increase iteration number." ); } LOG.info( "Delta time in nanos: {}" , deltaTime); final double speed = (iterationNum * 1000000000L) / (( double ) deltaTime); LOG.info( "Speed: {} it/sec" , speed); } LOG.info( "Benchmark end: {}" , benchmark); } } |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import biz.onixs.fix.fast.Decoder; import org.apache.commons.io.IOUtils; import java.util.Base64; public class DecodeBenchmark extends OnixsFastBenchmark { private byte [] inMsg = null ; private Decoder decoder = null ; @Override public void setUp() throws Exception { super .setUp(); inMsg = Base64.getDecoder().decode(IOUtils.toByteArray(getResourceLoader().getResource(getInputFile()))); decoder = new Decoder(getTemplateStream(), getFastVersion(), getFixVersion()); } @Override public void doAction() { decoder.decode(inMsg); } @Override public String toString() { return "DecodeBenchmark{" + toStringShort() + '}' ; } } |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import biz.onixs.fix.dictionary.Version; import biz.onixs.fix.fast.FastVersion; import biz.onixs.util.url.ResourceLoader; import biz.onixs.util.url.ResourceLoaderUtil; import java.io.InputStream; public abstract class OnixsFastBenchmark extends AbstractFastBenchmark { private final ResourceLoader resourceLoader = ResourceLoaderUtil.DEFAULT_LOADER; private FastVersion fastVersion = null ; private String fixEngineProperties = null ; private Version fixVersion = null ; public ResourceLoader getResourceLoader() { return resourceLoader; } public FastVersion getFastVersion() { return fastVersion; } public void setFastVersion( final FastVersion fastVersion) { this .fastVersion = fastVersion; } public String getFixEngineProperties() { return fixEngineProperties; } public void setFixEngineProperties( final String fixEngineProperties) { this .fixEngineProperties = fixEngineProperties; } public Version getFixVersion() { return fixVersion; } public void setFixVersion( final Version fixVersion) { this .fixVersion = fixVersion; } public InputStream getTemplateStream() { return resourceLoader.getResource(getFastTemplates()); } @Override public void setUp() throws Exception { } @Override public void tearDown() { } @Override public String toStringShort() { return super .toStringShort() + ", fixVersion=" + fixVersion.getId() + ", fastVersion=" + fastVersion + '\'' ; } @Override public String toString() { return "FastBenchmark{" + toStringShort() + '}' ; } } |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | public abstract class AbstractFastBenchmark extends AbstractBenchmark { private String fastTemplates = null ; private String inputFile = null ; public String getFastTemplates() { return fastTemplates; } public void setFastTemplates( final String fastTemplates) { this .fastTemplates = fastTemplates; } public String getInputFile() { return inputFile; } public void setInputFile( final String inputFile) { this .inputFile = inputFile; } @Override public String toStringShort() { return super .toStringShort() + ", fastTemplates='" + fastTemplates + '\ '' + ", inputFile='" + inputFile + '\ '' ; } @Override public String toString() { return "AbstractFastBenchmark{" + toStringShort() + '}' ; } } |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | public abstract class AbstractBenchmark implements Benchmark { private String id = null ; private long iterationNumber = 0L; public String getId() { return id; } public void setId( final String id) { this .id = id; } @Override public long getIterationNumber() { return iterationNumber; } public void setIterationNumber( final long iterationNumber) { this .iterationNumber = iterationNumber; } public String toStringShort() { return "id='" + id + '\ '' + ", iterationNumber=" + iterationNumber; } @Override public String toString() { return "AbstractBenchmark{" + toStringShort() + '}' ; } } |
22 23 24 25 26 27 28 29 30 | public interface Benchmark { void setUp() throws Exception; void doAction() throws Exception; void tearDown() throws Exception; long getIterationNumber(); } |