diff options
| author | lotus <lotus@6c8d7289-2bf4-0310-a012-ef5d649a1542> | 2009-02-07 11:53:48 +0000 |
|---|---|---|
| committer | lotus <lotus@6c8d7289-2bf4-0310-a012-ef5d649a1542> | 2009-02-07 11:53:48 +0000 |
| commit | e8ae2599fdfce2c31dae2ee593a81d88416cef1b (patch) | |
| tree | 26b16669f17b03e9afccfae5de603e0f3b25ee59 | |
| parent | 49d95fb3d930bb273cdc2906b59121c96d977536 (diff) | |
* some refactoring/moves to consoleInterface
* added possibility to find maximum possible heap size
you can get it via getWin32MaxHeap.bat
this may cause high system load
moreover the found limit is no guarantee for stable startups since it depends on system configuration
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5583 6c8d7289-2bf4-0310-a012-ef5d649a1542
| -rw-r--r-- | build.xml | 6 | ||||
| -rw-r--r-- | getWin32MaxHeap.bat | 7 | ||||
| -rw-r--r-- | source/de/anomic/server/serverSystem.java | 42 | ||||
| -rwxr-xr-x | source/de/anomic/tools/consoleInterface.java | 49 | ||||
| -rw-r--r-- | source/de/anomic/tools/diskUsage.java | 39 |
5 files changed, 101 insertions, 42 deletions
@@ -404,7 +404,8 @@ <fileset dir="."> <include name="startYACY.bat"/> <include name="startYACY_debug.bat"/> - <include name="stopYACY.bat"/>
+ <include name="stopYACY.bat"/> + <include name="getWin32MaxHeap.bat"/>
<!-- <include name="startYACY_Win9x.bat"/> <include name="startYACY_noconsole_Win9x.bat"/> @@ -579,7 +580,8 @@ <fileset dir="."> <include name="startYACY.bat"/> <include name="startYACY_noconsole.bat"/> - <include name="stopYACY.bat"/>
+ <include name="stopYACY.bat"/> + <include name="getWin32MaxHeap.bat"/>
<!-- <include name="startYACY_Win9x.bat"/> <include name="startYACY_noconsole_Win9x.bat"/> diff --git a/getWin32MaxHeap.bat b/getWin32MaxHeap.bat new file mode 100644 index 000000000..841ab490a --- /dev/null +++ b/getWin32MaxHeap.bat @@ -0,0 +1,7 @@ +@echo off
+echo This can cause high system load.
+echo To abort press CTRL+C.
+echo ***
+pause
+java -cp classes de.anomic.server.serverSystem -m
+pause
\ No newline at end of file diff --git a/source/de/anomic/server/serverSystem.java b/source/de/anomic/server/serverSystem.java index 29dc7bafe..961868884 100644 --- a/source/de/anomic/server/serverSystem.java +++ b/source/de/anomic/server/serverSystem.java @@ -27,12 +27,15 @@ import java.io.IOException; import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.List;
import java.util.Properties;
import java.util.Vector;
import de.anomic.kelondro.util.Log;
import de.anomic.kelondro.util.FileUtils;
+import de.anomic.tools.consoleInterface;
public final class serverSystem {
@@ -109,10 +112,6 @@ public final class serverSystem { if (isWindows) maxPathLength = 255; else maxPathLength = 65535;
}
- /* public static boolean isWindows() {
- return systemOS == systemWindows;
- }*/
-
public static Object getMacOSTS(final String s) {
if ((isMacArchitecture) && (macMRJFileUtils != null)) try {
if ((s == null) || (s.equals(blankTypeString))) return macMRJOSNullObj;
@@ -214,6 +213,38 @@ public final class serverSystem { setMacFSCreator(f, creator);
return getMacFSCreator(f).equals(creator); // this is not always true! I guess it's caused by deprecation of the interface in 1.4er Apple Extensions
}
+
+ /**
+ * finds the maximum possible heap (may cause high system load)
+ * @return heap in -Xmx<i>[heap]</i>m
+ * @author [DW], 07.02.2009
+ */
+ public static int getWin32MaxHeap() {
+ int maxmem = 1000;
+ while(checkWin32Heap(maxmem)) maxmem += 100;
+ while(!checkWin32Heap(maxmem)) maxmem -= 10;
+ return maxmem;
+ }
+
+ /**
+ * checks heap (may cause high system load)
+ * @param mem heap to check in -Xmx<i>[heap]</i>m
+ * @return true if possible
+ * @author [DW], 07.02.2009
+ */
+ public static boolean checkWin32Heap(int mem){
+ String line = "";
+ final List<String> processArgs = new ArrayList<String>();
+ processArgs.add("java");
+ processArgs.add("-Xms4m");
+ processArgs.add("-Xmx" + Integer.toString(mem) + "m");
+ try {
+ line = consoleInterface.getLastLineConsoleOutput(processArgs, new Log("MEMCHECK"));
+ } catch (final IOException e) {
+ return false;
+ }
+ return (line.indexOf("space for object heap") > -1) ? false : true;
+ }
public static String infoString() {
String s = "System=";
@@ -383,6 +414,9 @@ public final class serverSystem { if (args[0].equals("-u")) {
openBrowser(args[1]);
}
+ if (args[0].equals("-m")) {
+ System.out.println("Maximum possible memory: " + Integer.toString(getWin32MaxHeap()) + "m");
+ }
}
}
diff --git a/source/de/anomic/tools/consoleInterface.java b/source/de/anomic/tools/consoleInterface.java index 50e7a3636..92ba6ca24 100755 --- a/source/de/anomic/tools/consoleInterface.java +++ b/source/de/anomic/tools/consoleInterface.java @@ -92,4 +92,53 @@ public class consoleInterface extends Thread dataIsRead.release(); return output; } + + /** + * simple interface + * @return console output + * @throws IOException + */ + public static List<String> getConsoleOutput(final List<String> processArgs, Log log) throws IOException { + final ProcessBuilder processBuilder = new ProcessBuilder(processArgs); + Process process = null; + consoleInterface inputStream = null; + consoleInterface errorStream = null; + + try { + process = processBuilder.start(); + + inputStream = new consoleInterface(process.getInputStream(), log); + errorStream = new consoleInterface(process.getErrorStream(), log); + + inputStream.start(); + errorStream.start(); + + /*int retval =*/ process.waitFor(); + + } catch (final IOException iox) { + log.logWarning("logpoint 0 " + iox.getMessage()); + throw new IOException(iox.getMessage()); + } catch (final InterruptedException ix) { + log.logWarning("logpoint 1 " + ix.getMessage()); + throw new IOException(ix.getMessage()); + } + final List<String> list = inputStream.getOutput(); + if (list.isEmpty()) { + final String error = errorStream.getOutput().toString(); + log.logWarning("logpoint 2: "+ error); + throw new IOException("empty list: " + error); + } + return list; + } + + public static String getLastLineConsoleOutput(final List<String> processArgs, Log log) throws IOException { + List<String> lines = getConsoleOutput(processArgs, log); + String line = ""; + for (int l = lines.size() - 1; l >= 0; l--) { + line = lines.get(l).trim(); + if (line.length() > 0) break; + } + return line; + } + }
\ No newline at end of file diff --git a/source/de/anomic/tools/diskUsage.java b/source/de/anomic/tools/diskUsage.java index 2ed7e71ae..cf1996f4d 100644 --- a/source/de/anomic/tools/diskUsage.java +++ b/source/de/anomic/tools/diskUsage.java @@ -228,7 +228,7 @@ public class diskUsage { if (usedOS != TRU64 && usedOS != HAIKU) processArgs.add("-l"); - final List<String> lines = getConsoleOutput(processArgs); + final List<String> lines = consoleInterface.getConsoleOutput(processArgs, log); return lines; } @@ -306,7 +306,7 @@ public class diskUsage { yacyUsedVolumes.add(path.substring(0, 1)); } - public static HashMap<String, long[]> dfWindows() { + private static HashMap<String, long[]> dfWindows() { final HashMap<String, long[]> diskUsages = new HashMap<String, long[]>(); for (int i = 0; i < yacyUsedVolumes.size(); i++){ final List<String> processArgs = new ArrayList<String>(); @@ -316,7 +316,7 @@ public class diskUsage { processArgs.add(yacyUsedVolumes.get(i) + ":\\"); try { - final List<String> lines = getConsoleOutput(processArgs); + final List<String> lines = consoleInterface.getConsoleOutput(processArgs, log); String line = ""; for (int l = lines.size() - 1; l >= 0; l--) { @@ -388,38 +388,5 @@ public class diskUsage { yacyUsedVolumes.add(sub); } - private static List<String> getConsoleOutput(final List<String> processArgs) throws IOException { - final ProcessBuilder processBuilder = new ProcessBuilder(processArgs); - Process process = null; - consoleInterface inputStream = null; - consoleInterface errorStream = null; - - try { - process = processBuilder.start(); - - inputStream = new consoleInterface(process.getInputStream(), log); - errorStream = new consoleInterface(process.getErrorStream(), log); - - inputStream.start(); - errorStream.start(); - - /*int retval =*/ process.waitFor(); - - } catch (final IOException iox) { - log.logWarning("logpoint 0 " + iox.getMessage()); - throw new IOException(iox.getMessage()); - } catch (final InterruptedException ix) { - log.logWarning("logpoint 1 " + ix.getMessage()); - throw new IOException(ix.getMessage()); - } - final List<String> list = inputStream.getOutput(); - if (list.isEmpty()) { - final String error = errorStream.getOutput().toString(); - log.logWarning("logpoint 2: "+ error); - throw new IOException("empty list: " + error); - } - return list; - } - } |
