Package com.higherfrequencytrading.chronicle.tcp

Examples of com.higherfrequencytrading.chronicle.tcp.InProcessChronicleSink


        Chronicle chronicle2w = new IndexedChronicle(basePath2);
        EventsWriter writer2 = new EventsWriter(chronicle2w);

        Chronicle chronicle1 = new IndexedChronicle(basePath1);
        InProcessChronicleSink sink = new InProcessChronicleSink(chronicle1, HOST, PORT);
        final EventsReader sinkReader = new EventsReader(sink.createExcerpt(), new BrokerEvents(writer2),
                TimingStage.SourceRead, TimingStage.EngineWrite);

        Thread cbt = new Thread(new Runnable() {
            @Override
            public void run() {
View Full Code Here


        String basePath3 = TMP + "/3-sink";

        ChronicleTools.deleteOnExit(basePath3);

        Chronicle chronicle3 = new IndexedChronicle(basePath3);
        InProcessChronicleSink sink3 = new InProcessChronicleSink(chronicle3, HOST3, PORT3);
        final EventsReader sinkReader = new EventsReader(sink3.createExcerpt(), new LatencyEvents(), TimingStage.SinkRead, TimingStage.EngineWrite);

        while (true) {
            if (!sinkReader.read())
                pause();
        }
View Full Code Here

        MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>(dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);
        dataStore.start();
        ints.clear();
        strings.clear();

        InProcessChronicleSink chronicle2 = new InProcessChronicleSink(new IndexedChronicle(name2), "localhost", PORT);
        DataStore dataStore2 = new DataStore(chronicle2, ModelMode.READ_ONLY);
        MapWrapper<String, String> strings2 = new MapWrapper<String, String>(dataStore2, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16);
        MapWrapper<Integer, Integer> ints2 = new MapWrapper<Integer, Integer>(dataStore2, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);

        final AtomicInteger sai = new AtomicInteger();
        MapListener<String, String> stringsListener = new AbstractMapListener<String, String>() {
            @Override
            public void update(String key, String oldValue, String newValue) {
//                System.out.println(key + " " + oldValue + " => " + newValue);
                sai.incrementAndGet();
            }

            @Override
            public void inSync() {
//                System.out.println("inSync");
            }
        };
        strings2.addListener(stringsListener);

        final AtomicInteger iai = new AtomicInteger();
        MapListener<Integer, Integer> intsListener = new AbstractMapListener<Integer, Integer>() {
            @Override
            public void update(Integer key, Integer oldValue, Integer newValue) {
//                System.out.println(key + " " + oldValue + " => " + newValue);
                iai.incrementAndGet();
            }
        };
        ints2.addListener(intsListener);
        dataStore2.start();

        int count = 0;
        for (int j = 0; j < 1000; j++) {
            int collectionSize = 1000;
            for (int i = 0; i < collectionSize; i++) {
                ints.put(i, i + j);
                strings.put(Integer.toString(i), Integer.toString(i + j));
            }
            size += Math.min(strings.size(), ints.size());
            for (int i = 0; i < collectionSize; i++) {
                ints.remove(i);
                strings.remove(Integer.toString(i));
            }
            count += 4 * collectionSize;
        }
        long mid = System.nanoTime();

//        int timeout = 0;
        while (dataStore2.events() < count) {
//            if (timeout++ % 10000 == 0)
//                System.out.println(dataStore2.events());
            Thread.sleep(1);
        }

        long end = System.nanoTime();

        System.out.printf("Startup and write took %.2f us on average and read and shutdown took %.2f on average%n",
                (mid - start) / count / 1e3, (end - mid) / count / 1e3);

//        Thread.sleep(10000);

        chronicle.close();
        chronicle2.close();
    }
View Full Code Here

        MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>(dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);
        dataStore.start();
        ints.clear();
        strings.clear();

        InProcessChronicleSink chronicle2 = new InProcessChronicleSink(new IndexedChronicle(name2), "localhost", PORT);
        DataStore dataStore2 = new DataStore(chronicle2, ModelMode.READ_ONLY);
        MapWrapper<String, String> strings2 = new MapWrapper<String, String>(dataStore2, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16);
        MapWrapper<Integer, Integer> ints2 = new MapWrapper<Integer, Integer>(dataStore2, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);

        final AtomicInteger sai = new AtomicInteger();
        MapListener<String, String> stringsListener = new AbstractMapListener<String, String>() {
            @Override
            public void update(String key, String oldValue, String newValue) {
//                System.out.println(key + " " + oldValue + " => " + newValue);
                sai.incrementAndGet();
            }
        };
        strings2.addListener(stringsListener);

        final AtomicInteger iai = new AtomicInteger();
        MapListener<Integer, Integer> intsListener = new AbstractMapListener<Integer, Integer>() {
            @Override
            public void update(Integer key, Integer oldValue, Integer newValue) {
//                System.out.println(key + " " + oldValue + " => " + newValue);
                iai.incrementAndGet();
            }
        };
        ints2.addListener(intsListener);
        dataStore2.start();

        Map<String, String> ssMap = new LinkedHashMap<String, String>();
        Map<Integer, Integer> iiMap = new LinkedHashMap<Integer, Integer>();
        int count = 0;
        int collectionSize = 2000;
        for (int i = 0; i < collectionSize; i++) {
            iiMap.put(i, i);
            ssMap.put(Integer.toString(i), Integer.toString(i));
        }
        for (int j = 0; j < 2500; j++) {
            strings.putAll(ssMap);
            ints.putAll(iiMap);
            strings.clear();
            ints.clear();
            count += 4;
        }
        long mid = System.nanoTime();

//        int timeout = 0;
        while (dataStore2.events() < count) {
            Thread.sleep(1);
        }

        long end = System.nanoTime();

        System.out.printf("Startup and write took %.2f us on average (per key) and read and shutdown took %.2f us on average (per key)%n",
                (mid - start) / count / collectionSize / 1e3, (end - mid) / count / collectionSize / 1e3);

        chronicle.close();
//        System.gc();
        chronicle2.close();
    }
View Full Code Here

        MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>(dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);
        dataStore.start();
        ints.clear();
        strings.clear();

        InProcessChronicleSink chronicle2 = new InProcessChronicleSink(new IndexedChronicle(name2), "localhost", PORT);
        DataStore dataStore2 = new DataStore(chronicle2, ModelMode.READ_ONLY);
        MapWrapper<String, String> strings2 = new MapWrapper<String, String>(dataStore2, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16);
        MapWrapper<Integer, Integer> ints2 = new MapWrapper<Integer, Integer>(dataStore2, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16);

        final AtomicInteger sai = new AtomicInteger();
        MapListener<String, String> stringsListener = new AbstractMapListener<String, String>() {
            @Override
            public void update(String key, String oldValue, String newValue) {
//                System.out.println(key + " " + oldValue + " => " + newValue);
                sai.incrementAndGet();
            }
        };
        strings2.addListener(stringsListener);

        final AtomicInteger iai = new AtomicInteger();
        MapListener<Integer, Integer> intsListener = new AbstractMapListener<Integer, Integer>() {
            @Override
            public void update(Integer key, Integer oldValue, Integer newValue) {
//                System.out.println(key + " " + oldValue + " => " + newValue);
                iai.incrementAndGet();
            }
        };
        ints2.addListener(intsListener);
        dataStore2.start();

        Map<String, String> ssMap = new LinkedHashMap<String, String>();
        Map<Integer, Integer> iiMap = new LinkedHashMap<Integer, Integer>();
        int count = 2; // one clear per collection
        int collectionSize = 2000;
        for (int i = 0; i < collectionSize; i++) {
            iiMap.put(i, i);
            ssMap.put(Integer.toString(i), Integer.toString(i));
        }

        strings.putAll(ssMap);
        ints.putAll(iiMap);
        count += 2;

        Thread.sleep(100);
//        int timeout = 0;
        while (dataStore2.events() < count || ints2.size() < collectionSize) {
//            if (timeout++ % 10000 == 0)
//                System.out.println(dataStore2.events());
            Thread.sleep(1);
        }

        assertEquals(collectionSize, strings.size());
        assertEquals(collectionSize, strings2.size());
        assertEquals(collectionSize, ints.size());
        assertEquals(collectionSize, ints2.size());
        System.out.println("=== performing get test ===");
        int gets = 0;
        for (int j = 0; j < 10000; j++) {
            for (String s : ssMap.keySet()) {
                String s1 = strings.get(s);
                String s2 = strings2.get(s);
                if (s1 == null)
                    assertNotNull(s1);
                if (!s1.equals(s2))
                    assertEquals(s1, s2);
            }
            gets += ssMap.size();
            for (Integer i : iiMap.keySet()) {
                Integer i1 = ints.get(i);
                Integer i2 = ints2.get(i);
                if (i1 == null)
                    assertNotNull(i1);
                if (!i1.equals(i2))
                    assertEquals(i1, i2);
            }
            gets += iiMap.size();
        }

        chronicle.close();
        chronicle2.close();
        long end = System.nanoTime();

        System.out.printf("Average get time including startup, bootstrap and shutdown, took %.3f us average per key%n",
                (end - start) / gets / 1e3);
    }
View Full Code Here

        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

        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 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

            }
        });

        String snkBasePath = baseDir + "/IPCT.testOverTCP.sink";
        ChronicleTools.deleteOnExit(snkBasePath);
        Chronicle sink = new InProcessChronicleSink(new IndexedChronicle(snkBasePath), "localhost", PORT + 1);

        long start = System.nanoTime();
        t.start();
        Excerpt excerpt = sink.createExcerpt();
        int count = 0;
        for (int i = 1; i <= messages; i++) {
            while (!excerpt.nextIndex())
                count++;
            long n = excerpt.readLong();
            assertEquals(i, n);
            excerpt.finish();
        }
        sink.close();
        System.out.println("There were " + count + " misses");
        t.join();
        source.close();
        long time = System.nanoTime() - start;
        System.out.printf("Messages per second %,d%n", (int) (messages * 1e9 / time));
View Full Code Here

        Chronicle source = new InProcessChronicleSource(new IndexedChronicle(sourceName), PORT + 2);
        PriceWriter pw = new PriceWriter(source.createExcerpt());

        String sinkName = baseDir + "/price.sink";
        ChronicleTools.deleteOnExit(sinkName);
        Chronicle sink = new InProcessChronicleSink(new IndexedChronicle(sinkName), "localhost", PORT + 2);

        final AtomicInteger count = new AtomicInteger();
        PriceReader reader = new PriceReader(sink.createExcerpt(), new PriceListener() {
            @Override
            public void onPrice(long timeInMicros, String symbol, double bp, int bq, double ap, int aq) {
                count.incrementAndGet();
            }
        });
        pw.onPrice(1, "symbol", 99.9, 1, 100.1, 2);
        reader.read();

        long start = System.nanoTime();
        int prices = 12000000;
        for (int i = 1; i <= prices; i++) {
            pw.onPrice(i, "symbol", 99.9, i, 100.1, i + 1);
        }

        long mid = System.nanoTime();
        while (count.get() < prices)
            reader.read();

        long end = System.nanoTime();
        System.out.printf("Took an average of %.2f us to write and %.2f us to read%n",
                (mid - start) / prices / 1e3, (end - mid) / prices / 1e3);


        source.close();
        sink.close();
    }
View Full Code Here

TOP

Related Classes of com.higherfrequencytrading.chronicle.tcp.InProcessChronicleSink

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.