Skip to content

Commit 2df8bdc

Browse files
fix: prevent kanzi from stalling w/ TPAQX and too many threads on limited memory
1 parent 7efcb19 commit 2df8bdc

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

h2/src/main/org/h2/tools/CompressTool.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,23 @@ public static OutputStream createKanziOutputStream(OutputStream baseOutputStream
9393
// Create configuration map with proper Kanzi parameters
9494
java.util.Map<String, Object> configMap = new java.util.HashMap<>();
9595

96-
// Best compression settings (brute tested on a 1.7 GB database)
96+
// Best compression settings (brute tested on a 1.7 GB database, 4.7GB SQL file)
9797
// 88658331 kanzi -x64 -b 256m -t RLT+PACK+LZP -e TPAQX
9898
// 88654035 kanzi -x64 -b 256m -t RLT+PACK+LZP+RLT -e TPAQX
9999
// 85411430 kanzi -x64 -b 256m -t TEXT+RLT+LZP+PACK -e TPAQX
100100
// 85397152 kanzi -x64 -b 256m -t TEXT+RLT+LZP+PACK+RLT -e TPAQX
101101

102102
configMap.put("transform", "TEXT+RLT+LZP+PACK+RLT");// Good for SQL dump
103-
configMap.put("entropy", "TPAQ"); // Text and structured data
104-
configMap.put("blockSize", 64 * 1024 * 1024); // 64MB blocks
105-
configMap.put("level", 9); // Max. compression level
103+
configMap.put("entropy", "TPAQX"); // Text and structured data
104+
configMap.put("blockSize", 32 * 1024 * 1024); // 32MB blocks
106105
configMap.put("checksum", 64); // Enable checksums
107106

108107
configMap.put("pool", executor); // Multi-threaded
109-
configMap.put("jobs", Runtime.getRuntime().availableProcessors());
108+
if (Runtime.getRuntime().freeMemory() < 8L * 1024 * 1024 * 1024) {
109+
configMap.put("jobs", 4);
110+
} else {
111+
configMap.put("jobs", Runtime.getRuntime().availableProcessors() / 2);
112+
}
110113

111114
Constructor<?> constructor = clazz.getConstructor(
112115
OutputStream.class,

0 commit comments

Comments
 (0)