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