提交 f5c6cbe5 authored 作者: Thomas Mueller's avatar Thomas Mueller

SHUTDOWN COMPACT and compacting in general is faster.

上级 b9cafa06
......@@ -18,9 +18,15 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The built-in profiling tool now uses a default stack depth of 32 elements and a default interval of 10 ms.
</li><li>Database files now grow 2 MB at a time instead of 256 KB. This improves performance, specially
when loading a new database.
<ul><li>Storing lobs in the database has been changed. It is now faster.
Unfortunately, the change is not backward compatible; if you have used h2.lobInDatabase before
you will need to re-build the database.
</li><li>SHUTDOWN COMPACT and compacting in general is faster.
</li><li>H2 Console: requesting the status did not always show the window on top of others.
</li><li>H2 Console: on some system, the browser windows got opened when requesting a new one.
</li><li>The built-in profiling tool now uses a default stack depth of 32 elements and a default interval of 10 ms.
</li><li>Database files now grows in 1 MB blocks (and at least 2%) at a time,
instead of always 256 KB. This speeds up loading a new database.
</li><li>H2 Console: new built-in command @sleep to help profile another session.
</li><li>For improved performance, LOG=0 and LOG=1 are again supported.
LOG=0 means the transaction log is disabled completely (fastest; for loading a database).
......
......@@ -121,13 +121,15 @@ public class PageStore implements CacheWriter {
private static final int PAGE_ID_FREE_LIST_ROOT = 3;
private static final int PAGE_ID_META_ROOT = 4;
private static final int MIN_PAGE_COUNT = 6;
private static final int INCREMENT_KB = 2048;
private static final int INCREMENT_KB = 1024;
private static final int INCREMENT_PERCENT_MIN = 2;
private static final int READ_VERSION = 3;
private static final int WRITE_VERSION = 3;
private static final int META_TYPE_DATA_INDEX = 0;
private static final int META_TYPE_BTREE_INDEX = 1;
private static final int META_TABLE_ID = -1;
private static final SearchRow[] EMPTY_SEARCH_ROW = { };
private static final int COMPACT_BLOCK_SIZE = 1536;
private Database database;
private final Trace trace;
private String fileName;
......@@ -291,7 +293,7 @@ public class PageStore implements CacheWriter {
log.openForWriting(logFirstTrunkPage, false);
isNew = true;
recoveryRunning = false;
increaseFileSize(INCREMENT_KB * 1024 / pageSize);
increaseFileSize();
}
private void openExisting() {
......@@ -443,16 +445,26 @@ public class PageStore implements CacheWriter {
maxCompactTime = Integer.MAX_VALUE;
maxMove = Integer.MAX_VALUE;
}
for (int x = lastUsed, j = 0; x > MIN_PAGE_COUNT && j < maxMove; x--, j++) {
int blockSize = COMPACT_BLOCK_SIZE;
for (int x = lastUsed, j = 0; x > MIN_PAGE_COUNT && j < maxMove; x -= blockSize) {
for (int y = x - blockSize + 1; y <= x; y++) {
if (y > MIN_PAGE_COUNT) {
getPage(y);
}
}
for (int y = x - blockSize + 1; y <= x; y++) {
if (y > MIN_PAGE_COUNT) {
synchronized (database) {
compact(x);
compact(y);
}
j++;
}
}
long now = System.currentTimeMillis();
if (now > start + maxCompactTime) {
break;
}
}
// TODO can most likely be simplified
checkpoint();
log.checkpoint();
......@@ -878,7 +890,7 @@ public class PageStore implements CacheWriter {
synchronized (database) {
int p = PAGE_ID_FREE_LIST_ROOT + i * freeListPagesPerList;
while (p >= pageCount) {
increaseFileSize(INCREMENT_KB * 1024 / pageSize);
increaseFileSize();
}
if (p < pageCount) {
list = (PageFreeList) getPage(p);
......@@ -954,8 +966,8 @@ public class PageStore implements CacheWriter {
break;
}
}
if (page >= pageCount) {
increaseFileSize(INCREMENT_KB * 1024 / pageSize);
while (page >= pageCount) {
increaseFileSize();
}
if (trace.isDebugEnabled()) {
// trace.debug("allocatePage " + pos);
......@@ -964,6 +976,15 @@ public class PageStore implements CacheWriter {
}
}
private void increaseFileSize() {
int increment = INCREMENT_KB * 1024 / pageSize;
int percent = pageCount * INCREMENT_PERCENT_MIN / 100;
if (increment < percent) {
increment = (1 + (percent / increment)) * increment;
}
increaseFileSize(increment);
}
private void increaseFileSize(int increment) {
for (int i = pageCount; i < pageCount + increment; i++) {
freed.set(i);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论