Package com.higherfrequencytrading.chronicle.impl

Examples of com.higherfrequencytrading.chronicle.impl.IndexedChronicle


        String msg0 = "8=FIX.4.2 | 9=178 | 35=8 | 49=PHLX | 56=PERS | 52=20071123-05:30:00.000 | 11=ATOMNOCCC9990900 | 20=3 | 150=E | 39=E | 55=MSFT | 167=CS | 54=1 | 38=15 | 40=2 | 44=15 | 58=PHLX EQUITY TESTING | 59=0 | 47=C | 32=0 | 31=0 | 151=15 | 14=0 | 6=0 | 10=128 | ";
        String msg = msg0.replace(" | ", "" + (char) 1);

        String basePath = TMP + "/fix";
        ChronicleTools.deleteOnExit(basePath);
        IndexedChronicle chronicle = new IndexedChronicle(basePath);
        chronicle.useUnsafe(true);
        Excerpt excerpt = chronicle.createExcerpt();
        byte[] bytes = msg.getBytes();
        int runs = 1000000;
        for (int i = 0; i < runs; i++) {
            excerpt.startExcerpt(bytes.length);
            excerpt.write(bytes);
            excerpt.finish();
        }
        excerpt.index(-1);

        StringBuilder date = new StringBuilder();
        long start = System.nanoTime();
        while (excerpt.nextIndex()) {
            long l = excerpt.parseLong();
            assert l == 8;
            String s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("FIX.4.2");
            l = excerpt.parseLong();
            assert l == 9;
            l = excerpt.parseLong();

            l = excerpt.parseLong();
            assert l == 35;
            l = excerpt.parseLong();
            assert l == 8;

            l = excerpt.parseLong();
            assert l == 49;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("PHLX");

            l = excerpt.parseLong();
            assert l == 56;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("PERS");

            l = excerpt.parseLong();
            assert l == 52;
            date.setLength(0);
            excerpt.parseUTF(date, StopCharTesters.CONTROL_STOP);
            assert date.toString().equals("20071123-05:30:00.000");

            l = excerpt.parseLong();
            assert l == 11;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("ATOMNOCCC9990900");

            l = excerpt.parseLong();
            assert l == 20;
            l = excerpt.parseLong();
            assert l == 3;

            l = excerpt.parseLong();
            assert l == 150;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("E");

            l = excerpt.parseLong();
            assert l == 39;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("E");

            l = excerpt.parseLong();
            assert l == 55;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("MSFT");

            l = excerpt.parseLong();
            assert l == 167;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("CS");

            l = excerpt.parseLong();
            assert l == 54;
            l = excerpt.parseLong();
            assert l == 1;

            l = excerpt.parseLong();
            assert l == 38;
            l = excerpt.parseLong();
            assert l == 15;

            l = excerpt.parseLong();
            assert l == 40;
            l = excerpt.parseLong();
            assert l == 2;

            l = excerpt.parseLong();
            assert l == 44;
            l = excerpt.parseLong();
            assert l == 15;

            l = excerpt.parseLong();
            assert l == 58;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("PHLX EQUITY TESTING");

            l = excerpt.parseLong();
            assert l == 59;
            l = excerpt.parseLong();
            assert l == 0;

            l = excerpt.parseLong();
            assert l == 47;
            s = excerpt.parseEnum(String.class, StopCharTesters.CONTROL_STOP);
            assert s.equals("C");

            l = excerpt.parseLong();
            assert l == 32;
            l = excerpt.parseLong();
            assert l == 0;

            l = excerpt.parseLong();
            assert l == 31;
            l = excerpt.parseLong();
            assert l == 0;

            l = excerpt.parseLong();
            assert l == 151;
            l = excerpt.parseLong();
            assert l == 15;

            l = excerpt.parseLong();
            assert l == 14;
            l = excerpt.parseLong();
            assert l == 0;

            l = excerpt.parseLong();
            assert l == 6;
            l = excerpt.parseLong();
            assert l == 0;

            l = excerpt.parseLong();
            assert l == 10;
            l = excerpt.parseLong();
            assert l == 128;

            excerpt.finish();
        }
        long time = System.nanoTime() - start;
        System.out.printf("The average decode time was %,d ns%n", time / runs);
        chronicle.close();
    }
View Full Code Here


            stringsListener.inSync();
            intListener.inSync();

            replay(stringsListener);
            replay(intListener);
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "strings", String.class, new ArrayList<String>(), 8);
            strings.addListener(stringsListener);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 6);
            ints.addListener(intListener);

            dataStore.start();

            ints.add(0);
            strings.add("Hello");
            ints.add(1);
            strings.add("World");
            ints.add(2);

            strings.publishEvent("bye");
            ints.publishEvent("now");

            verify(stringsListener);
            verify(intListener);

            assertEquals("[Hello, World]", strings.toString());
            assertEquals("[0, 1, 2]", ints.toString());
            assertEquals(String[].class, strings.toArray().getClass());

            chronicle.close();
        }
        {
            ListListener stringsListener = createMock("strings", ListListener.class);
            stringsListener.eventStart(7, "strings");
            stringsListener.add("!");
            stringsListener.eventEnd(true);

            ListListener intListener = createMock("ints", ListListener.class);

            intListener.eventStart(8, "ints");
            intListener.add(3);
            intListener.eventEnd(true);

            stringsListener.inSync();
            intListener.inSync();

            replay(stringsListener);
            replay(intListener);

            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "strings", String.class, new ArrayList<String>(), 8);
            strings.addListener(stringsListener);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 6);
            ints.addListener(intListener);

            // assume we have  all the events written so far
            dataStore.start(chronicle.size() - 1);

            strings.add("!");
            ints.add(3);

            verify(stringsListener);
            verify(intListener);

            assertEquals("[Hello, World, !]", strings.toString());
            assertEquals("[0, 1, 2, 3]", ints.toString());
            chronicle.close();
        }
    }
View Full Code Here

        String name = TMP + "/testListPerformance";
        ChronicleTools.deleteOnExit(name);
        long start = System.nanoTime();
        int size = 0;
        {
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "test", String.class, new ArrayList<String>(), 9);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 9);
            dataStore.start();
            ints.clear();
            strings.clear();
            for (int j = 0; j < 10000; j++) {
                for (int i = 0; i < 100; i++) {
                    ints.add(i);
                    strings.add(Integer.toString(i));
                }
                size += Math.min(strings.size(), ints.size());
                for (int i = 0; i < 100; i++) {
                    ints.remove((Integer) i);
                    strings.remove(i);
                }
            }

            chronicle.close();
        }
        long mid = System.nanoTime();
        {
            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            ListWrapper<String> strings = new ListWrapper<String>(dataStore, "test", String.class, new ArrayList<String>(), 9);
            ListWrapper<Integer> ints = new ListWrapper<Integer>(dataStore, "ints", Integer.class, new ArrayList<Integer>(), 9);
            dataStore.start();
            chronicle.close();
        }
        long end = System.nanoTime();
        System.out.printf("Took %.1f seconds avg to add&remove %,d elements and %.1f seconds avg to reload them%n",
                (mid - start) / 2e9, size, (end - mid) / 2e9);
    }
View Full Code Here

        String name = TMP + "/inject";
        ChronicleTools.deleteOnExit(name);
        for (int i = 0; i < 10; i++) {
            ExampleDataModel model = new ExampleDataModel();

            Chronicle chronicle = new IndexedChronicle(name);
            DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
            dataStore.inject(model);
            final AtomicInteger map2Count = new AtomicInteger();
            model.map2.addListener(new AbstractMapListener<Date, ExampleDataModel.MyType>() {
                @Override
                public void update(Date key, ExampleDataModel.MyType oldValue, ExampleDataModel.MyType newValue) {
                    map2Count.incrementAndGet();
                }
            });
            final AtomicInteger list2Count = new AtomicInteger();
            model.list2.addListener(new AbstractCollectionListener<ExampleDataModel.MyType>() {
                @Override
                public void add(ExampleDataModel.MyType element) {
                    list2Count.incrementAndGet();
                }
            });
            final AtomicInteger set2Count = new AtomicInteger();
            model.set2.addListener(new AbstractCollectionListener<ExampleDataModel.MyType>() {
                @Override
                public void add(ExampleDataModel.MyType element) {
                    set2Count.incrementAndGet();
                }
            });
            dataStore.start();

            model.map.put(new Date(i * 1000), new ExampleDataModel.MyType());
            model.map2.put(new Date(i * 1000), new ExampleDataModel.MyType());
            model.list.add(new ExampleDataModel.MyType());
            model.list2.add(new ExampleDataModel.MyType());
            model.set.add(new ExampleDataModel.MyType());
            model.set2.add(new ExampleDataModel.MyType());

            assertEquals(i + 1, model.map.size());
            assertEquals(i + 1, map2Count.get());
            assertEquals(i + 1, model.list.size());
            assertEquals(i + 1, list2Count.get());
            assertEquals(i + 1, model.set.size());
            assertEquals(i + 1, set2Count.get());
            MyAnnotation annotation = model.map2.getAnnotation(MyAnnotation.class);
            assertNotNull(annotation);
            assertEquals("My text", annotation.value());
            chronicle.close();
        }
    }
View Full Code Here

    @Test
    public void testTCP() throws IOException, InterruptedException {
        int port = 65432;
        String masterPath = TMP + "/master";
        ChronicleTools.deleteOnExit(masterPath);
        InProcessChronicleSource masterC = new InProcessChronicleSource(new IndexedChronicle(masterPath), port);
        DataStore master = new DataStore(masterC, ModelMode.MASTER);
        ExampleDataModel masterModel = new ExampleDataModel();
        master.inject(masterModel);
        master.start();

        String copyPath = TMP + "/copy";
        ChronicleTools.deleteOnExit(copyPath);
        InProcessChronicleSink copyC = new InProcessChronicleSink(new IndexedChronicle(copyPath), "localhost", port);
        DataStore copy = new DataStore(copyC, ModelMode.READ_ONLY);
        ExampleDataModel copyModel = new ExampleDataModel();
        copy.inject(copyModel);
        copy.start();
View Full Code Here

    static class Repeater implements Runnable {
        private final InProcessChronicleSink chronicle;

        public Repeater(int test, int port, String hostname2, int port2) throws IOException {
            IndexedChronicle store = new IndexedChronicle(DIR + "/repeater-" + test);
            InProcessChronicleSource source = new InProcessChronicleSource(store, port);
            chronicle = new InProcessChronicleSink(source, hostname2, port2);
        }
View Full Code Here

        private final Future<?> future;
        private final InProcessChronicleSink sink;
        private final InProcessChronicleSource source;

        public Sender(int test, String hostname, int port, int port2) throws IOException {
            IndexedChronicle receiverStore = new IndexedChronicle(DIR + "/receiver-" + test);
            IndexedChronicle senderStore = new IndexedChronicle(DIR + "/sender-" + test);
            sink = new InProcessChronicleSink(receiverStore, hostname, port);
            source = new InProcessChronicleSource(senderStore, port2);
            future = reader.submit(new Reader(sink));
        }
View Full Code Here

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    IndexedChronicle ic = new IndexedChronicle(basePath);
                    ic.useUnsafe(true); // for benchmarks
                    Excerpt excerpt = ic.createExcerpt();
                    for (long i = 1; i <= runs; i += batchSize) {
                        excerpt.startExcerpt(13 * batchSize);
                        for (int k = 0; k < batchSize; k++) {
                            excerpt.writeUnsignedByte('M'); // message type
                            excerpt.writeLong(i); // e.g. time stamp
                            excerpt.writeFloat(i);
                        }
                        excerpt.finish();
                    }
                    ic.close();
                } catch (IOException e) {
                    throw new AssertionError(e);
                }
            }
        }).start();

        IndexedChronicle ic = new IndexedChronicle(basePath);
        ic.useUnsafe(true); // for benchmarks
        Excerpt excerpt = ic.createExcerpt();
        int blocks = 1000000;
        for (long j = 0; j < runs; j += blocks) {
            for (long i = j + 1; i <= j + blocks; i += batchSize) {
                while (!excerpt.nextIndex()) {
                    // busy wait
                }
                for (int k = 0; k < batchSize; k++) {
                    char ch = (char) excerpt.readUnsignedByte();
                    long l = excerpt.readLong();
                    float d = excerpt.readFloat();
                    assert ch == 'M';
                    assert l == i;
                    assert d == (float) i;
                }
                excerpt.finish();
            }
            if (((j + blocks) % 100000000) == 0) {
                long time = System.nanoTime() - start;
                System.out.printf("... Took %.2f to write and read %,d entries%n", time / 1e9, j + blocks);
            }
        }
        ic.close();

        long time = System.nanoTime() - start;
        System.out.printf("Took %.2f to write and read %,d entries%n", time / 1e9, runs);
    }
View Full Code Here

            return -1;
        }
    };

    public ExampleKeyedExcerptMain(String basePath) throws IOException {
        chronicle = new IndexedChronicle(basePath);
        excerpt = chronicle.createExcerpt();
    }
View Full Code Here

public class TestManyUpdatesMain {
    public static void main(String... ignored) throws IOException {
        String basePath = System.getProperty("java.io.tmpdir") + "/updates";
        ChronicleTools.deleteOnExit(basePath);
        long start = System.nanoTime();
        IndexedChronicle chronicle = new IndexedChronicle(basePath);
        int count = 1000 * 1000;
        for (Excerpt e = chronicle.createExcerpt(); e.index() < count; ) {
            e.startExcerpt(100);
            e.append("id=").append(e.index()).append(",name=lyj").append(e.index());
            e.finish();
        }
        chronicle.close();
        long time = System.nanoTime() - start;
        System.out.printf("%,d inserts took %.3f seconds%n", count, time / 1e9);
    }
View Full Code Here

TOP

Related Classes of com.higherfrequencytrading.chronicle.impl.IndexedChronicle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.