* 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
pull/1/head
lotus 16 years ago
parent 49d95fb3d9
commit e8ae2599fd

@ -405,6 +405,7 @@
<include name="startYACY.bat"/> <include name="startYACY.bat"/>
<include name="startYACY_debug.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_Win9x.bat"/>
<include name="startYACY_noconsole_Win9x.bat"/> <include name="startYACY_noconsole_Win9x.bat"/>
@ -580,6 +581,7 @@
<include name="startYACY.bat"/> <include name="startYACY.bat"/>
<include name="startYACY_noconsole.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_Win9x.bat"/>
<include name="startYACY_noconsole_Win9x.bat"/> <include name="startYACY_noconsole_Win9x.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

@ -27,12 +27,15 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Vector; import java.util.Vector;
import de.anomic.kelondro.util.Log; import de.anomic.kelondro.util.Log;
import de.anomic.kelondro.util.FileUtils; import de.anomic.kelondro.util.FileUtils;
import de.anomic.tools.consoleInterface;
public final class serverSystem { public final class serverSystem {
@ -109,10 +112,6 @@ public final class serverSystem {
if (isWindows) maxPathLength = 255; else maxPathLength = 65535; if (isWindows) maxPathLength = 255; else maxPathLength = 65535;
} }
/* public static boolean isWindows() {
return systemOS == systemWindows;
}*/
public static Object getMacOSTS(final String s) { public static Object getMacOSTS(final String s) {
if ((isMacArchitecture) && (macMRJFileUtils != null)) try { if ((isMacArchitecture) && (macMRJFileUtils != null)) try {
if ((s == null) || (s.equals(blankTypeString))) return macMRJOSNullObj; if ((s == null) || (s.equals(blankTypeString))) return macMRJOSNullObj;
@ -215,6 +214,38 @@ public final class serverSystem {
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 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() { public static String infoString() {
String s = "System="; String s = "System=";
if (systemOS == systemUnknown) s += "unknown"; if (systemOS == systemUnknown) s += "unknown";
@ -383,6 +414,9 @@ public final class serverSystem {
if (args[0].equals("-u")) { if (args[0].equals("-u")) {
openBrowser(args[1]); openBrowser(args[1]);
} }
if (args[0].equals("-m")) {
System.out.println("Maximum possible memory: " + Integer.toString(getWin32MaxHeap()) + "m");
}
} }
} }

@ -92,4 +92,53 @@ public class consoleInterface extends Thread
dataIsRead.release(); dataIsRead.release();
return output; 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;
}
} }

@ -228,7 +228,7 @@ public class diskUsage {
if (usedOS != TRU64 && usedOS != HAIKU) if (usedOS != TRU64 && usedOS != HAIKU)
processArgs.add("-l"); processArgs.add("-l");
final List<String> lines = getConsoleOutput(processArgs); final List<String> lines = consoleInterface.getConsoleOutput(processArgs, log);
return lines; return lines;
} }
@ -306,7 +306,7 @@ public class diskUsage {
yacyUsedVolumes.add(path.substring(0, 1)); 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[]>(); final HashMap<String, long[]> diskUsages = new HashMap<String, long[]>();
for (int i = 0; i < yacyUsedVolumes.size(); i++){ for (int i = 0; i < yacyUsedVolumes.size(); i++){
final List<String> processArgs = new ArrayList<String>(); final List<String> processArgs = new ArrayList<String>();
@ -316,7 +316,7 @@ public class diskUsage {
processArgs.add(yacyUsedVolumes.get(i) + ":\\"); processArgs.add(yacyUsedVolumes.get(i) + ":\\");
try { try {
final List<String> lines = getConsoleOutput(processArgs); final List<String> lines = consoleInterface.getConsoleOutput(processArgs, log);
String line = ""; String line = "";
for (int l = lines.size() - 1; l >= 0; l--) { for (int l = lines.size() - 1; l >= 0; l--) {
@ -388,38 +388,5 @@ public class diskUsage {
yacyUsedVolumes.add(sub); 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;
}
} }

Loading…
Cancel
Save