diff --git a/.vscode/launch.json b/.vscode/launch.json index 4f5b55cf..f62fc54e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "name": "Launch Current File", "request": "launch", "mainClass": "${file}", - "vmArgs": "-Xmx6G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=5G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\"", + "vmArgs": "-Xmx8G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=7G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\"", "preLaunchTask": "Install Native Lib" }, { @@ -14,7 +14,7 @@ "name": "Launch Main", "request": "launch", "mainClass": "electrosphere.engine.Main", - "vmArgs": "-Xmx6G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=5G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\"", + "vmArgs": "-Xmx8G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=7G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\"", "projectName": "Renderer", "preLaunchTask": "Install Native Lib" }, @@ -23,7 +23,7 @@ "name": "Launch Main (Debug Memory)", "request": "launch", "mainClass": "electrosphere.engine.Main", - "vmArgs": "-Xmx6G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=5G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\" -javaagent:./lwjglx-debug-1.0.0.jar=t;o=trace.log", + "vmArgs": "-Xmx8G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=7G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\" -javaagent:./lwjglx-debug-1.0.0.jar=t;o=trace.log", "projectName": "Renderer", "preLaunchTask": "Install Native Lib" }, @@ -35,7 +35,7 @@ "env": { "ALSOFT_LOGLEVEL": 4 }, - "vmArgs": "-Xmx6G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=5G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\"", + "vmArgs": "-Xmx8G -Xms1024m -Djava.library.path=./shared-folder -XX:+UseZGC -XX:SoftMaxHeapSize=7G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\"./tmp/heap.hprof\"", "projectName": "Renderer" }, { diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 3d34228f..5eebc405 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1994,6 +1994,8 @@ Performance improvements - Client leverages block chunk short pool - Client doesn't load physics on entities by default - Block chunk disk map writes files without allocating a buffer + - Increase memory limit 6GB->8GB + - Server block chunk disk map writes directly to output stream instead of inbetween buffer Increase human move speed LOD components re-attach physics VectorPool->JomlPool diff --git a/src/main/java/electrosphere/server/physics/block/diskmap/ServerBlockChunkDiskMap.java b/src/main/java/electrosphere/server/physics/block/diskmap/ServerBlockChunkDiskMap.java index c9b0e4fe..18e39bfd 100644 --- a/src/main/java/electrosphere/server/physics/block/diskmap/ServerBlockChunkDiskMap.java +++ b/src/main/java/electrosphere/server/physics/block/diskmap/ServerBlockChunkDiskMap.java @@ -3,6 +3,7 @@ package electrosphere.server.physics.block.diskmap; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ShortBuffer; import java.util.HashMap; @@ -216,11 +217,10 @@ public class ServerBlockChunkDiskMap { fileName = BLOCK_DATA_DIR + chunkKey + "b.dat"; } //compress - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DeflaterOutputStream deflaterOutStream = new DeflaterOutputStream(out); - DataOutputStream dataOut = new DataOutputStream(deflaterOutStream); try { - + OutputStream out = FileUtils.getBinarySavePathOutputStream(Globals.serverState.currentSave.getName(), fileName); + DeflaterOutputStream deflaterOutStream = new DeflaterOutputStream(out); + DataOutputStream dataOut = new DataOutputStream(deflaterOutStream); //generate binary for the file short[] type = chunkData.getType(); @@ -244,11 +244,10 @@ public class ServerBlockChunkDiskMap { dataOut.writeShort(chunkData.getHomogenousValue()); } - + //flush and close dataOut.flush(); dataOut.close(); - //write to disk - FileUtils.saveBinaryToSavePath(Globals.serverState.currentSave.getName(), fileName, out.toByteArray()); + //save to the map of filenames worldPosFileMap.put(chunkKey,fileName); } catch (IOException e) { diff --git a/src/main/java/electrosphere/util/FileUtils.java b/src/main/java/electrosphere/util/FileUtils.java index d7992607..1d568374 100644 --- a/src/main/java/electrosphere/util/FileUtils.java +++ b/src/main/java/electrosphere/util/FileUtils.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectOutputStream; +import java.io.OutputStream; import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; @@ -401,6 +402,19 @@ public class FileUtils { } } + /** + * Opens an output straem to a binary file in a save directory + * @param saveName The save name + * @param pathName The path name to the file + * @return The output stream + */ + public static OutputStream getBinarySavePathOutputStream(String saveName, String pathName) throws IOException { + String sanitizedFilePath = FileUtils.sanitizeFilePath(pathName); + File file = FileUtils.getSaveFile(saveName,sanitizedFilePath); + Files.createDirectories(file.getParentFile().toPath()); + return Files.newOutputStream(file.toPath()); + } + /** * Checks if a given file exists in a given save * @param saveName the name of the save