Search in sources :

Example 26 with LoopInterruptedCheck

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

the class HsqldbPerformanceTest method testHsqldbPerformance.

@Test
public void testHsqldbPerformance() throws Exception {
    final File directory = new File(ContextProperties.getCacheDirectory(), HsqldbPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdirParent(directory);
    final Instant writesStart = new Instant();
    int i = 0;
    Class.forName("org.hsqldb.jdbc.JDBCDriver");
    final Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:" + directory.getAbsolutePath(), "SA", "");
    final Statement create = conn.createStatement();
    create.execute("DROP TABLE abc IF EXISTS");
    create.execute("CREATE TABLE abc (key BIGINT, value BIGINT, PRIMARY KEY(key))");
    create.execute("CREATE UNIQUE INDEX idx_abc on abc (key)");
    create.close();
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Statement tx = conn.createStatement();
    tx.execute("START TRANSACTION");
    final PreparedStatement insert = conn.prepareStatement("INSERT INTO abc VALUES (?,?)");
    boolean batch = false;
    for (final FDate date : newValues()) {
        final long value = date.longValue(FTimeUnit.MILLISECONDS);
        insert.setLong(1, value);
        insert.setLong(2, value);
        insert.addBatch();
        i++;
        batch = true;
        if (i % FLUSH_INTERVAL == 0) {
            insert.executeBatch();
            batch = false;
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    if (batch) {
        insert.executeBatch();
    }
    insert.close();
    tx.execute("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 27 with LoopInterruptedCheck

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

the class SqlitePerformanceTest method testSQLitePerformance.

@Test
public void testSQLitePerformance() throws Exception {
    final File directory = new File(ContextProperties.getCacheDirectory(), SqlitePerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdirParent(directory);
    final Instant writesStart = new Instant();
    int i = 0;
    Class.forName("org.sqlite.JDBC");
    final Connection conn = DriverManager.getConnection("jdbc:sqlite:" + directory.getAbsolutePath());
    final Statement create = conn.createStatement();
    create.execute("DROP TABLE IF EXISTS abc");
    create.execute("CREATE TABLE abc (key LONG, value LONG, PRIMARY KEY(key))");
    create.execute("CREATE UNIQUE INDEX idx_abc on abc (key)");
    create.close();
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Statement tx = conn.createStatement();
    tx.execute("BEGIN TRANSACTION");
    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();
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    insert.executeBatch();
    insert.close();
    tx.execute("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 28 with LoopInterruptedCheck

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

the class TreeMapDBPerformanceTest method readGetLatest.

private void readGetLatest(final APersistentNavigableMap<FDate, FDate> table) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final List<FDate> values = Lists.toList(newValues());
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        for (int i = 0; i < values.size(); i++) {
            try {
                final Entry<FDate, FDate> entry = table.floorEntry(values.get(i));
                final FDate value = entry.getValue();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        if (loopCheck.check()) {
            printProgress("GetLatests", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("GetLatestsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Example 29 with LoopInterruptedCheck

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

the class TreeMapDBPerformanceTest method readIterator.

private void readIterator(final APersistentNavigableMap<FDate, FDate> table) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        final Iterator<FDate> range = table.values().iterator();
        int count = 0;
        while (true) {
            try {
                final FDate value = range.next();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Example 30 with LoopInterruptedCheck

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

the class QuestDBPerformanceTest method testQuestDbPerformance.

@Test
public void testQuestDbPerformance() throws InterruptedException, SqlException, IOException {
    final File directory = new File(ContextProperties.getCacheDirectory(), QuestDBPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final CairoConfiguration configuration = new DefaultCairoConfiguration(directory.getAbsolutePath());
    final Instant writesStart = new Instant();
    int i = 0;
    final CairoEngine engine = new CairoEngine(configuration);
    final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        compiler.compile("create table abc (value long, key timestamp) timestamp(key)", ctx);
        try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "insert")) {
            for (final FDate date : newValues()) {
                final TableWriter.Row row = writer.newRow(date.millisValue());
                row.putLong(0, date.millisValue());
                row.append();
                i++;
                if (i % FLUSH_INTERVAL == 0) {
                    if (loopCheck.check()) {
                        printProgress("Writes", writesStart, i, VALUES);
                    }
                    writer.commit();
                }
            }
            writer.commit();
        }
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
    }
    readIterator(engine);
    readGet(engine);
    readGetLatest(engine);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        compiler.compile("dtop table 'abc';", ctx);
    }
    engine.close();
    Files.deleteNative(directory);
}
Also used : SqlCompiler(io.questdb.griffin.SqlCompiler) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) TableWriter(io.questdb.cairo.TableWriter) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) File(java.io.File) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) 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