Package com.higherfrequencytrading.chronicle

Examples of com.higherfrequencytrading.chronicle.Excerpt


public class JETest {
    public static void main(String[] args) throws Exception {
        final String basePath = "test";
        ChronicleTools.deleteOnExit(basePath);
        final Chronicle chronicle = new IntIndexedChronicle(basePath);
        final Excerpt excerpt = chronicle.createExcerpt();
        final int[] consolidates = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
        int repeats = 10000;
        for (int i = 0; i < repeats; i++) {
            excerpt.startExcerpt(8 + 4 + 4 * consolidates.length);
            excerpt.writeLong(System.nanoTime());
            excerpt.writeInt(consolidates.length);
            for (final int consolidate : consolidates) {
                excerpt.writeInt(consolidate);
            }
            excerpt.finish();
        }

        long[] times = new long[repeats];
        int[] nbcs = new int[repeats];
        int count = 0;
        final Excerpt excerpt2 = chronicle.createExcerpt();
        while (excerpt2.nextIndex()) {
            final long timestamp = excerpt2.readLong();
            long time = System.nanoTime() - timestamp;
            times[count] = time;
            final int nbConsolidates = excerpt2.readInt();
            nbcs[count] = nbConsolidates;
            for (int i = 0; i < nbConsolidates; i++) {
                excerpt2.readInt();
            }
            excerpt2.finish();
            count++;
        }
        for (int i = 0; i < count; i++) {
            System.out.print("latency: " + times[i] / repeats / 1e3 + " us average, ");
            System.out.println("nbConsolidates: " + nbcs[i]);
View Full Code Here


    @Test
    public void testLookup() throws Exception {
        PackedHashedTable pht = new PackedHashedTable(baseDir + "/deleteme", 2, 4, 64);
        pht.deleteOnExit();

        Excerpt record = pht.startRecord();
        record.writeLong(1234567890L);
        pht.endRecord(1111);

        final boolean[] found = {false};
        pht.lookup(1111, new PackedHashedTable.HashRecordIterator() {
            @Override
View Full Code Here

        long start = 0;
        for (int i = -warmup; i < rows; i++) {
            if (i == 0)
                start = System.nanoTime();
            Excerpt record = pht.startRecord();
            record.writeInt(i);
            int pos = record.position();
            // field "c"
            record.append(i); // as text.
            record.write(xs, 0, pos + 120 - record.position());

            // field "pad"
            int pos2 = record.position();
            record.append(i); // as text.
            record.write(ys, 0, pos2 + 120 - record.position());
            pht.endRecord(i);
        }
        long mid = System.nanoTime();
/*
    def query_process(host, port, pipe_to_parent, requests_per, dbname, rows, check, id):
View Full Code Here

        String basePath = baseDir + "/deleteme.int";
        Chronicle chronicle = new IntIndexedChronicle(basePath);
        deleteOnExit(basePath);

        Excerpt record = chronicle.createExcerpt();
        final int warmup = 20000;
        final int rows = 1000000;

        byte[] xs = new byte[120];
        Arrays.fill(xs, (byte) 'x');
        byte[] ys = new byte[120];
        Arrays.fill(ys, (byte) 'y');

        long start = 0;
        for (int i = -warmup; i < rows; i++) {
            if (i == 0)
                start = System.nanoTime();
            record.startExcerpt(256);
            record.writeInt(i + warmup);
            int pos = record.position();
            // field "c"
            record.append(i + warmup); // as text.
            record.write(xs, 0, pos + 120 - record.position());

            // field "pad"
            int pos2 = record.position();
            record.append(i + warmup); // as text.
            record.write(ys, 0, pos2 + 120 - record.position());
            record.finish();
        }
        long mid = System.nanoTime();
/*
    def query_process(host, port, pipe_to_parent, requests_per, dbname, rows, check, id):
      conn = pymongo.Connection(host, port)
      db = conn[dbname]
      gets = 0
      while True:
        for loop in xrange(0, requests_per):
          target = random.randrange(0, rows)
          o = db.c.find_one({'_id': target})
          assert o['_id'] == target
          if check:
            assert o['k'] == target
            sx = str(o['id'])
            lsx = len(sx)
            assert o['c'] == sx+'x'*(120-lsx)
            assert o['pad'] == sx+'y'*(120-lsx)

          gets += 1
*/
        int ptr = -1;
        final MyHashRecordIterator iterator = new MyHashRecordIterator();

        for (int i = 0; i < rows; i++) {
            // pseudo random walk
            ptr += 1019;
            ptr %= rows;

            assertTrue(record.index(ptr));
            iterator.found = false;
            iterator.ptr = ptr;
            iterator.onExcerpt(record);

            //noinspection ConstantConditions
View Full Code Here

                    tsc.useUnsafe(USE_UNSAFE);
                    final IndexedChronicle tsc2 = new IndexedChronicle(basePath2);
                    tsc2.useUnsafe(USE_UNSAFE);
                    tsc2.clear();

                    Excerpt excerpt = tsc.createExcerpt();
                    Excerpt excerpt2 = tsc2.createExcerpt();
                    for (int i = 0; i < RUNS; i++) {
                        do {
                            busyWait();
                        } while (!excerpt.index(i));

                        char type = excerpt.readChar();
                        if ('T' != type)
                            assertEquals('T', type);
                        int n = excerpt.readInt();
                        if (i != n)
                            assertEquals(i, n);
                        excerpt.readChars(sb);
                        excerpt.finish();

                        excerpt2.startExcerpt(8);
                        excerpt2.writeChar('R');
                        excerpt2.writeInt(n);
                        excerpt2.writeShort(-1);
                        excerpt2.finish();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        Excerpt excerpt = tsc.createExcerpt();
        Excerpt excerpt2 = tsc2.createExcerpt();
        long start = System.nanoTime();
        int i2 = 0;
        for (int i = 0; i < RUNS; i++) {
            excerpt.startExcerpt(32);
            excerpt.writeChar('T');
            excerpt.writeInt(i);
            excerpt.writeChars("Hello World!");
            excerpt.finish();

            while (excerpt2.index(i2)) {
                char type = excerpt2.readChar();
                if ('R' != type)
                    assertEquals('R', type);
                int n = excerpt2.readInt();
                if (i2 != n)
                    assertEquals(i2, n);
                excerpt2.finish();
                i2++;
            }
        }

        for (; i2 < RUNS; i2++) {
            do {
                busyWait();
            } while (!excerpt2.index(i2));
            char type = excerpt2.readChar();
            if ('R' != type)
                assertEquals('R', type);
            int n = excerpt2.readInt();
            if (i2 != n)
                assertEquals(i2, n);
            excerpt2.finish();
        }

        t.join();
        long time = System.nanoTime() - start;
        tsc.close();
View Full Code Here

                    tsc.useUnsafe(USE_UNSAFE);
                    final IndexedChronicle tsc2 = new IndexedChronicle(basePath2);
                    tsc2.useUnsafe(USE_UNSAFE);
                    tsc2.clear();

                    Excerpt excerpt = tsc.createExcerpt();
                    Excerpt excerpt2 = tsc2.createExcerpt();

                    for (int i = 0; i < RUNS; i++) {
                        do {
                            /* try again */
                        } while (!excerpt.index(i));

                        long time = excerpt.readLong();
                        excerpt.finish();

                        excerpt2.startExcerpt(8);
                        excerpt2.writeLong(time);
                        excerpt2.finish();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        Excerpt excerpt = tsc.createExcerpt();
        Excerpt excerpt2 = tsc2.createExcerpt();

        Histogram hist = new Histogram(100000, 1);
        long totalTime = 0, longDelays = 0;
        for (int i = 0; i < RUNS; i++) {
            excerpt.startExcerpt(8);
            excerpt.writeLong(nanoTime());
            excerpt.finish();

            while (!excerpt2.index(i)) {
                /* try again */
            }

            long time1 = nanoTime();
            long time0 = excerpt2.readLong();
            excerpt2.finish();
            if (i >= WARMUP) {
                final long latency = time1 - time0;
                if (latency < 0 || latency > 100000) {
                    longDelays++;
                    System.out.println(latency);
View Full Code Here

        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

        deleteOnExit(basePath);

        IntIndexedChronicle tsc = new IntIndexedChronicle(basePath);
        tsc.useUnsafe(USE_UNSAFE);

        Excerpt excerpt = tsc.createExcerpt();
        double d = 0.001, factor = 1 + 10.0 / count;
        long timeInMS = System.currentTimeMillis() % 86400000;
        for (int i = 0; i < count; i++) {
            d *= factor;
            excerpt.startExcerpt(128);
            excerpt.appendTime(timeInMS).append(" [ ");
            excerpt.append(Thread.currentThread().getName()).append(" ] FINE ");
            excerpt.append("result= ").append(d, 6).append('\n');
            excerpt.finish();
        }
        tsc.close();
        return System.nanoTime() - start;
    }
View Full Code Here

                    tsc.useUnsafe(USE_UNSAFE);
                    final IndexedChronicle tsc2 = new IndexedChronicle(basePath2);
                    tsc2.useUnsafe(USE_UNSAFE);
                    tsc2.clear();

                    Excerpt excerpt = tsc.createExcerpt();
                    Excerpt excerpt2 = tsc2.createExcerpt();
                    for (int i = 0; i < RUNS; i++) {
                        do {
                            busyWait();
                        } while (!excerpt.index(i));

                        long time = excerpt.readLong();
                        excerpt.finish();

                        excerpt2.startExcerpt(8);
                        excerpt2.writeLong(time);
                        excerpt2.finish();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    al2.release();
                }
            }
        });
        t.start();

        al.bind();
        Excerpt excerpt = tsc.createExcerpt();
        Excerpt excerpt2 = tsc2.createExcerpt();

        Histogram hist = new Histogram(100000, 1);
        long totalTime = 0, longDelays = 0;
        for (int i = 0; i < RUNS; i++) {
            excerpt.startExcerpt(8);
            excerpt.writeLong(nanoTime());
            excerpt.finish();

            do {
                busyWait();
            } while (!excerpt2.index(i));

            long time1 = nanoTime();
            long time0 = excerpt2.readLong();
            excerpt2.finish();
            if (i >= WARMUP) {
                final long latency = time1 - time0;
                if (latency < 0 || latency > 100000) {
                    longDelays++;
                    System.out.println(latency);
View Full Code Here

        deleteOnExit(basePath);

        IndexedChronicle tsc = new IndexedChronicle(basePath);
        tsc.useUnsafe(USE_UNSAFE);
        tsc.clear();
        Excerpt excerpt = tsc.createExcerpt();

        StringBuilder sb = new StringBuilder();
        for (int i = Character.MIN_CODE_POINT; i <= Character.MAX_CODE_POINT; i += 16) {
            sb.setLength(0);
            for (int j = i; j < i + 16; j++) {
                if (Character.isValidCodePoint(j))
                    sb.appendCodePoint(j);
            }
            excerpt.startExcerpt(2 + sb.length() * 3);
            excerpt.writeUTF(sb);
            excerpt.finish();
        }
        excerpt.startExcerpt(2 + 1);
        excerpt.writeUTF(null);
        excerpt.finish();

        for (int i = Character.MIN_CODE_POINT, n = 0; i <= Character.MAX_CODE_POINT; i += 16, n++) {
            sb.setLength(0);
            for (int j = i; j < i + 16; j++) {
                if (Character.isValidCodePoint(j))
                    sb.appendCodePoint(j);
            }
            excerpt.index(n);
            String text = excerpt.readUTF();
            excerpt.finish();
            assertEquals("i: " + i, sb.toString(), text);
        }
        assertTrue(excerpt.nextIndex());
        String text = excerpt.readUTF();
        excerpt.finish();
        assertEquals(null, text);
    }
View Full Code Here

TOP

Related Classes of com.higherfrequencytrading.chronicle.Excerpt

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.