use of org.h2.util.Task in project h2database by h2database.
the class TestMultiThread method testConcurrentAnalyze.
private void testConcurrentAnalyze() throws Exception {
if (config.mvcc) {
return;
}
deleteDb(getTestName());
final String url = getURL("concurrentAnalyze;MULTI_THREADED=1", true);
try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement();
stat.execute("create table test(id bigint primary key) " + "as select x from system_range(1, 1000)");
Task t = new Task() {
@Override
public void call() throws SQLException {
try (Connection conn2 = getConnection(url)) {
for (int i = 0; i < 1000; i++) {
conn2.createStatement().execute("analyze");
}
}
}
};
t.execute();
Thread.yield();
for (int i = 0; i < 1000; i++) {
conn.createStatement().execute("analyze");
}
t.get();
stat.execute("drop table test");
}
}
use of org.h2.util.Task in project h2database by h2database.
the class TestMultiThread method testConcurrentSchemaChange.
private void testConcurrentSchemaChange() throws Exception {
String db = getTestName();
deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1;LOCK_TIMEOUT=10000", true);
try (Connection conn = getConnection(url)) {
Task[] tasks = new Task[2];
for (int i = 0; i < tasks.length; i++) {
final int x = i;
Task t = new Task() {
@Override
public void call() throws Exception {
try (Connection c2 = getConnection(url)) {
Statement stat = c2.createStatement();
for (int i = 0; !stop; i++) {
stat.execute("create table test" + x + "_" + i);
c2.getMetaData().getTables(null, null, null, null);
stat.execute("drop table test" + x + "_" + i);
}
}
}
};
tasks[i] = t;
t.execute();
}
Thread.sleep(1000);
for (Task t : tasks) {
t.get();
}
}
}
use of org.h2.util.Task in project h2database by h2database.
the class TestMultiThreadedKernel method testCache.
private void testCache() throws Exception {
ArrayList<Task> list = New.arrayList();
int size = 3;
final int count = 100;
final Connection[] connections = new Connection[count];
String url = getURL("multiThreadedKernel;" + "MULTI_THREADED=TRUE;CACHE_SIZE=1", true);
for (int i = 0; i < size; i++) {
final Connection conn = DriverManager.getConnection(url, getUser(), getPassword());
connections[i] = conn;
if (i == 0) {
Statement stat = conn.createStatement();
stat.execute("drop table test if exists");
stat.execute("create table test(id int primary key, name varchar) " + "as select x, space(3000) from system_range(1, " + count + ")");
}
final Random random = new Random(i);
Task t = new Task() {
@Override
public void call() throws SQLException {
PreparedStatement prep = conn.prepareStatement("select * from test where id = ?");
while (!stop) {
prep.setInt(1, random.nextInt(count));
prep.execute();
}
}
};
t.execute();
list.add(t);
}
Thread.sleep(1000);
for (Task t : list) {
t.get();
}
for (int i = 0; i < size; i++) {
connections[i].close();
}
}
use of org.h2.util.Task in project h2database by h2database.
the class TestMultiThreadedKernel method testConcurrentRead.
private void testConcurrentRead() throws Exception {
ArrayList<Task> list = New.arrayList();
int size = 2;
final int count = 1000;
final Connection[] connections = new Connection[count];
String url = getURL("multiThreadedKernel;" + "MULTI_THREADED=TRUE;CACHE_SIZE=16", true);
for (int i = 0; i < size; i++) {
final Connection conn = DriverManager.getConnection(url, getUser(), getPassword());
connections[i] = conn;
if (i == 0) {
Statement stat = conn.createStatement();
stat.execute("drop table test if exists");
stat.execute("create table test(id int primary key, name varchar) " + "as select x, x || space(10) from system_range(1, " + count + ")");
}
final Random random = new Random(i);
Task t = new Task() {
@Override
public void call() throws Exception {
PreparedStatement prep = conn.prepareStatement("select * from test where id = ?");
while (!stop) {
prep.setInt(1, random.nextInt(count));
prep.execute();
}
}
};
t.execute();
list.add(t);
}
Thread.sleep(1000);
for (Task t : list) {
t.get();
}
for (int i = 0; i < size; i++) {
connections[i].close();
}
}
use of org.h2.util.Task in project h2database by h2database.
the class TestMVStoreCachePerformance method testCache.
private void testCache(int threadCount, String fileNamePrefix) {
String fileName = getBaseDir() + "/" + getTestName();
fileName = fileNamePrefix + fileName;
FileUtils.delete(fileName);
MVStore store = new MVStore.Builder().fileName(fileName).open();
final MVMap<Integer, byte[]> map = store.openMap("test");
final AtomicInteger counter = new AtomicInteger();
byte[] data = new byte[8 * 1024];
final int count = 10000;
for (int i = 0; i < count; i++) {
map.put(i, data);
store.commit();
if (i % 1000 == 0) {
// System.out.println("add " + i);
}
}
Task[] tasks = new Task[threadCount];
for (int i = 0; i < threadCount; i++) {
tasks[i] = new Task() {
@Override
public void call() throws Exception {
Random r = new Random();
do {
int id = r.nextInt(count);
map.get(id);
counter.incrementAndGet();
} while (!stop);
}
};
tasks[i].execute();
}
for (int i = 0; i < 4; i++) {
// Profiler prof = new Profiler().startCollecting();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
// System.out.println(prof.getTop(5));
// System.out.println(" " + counter.get() / (i + 1) + " op/s");
}
// long time = System.nanoTime();
for (Task t : tasks) {
t.get();
}
store.close();
System.out.println(counter.get() / 10000 + " ops/ms; " + threadCount + " thread(s); " + fileNamePrefix);
}
Aggregations