Search in sources :

Example 1 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class DerbyPerformanceTest method readIterator.

private void readIterator(final Connection conn) throws Exception {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    final Statement select = conn.createStatement();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (ResultSet results = select.executeQuery("SELECT v FROM abc ORDER BY k ASC")) {
            while (results.next()) {
                final FDate value = new FDate(results.getLong(1));
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Instant(de.invesdwin.util.time.Instant) ResultSet(java.sql.ResultSet) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 2 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class DerbyPerformanceTest method readGet.

private void readGet(final Connection conn) throws Exception {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final List<FDate> values = Lists.toList(newValues());
    final Instant readsStart = new Instant();
    for (int reads = 0; reads < READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (PreparedStatement select = conn.prepareStatement("SELECT v FROM abc where k = ?  fetch first 1 rows only")) {
            for (int i = 0; i < values.size(); i++) {
                select.setLong(1, values.get(i).millisValue());
                try (ResultSet results = select.executeQuery()) {
                    Assertions.checkTrue(results.next());
                    final FDate value = new FDate(results.getLong(1));
                    if (prevValue != null) {
                        Assertions.checkTrue(prevValue.isBefore(value));
                    }
                    prevValue = value;
                    count++;
                    if (loopCheck.check()) {
                        printProgress("Gets", readsStart, VALUES * reads + count, VALUES * READS);
                    }
                }
            }
        }
        Assertions.checkEquals(count, VALUES);
    }
    printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 3 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class DerbyPerformanceTest method testDerbyPerformance.

@Test
public void testDerbyPerformance() throws Exception {
    final File directory = new File(ContextProperties.getCacheDirectory(), DerbyPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdirParent(directory);
    final Instant writesStart = new Instant();
    int i = 0;
    Class.forName("org.apache.derby.iapi.jdbc.AutoloadedDriver");
    final Connection conn = DriverManager.getConnection("jdbc:derby:" + directory.getAbsolutePath() + ";create=true");
    // autocommit is very slow and overrides transactions
    conn.setAutoCommit(false);
    final Statement create = conn.createStatement();
    create.execute("CREATE TABLE abc (k BIGINT, v BIGINT, PRIMARY KEY(k))");
    create.execute("CREATE UNIQUE INDEX idx_abc on abc (k desc)");
    create.close();
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Statement tx = conn.createStatement();
    final PreparedStatement insert = conn.prepareStatement("INSERT INTO abc VALUES (?,?)");
    for (final FDate date : newValues()) {
        final long value = date.longValue(FTimeUnit.MILLISECONDS);
        insert.setLong(1, value);
        insert.setLong(2, value);
        insert.addBatch();
        i++;
        if (i % FLUSH_INTERVAL == 0) {
            insert.executeBatch();
            conn.commit();
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    insert.executeBatch();
    insert.close();
    conn.commit();
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    tx.close();
    readIterator(conn);
    readGet(conn);
    readGetLatest(conn);
    final Statement drop = conn.createStatement();
    drop.execute("drop table abc");
    drop.close();
    Files.deleteNative(directory);
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Instant(de.invesdwin.util.time.Instant) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) File(java.io.File) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Example 4 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class LsmTreePerformanceTest method testLsmTreePerformance.

@Test
public void testLsmTreePerformance() throws IOException, InterruptedException {
    final File directory = new File(ContextProperties.getCacheDirectory(), LsmTreePerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final File file = new File(directory, "testLsmTreePerformance");
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant writesStart = new Instant();
    Store<FDate, FDate> store = newStore(file);
    int i = 0;
    for (final FDate date : newValues()) {
        store.put(date, date);
        i++;
        if (i % FLUSH_INTERVAL == 0) {
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    // store.waitForCompactions();
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    store.close();
    store = newStore(file);
    readIterator(store);
    readGet(store);
    readGetLatest(store);
    store.close();
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) File(java.io.File) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Example 5 with LoopInterruptedCheck

use of de.invesdwin.util.concurrent.loop.LoopInterruptedCheck in project invesdwin-context-persistence by subes.

the class RecordLogDirectoryPerformanceTest method testRecordLogDirectoryPerformance.

@Test
public void testRecordLogDirectoryPerformance() throws IOException, InterruptedException {
    final File directory = new File(ContextProperties.getCacheDirectory(), RecordLogDirectoryPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final File file = new File(directory, "testRecordLogDirectoryPerformance");
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant writesStart = new Instant();
    try (RecordLogDirectory.Writer<TimedDecimal> writer = RecordLogDirectory.Writer.create(file, IndeedSerializer.valueOf(TimedDecimalSerde.GET), new SnappyCodec(), Integer.MAX_VALUE)) {
        int i = 0;
        for (final FDate date : newValues()) {
            writer.append(new TimedDecimal(date, date.millisValue()));
            i++;
            if (i % FLUSH_INTERVAL == 0) {
                if (loopCheck.check()) {
                    printProgress("Writes", writesStart, i, VALUES);
                }
            // writer.roll();
            }
        }
        writer.roll();
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
    }
    readIterator(file);
}
Also used : Instant(de.invesdwin.util.time.Instant) RecordLogDirectory(com.indeed.lsmtree.recordlog.RecordLogDirectory) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) File(java.io.File) RecordFile(com.indeed.lsmtree.recordlog.RecordFile) TimedDecimal(de.invesdwin.util.math.decimal.TimedDecimal) SnappyCodec(com.indeed.util.compress.SnappyCodec) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Aggregations

LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)65 Instant (de.invesdwin.util.time.Instant)65 FDate (de.invesdwin.util.time.date.FDate)63 NoSuchElementException (java.util.NoSuchElementException)22 Test (org.junit.jupiter.api.Test)19 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)15 File (java.io.File)12 Statement (java.sql.Statement)12 RecordFile (com.indeed.lsmtree.recordlog.RecordFile)6 TimedDecimal (de.invesdwin.util.math.decimal.TimedDecimal)6 Connection (java.sql.Connection)5 APersistentMap (de.invesdwin.context.integration.persistentmap.APersistentMap)4 SqlCompiler (io.questdb.griffin.SqlCompiler)4 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)4 SnappyCodec (com.indeed.util.compress.SnappyCodec)3 RecordCursor (io.questdb.cairo.sql.RecordCursor)3 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 KeyValue (com.googlecode.cqengine.index.support.KeyValue)2 BasicRecordFile (com.indeed.lsmtree.recordlog.BasicRecordFile)2