Add an option to display max_open_files, by setting -Des.max-open-files to `true`, closes #483.

This commit is contained in:
kimchy 2010-11-06 22:47:09 +02:00
parent 17e5b3dd27
commit 998bde0820
2 changed files with 37 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.Classes;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.CreationException;
import org.elasticsearch.common.inject.spi.Message;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.jline.ANSI;
import org.elasticsearch.common.jna.Natives;
import org.elasticsearch.common.logging.ESLogger;
@ -155,6 +156,11 @@ public class Bootstrap {
System.exit(3);
}
if (System.getProperty("es.max-open-files", "false").equals("true")) {
ESLogger logger = Loggers.getLogger(Bootstrap.class);
logger.info("max_open_files [{}]", FileSystemUtils.maxOpenFiles(new File(tuple.v2().workFile(), "open_files")));
}
String stage = "Initialization";
try {
if (!foreground) {

View File

@ -21,12 +21,42 @@ package org.elasticsearch.common.io;
import java.io.*;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class FileSystemUtils {
public static int maxOpenFiles(File testDir) {
boolean dirCreated = false;
if (!testDir.exists()) {
dirCreated = true;
testDir.mkdirs();
}
List<RandomAccessFile> files = new ArrayList<RandomAccessFile>();
try {
while (true) {
files.add(new RandomAccessFile(new File(testDir, "tmp" + files.size()), "rw"));
}
} catch (IOException ioe) {
int i = 0;
for (RandomAccessFile raf : files) {
try {
raf.close();
} catch (IOException e) {
// ignore
}
new File(testDir, "tmp" + i++).delete();
}
if (dirCreated) {
deleteRecursively(testDir);
}
}
return files.size();
}
public static boolean deleteRecursively(File root) {
return deleteRecursively(root, true);
}