提交 04feaa24 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved performance, bugfix

上级 e67b6759
...@@ -299,8 +299,9 @@ public class MVStore { ...@@ -299,8 +299,9 @@ public class MVStore {
segmentCount, stackMoveDistance); segmentCount, stackMoveDistance);
} }
o = config.get("autoCommitBufferSize"); o = config.get("autoCommitBufferSize");
mb = o == null ? 4 : (Integer) o; int kb = o == null ? 512 : (Integer) o;
int autoCommitBufferSize = mb * 1024 * 1024; // 19 KB memory is about 1 KB storage
int autoCommitBufferSize = kb * 1024 * 19;
int div = pageSplitSize; int div = pageSplitSize;
autoCommitPageCount = autoCommitBufferSize / (div == 0 ? 1 : div); autoCommitPageCount = autoCommitBufferSize / (div == 0 ? 1 : div);
char[] encryptionKey = (char[]) config.get("encryptionKey"); char[] encryptionKey = (char[]) config.get("encryptionKey");
...@@ -902,7 +903,9 @@ public class MVStore { ...@@ -902,7 +903,9 @@ public class MVStore {
fileStore.free(x.start, len); fileStore.free(x.start, len);
} }
long end = getEndPosition(); // the length of the file that is still in use
// (not necessarily the end of the file)
long end = getFileLengthInUse();
long filePos; long filePos;
if (reuseSpace) { if (reuseSpace) {
filePos = fileStore.allocate(length); filePos = fileStore.allocate(length);
...@@ -910,7 +913,8 @@ public class MVStore { ...@@ -910,7 +913,8 @@ public class MVStore {
filePos = end; filePos = end;
fileStore.markUsed(end, length); fileStore.markUsed(end, length);
} }
boolean storeAtEndOfFile = filePos + length >= end; // end is not necessarily the end of the file
boolean storeAtEndOfFile = filePos + length >= fileStore.size();
c.start = filePos; c.start = filePos;
c.length = chunkLength; c.length = chunkLength;
...@@ -1078,7 +1082,7 @@ public class MVStore { ...@@ -1078,7 +1082,7 @@ public class MVStore {
* @param minPercent the minimum percentage to save * @param minPercent the minimum percentage to save
*/ */
private void shrinkFileIfPossible(int minPercent) { private void shrinkFileIfPossible(int minPercent) {
long end = getEndPosition(); long end = getFileLengthInUse();
long fileSize = fileStore.size(); long fileSize = fileStore.size();
if (end >= fileSize) { if (end >= fileSize) {
return; return;
...@@ -1098,7 +1102,7 @@ public class MVStore { ...@@ -1098,7 +1102,7 @@ public class MVStore {
* *
* @return the position * @return the position
*/ */
private long getEndPosition() { private long getFileLengthInUse() {
long size = 2 * BLOCK_SIZE; long size = 2 * BLOCK_SIZE;
for (Chunk c : chunks.values()) { for (Chunk c : chunks.values()) {
long x = c.start + c.length; long x = c.start + c.length;
...@@ -1184,7 +1188,7 @@ public class MVStore { ...@@ -1184,7 +1188,7 @@ public class MVStore {
buff.limit(length); buff.limit(length);
ByteBuffer buff2 = fileStore.readFully(c.start, length); ByteBuffer buff2 = fileStore.readFully(c.start, length);
buff.put(buff2); buff.put(buff2);
long end = getEndPosition(); long end = getFileLengthInUse();
fileStore.markUsed(end, length); fileStore.markUsed(end, length);
fileStore.free(c.start, length); fileStore.free(c.start, length);
c.start = end; c.start = end;
...@@ -2069,20 +2073,20 @@ public class MVStore { ...@@ -2069,20 +2073,20 @@ public class MVStore {
} }
/** /**
* Set the size of the write buffer, in MB (for file-based stores). * Set the size of the write buffer, in KB (for file-based stores).
* Unless auto-commit is disabled, changes are automatically saved if * Unless auto-commit is disabled, changes are automatically saved if
* there are more than this amount of changes. * there are more than this amount of changes.
* <p> * <p>
* The default is 4 MB. * The default is 512 KB.
* <p> * <p>
* When the value is set to 0 or lower, data is not automatically * When the value is set to 0 or lower, data is not automatically
* stored. * stored.
* *
* @param mb the write buffer size, in megabytes * @param kb the write buffer size, in kilobytes
* @return this * @return this
*/ */
public Builder autoCommitBufferSize(int mb) { public Builder autoCommitBufferSize(int kb) {
return set("autoCommitBufferSize", mb); return set("autoCommitBufferSize", kb);
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论