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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations