Search in sources :

Example 56 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestMultiDimension method testPerformance3d.

private void testPerformance3d() throws SQLException {
    deleteDb("multiDimension");
    Connection conn;
    conn = getConnection("multiDimension");
    Statement stat = conn.createStatement();
    stat.execute("CREATE ALIAS MAP FOR \"" + getClass().getName() + ".interleave\"");
    stat.execute("CREATE TABLE TEST(X INT NOT NULL, " + "Y INT NOT NULL, Z INT NOT NULL, " + "XYZ BIGINT AS MAP(X, Y, Z), DATA VARCHAR)");
    stat.execute("CREATE INDEX IDX_X ON TEST(X, Y, Z)");
    stat.execute("CREATE INDEX IDX_XYZ ON TEST(XYZ)");
    PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(X, Y, Z, DATA) VALUES(?, ?, ?, ?)");
    // the MultiDimension tool is faster for 8000 (20^3) points
    // the more the bigger the difference
    int max = getSize(10, 20);
    long time = System.nanoTime();
    for (int x = 0; x < max; x++) {
        for (int y = 0; y < max; y++) {
            for (int z = 0; z < max; z++) {
                long t2 = System.nanoTime();
                if (t2 - time > TimeUnit.SECONDS.toNanos(1)) {
                    int percent = (int) (100.0 * ((double) x * max + y) / ((double) max * max));
                    trace(percent + "%");
                    time = t2;
                }
                prep.setInt(1, x);
                prep.setInt(2, y);
                prep.setInt(3, z);
                prep.setString(4, "Test data");
                prep.execute();
            }
        }
    }
    stat.execute("ANALYZE SAMPLE_SIZE 10000");
    PreparedStatement prepRegular = conn.prepareStatement("SELECT * FROM TEST WHERE X BETWEEN ? AND ? " + "AND Y BETWEEN ? AND ? AND Z BETWEEN ? AND ? ORDER BY X, Y, Z");
    MultiDimension multi = MultiDimension.getInstance();
    String sql = multi.generatePreparedQuery("TEST", "XYZ", new String[] { "X", "Y", "Z" });
    sql += " ORDER BY X, Y, Z";
    PreparedStatement prepMulti = conn.prepareStatement(sql);
    long timeMulti = 0, timeRegular = 0;
    int timeMax = getSize(500, 2000);
    Random rand = new Random(1);
    while (timeMulti < timeMax) {
        int size = rand.nextInt(max / 10);
        int minX = rand.nextInt(max - size);
        int minY = rand.nextInt(max - size);
        int minZ = rand.nextInt(max - size);
        int maxX = minX + size, maxY = minY + size, maxZ = minZ + size;
        time = System.nanoTime();
        ResultSet rs1 = multi.getResult(prepMulti, new int[] { minX, minY, minZ }, new int[] { maxX, maxY, maxZ });
        timeMulti += System.nanoTime() - time;
        time = System.nanoTime();
        prepRegular.setInt(1, minX);
        prepRegular.setInt(2, maxX);
        prepRegular.setInt(3, minY);
        prepRegular.setInt(4, maxY);
        prepRegular.setInt(5, minZ);
        prepRegular.setInt(6, maxZ);
        ResultSet rs2 = prepRegular.executeQuery();
        timeRegular += System.nanoTime() - time;
        while (rs1.next()) {
            assertTrue(rs2.next());
            assertEquals(rs1.getInt(1), rs2.getInt(1));
            assertEquals(rs1.getInt(2), rs2.getInt(2));
        }
        assertFalse(rs2.next());
    }
    conn.close();
    deleteDb("multiDimension");
    trace("3d: regular: " + TimeUnit.NANOSECONDS.toMillis(timeRegular) + " MultiDimension: " + TimeUnit.NANOSECONDS.toMillis(timeMulti));
}
Also used : Random(java.util.Random) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MultiDimension(org.h2.tools.MultiDimension)

Example 57 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestMVStoreBenchmark method getMemoryUsed.

private long[] getMemoryUsed(int count, int size) {
    long hash, tree, mv;
    ArrayList<Map<Integer, String>> mapList;
    long mem;
    mapList = New.arrayList();
    mem = getMemory();
    for (int i = 0; i < count; i++) {
        mapList.add(new HashMap<Integer, String>(size));
    }
    addEntries(mapList, size);
    hash = getMemory() - mem;
    mapList.size();
    mapList = New.arrayList();
    mem = getMemory();
    for (int i = 0; i < count; i++) {
        mapList.add(new TreeMap<Integer, String>());
    }
    addEntries(mapList, size);
    tree = getMemory() - mem;
    mapList.size();
    mapList = New.arrayList();
    mem = getMemory();
    MVStore store = MVStore.open(null);
    for (int i = 0; i < count; i++) {
        Map<Integer, String> map = store.openMap("t" + i);
        mapList.add(map);
    }
    addEntries(mapList, size);
    mv = getMemory() - mem;
    mapList.size();
    trace("hash: " + hash / 1024 / 1024 + " mb");
    trace("tree: " + tree / 1024 / 1024 + " mb");
    trace("mv: " + mv / 1024 / 1024 + " mb");
    return new long[] { hash, tree, mv };
}
Also used : MVStore(org.h2.mvstore.MVStore) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 58 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestDataSource method test.

// public static void main(String... args) throws SQLException {
// 
// // first, need to start on the command line:
// // rmiregistry 1099
// 
// // System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
// "com.sun.jndi.ldap.LdapCtxFactory");
// System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
// "com.sun.jndi.rmi.registry.RegistryContextFactory");
// System.setProperty(Context.PROVIDER_URL, "rmi://localhost:1099");
// 
// JdbcDataSource ds = new JdbcDataSource();
// ds.setURL("jdbc:h2:test");
// ds.setUser("test");
// ds.setPassword("");
// 
// Context ctx = new InitialContext();
// ctx.bind("jdbc/test", ds);
// 
// DataSource ds2 = (DataSource)ctx.lookup("jdbc/test");
// Connection conn = ds2.getConnection();
// conn.close();
// }
@Override
public void test() throws Exception {
    if (config.traceLevelFile > 0) {
        TraceSystem sys = JdbcDataSourceFactory.getTraceSystem();
        sys.setFileName(getBaseDir() + "/test/trace");
        sys.setLevelFile(3);
    }
    testDataSourceFactory();
    testDataSource();
    testUnwrap();
    testXAConnection();
    deleteDb("dataSource");
}
Also used : TraceSystem(org.h2.message.TraceSystem)

Example 59 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestCacheConcurrentLIRS method testConcurrent.

private void testConcurrent() {
    CacheLongKeyLIRS.Config cc = new CacheLongKeyLIRS.Config();
    cc.maxMemory = 100;
    final CacheLongKeyLIRS<Integer> test = new CacheLongKeyLIRS<>(cc);
    int threadCount = 8;
    final CountDownLatch wait = new CountDownLatch(1);
    final AtomicBoolean stopped = new AtomicBoolean();
    Task[] tasks = new Task[threadCount];
    final int[] getCounts = new int[threadCount];
    final int offset = 1000000;
    for (int i = 0; i < 100; i++) {
        test.put(offset + i, i);
    }
    final int[] keys = new int[1000];
    Random random = new Random(1);
    for (int i = 0; i < keys.length; i++) {
        int key;
        do {
            key = (int) Math.abs(random.nextGaussian() * 50);
        } while (key > 100);
        keys[i] = key;
    }
    for (int i = 0; i < threadCount; i++) {
        final int x = i;
        Task t = new Task() {

            @Override
            public void call() throws Exception {
                Random random = new Random(x);
                wait.await();
                int i = 0;
                for (; !stopped.get(); i++) {
                    int key = keys[random.nextInt(keys.length)];
                    test.get(offset + key);
                    if ((i & 127) == 0) {
                        test.put(offset + random.nextInt(100), random.nextInt());
                    }
                }
                getCounts[x] = i;
            }
        };
        t.execute("t" + i);
        tasks[i] = t;
    }
    wait.countDown();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    stopped.set(true);
    for (Task t : tasks) {
        t.get();
    }
    int totalCount = 0;
    for (int x : getCounts) {
        totalCount += x;
    }
    trace("requests: " + totalCount);
}
Also used : CacheLongKeyLIRS(org.h2.mvstore.cache.CacheLongKeyLIRS) Task(org.h2.util.Task) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random)

Example 60 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class ModelsTest method validateModel.

private void validateModel(DbInspector inspector, Object o) {
    List<ValidationRemark> remarks = inspector.validateModel(o, false);
    if (config.traceTest && remarks.size() > 0) {
        trace("Validation remarks for " + o.getClass().getName());
        for (ValidationRemark remark : remarks) {
            trace(remark.toString());
        }
        trace("");
    }
    for (ValidationRemark remark : remarks) {
        assertFalse(remark.toString(), remark.isError());
    }
}
Also used : ValidationRemark(org.h2.jaqu.ValidationRemark)

Aggregations

SQLException (java.sql.SQLException)16 DbException (org.h2.message.DbException)14 Connection (java.sql.Connection)11 ResultSet (java.sql.ResultSet)10 PreparedStatement (java.sql.PreparedStatement)9 Statement (java.sql.Statement)8 IOException (java.io.IOException)7 Savepoint (java.sql.Savepoint)7 Random (java.util.Random)7 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TraceSystem (org.h2.message.TraceSystem)5 Server (org.h2.tools.Server)5 ValueString (org.h2.value.ValueString)5 SQLClientInfoException (java.sql.SQLClientInfoException)4 SysProperties (org.h2.engine.SysProperties)4 JdbcConnection (org.h2.jdbc.JdbcConnection)4 SortedProperties (org.h2.util.SortedProperties)4 Value (org.h2.value.Value)4 Socket (java.net.Socket)3