Use the actual available free memory instead of the max possible
This commit is contained in:
@@ -287,7 +287,15 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
|||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
OS os = OS.getOS();
|
OS os = OS.getOS();
|
||||||
String url = String.format("%s?computemethod=%s&cpu_cores=%s&ram_max=%s&rendertime_max=%s", this.getPage("request-job"), this.user_config.computeMethodToInt(), ((this.user_config.getNbCores() == -1) ? os.getCPU().cores() : this.user_config.getNbCores()), this.user_config.getMaxMemory(), this.user_config.getMaxRenderTime());
|
int maxMemory = this.user_config.getMaxMemory();
|
||||||
|
int freeMemory = os.getFreeMemory();
|
||||||
|
if (maxMemory < 0) {
|
||||||
|
maxMemory = freeMemory;
|
||||||
|
}
|
||||||
|
else if (freeMemory > 0 && maxMemory > 0) {
|
||||||
|
maxMemory = Math.min(maxMemory, freeMemory);
|
||||||
|
}
|
||||||
|
String url = String.format("%s?computemethod=%s&cpu_cores=%s&ram_max=%s&rendertime_max=%s", this.getPage("request-job"), this.user_config.computeMethodToInt(), ((this.user_config.getNbCores() == -1) ? os.getCPU().cores() : this.user_config.getNbCores()), maxMemory, this.user_config.getMaxRenderTime());
|
||||||
if (this.user_config.getComputeMethod() != ComputeType.CPU && this.user_config.getGPUDevice() != null) {
|
if (this.user_config.getComputeMethod() != ComputeType.CPU && this.user_config.getGPUDevice() != null) {
|
||||||
String gpu_model = "";
|
String gpu_model = "";
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -133,6 +133,11 @@ public class FreeBSD extends OS {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFreeMemory() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCUDALib() {
|
public String getCUDALib() {
|
||||||
return "cuda";
|
return "cuda";
|
||||||
|
|||||||
@@ -116,6 +116,35 @@ public class Linux extends OS {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFreeMemory() {
|
||||||
|
try {
|
||||||
|
String filePath = "/proc/meminfo";
|
||||||
|
Scanner scanner = new Scanner(new File(filePath));
|
||||||
|
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
String line = scanner.nextLine();
|
||||||
|
|
||||||
|
if (line.startsWith("MemFree")) {
|
||||||
|
String buf[] = line.split(":");
|
||||||
|
if (buf.length > 0) {
|
||||||
|
Integer buf2 = new Integer(buf[1].trim().split(" ")[0]);
|
||||||
|
return (((buf2 / 262144) + 1) * 262144); // 256*1024 = 262144
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
catch (java.lang.NoClassDefFoundError e) {
|
||||||
|
System.err.println("OS::Linux::getFreeMemory error " + e + " mostly because Scanner class was introducted by Java 5 and you are running a lower version");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCUDALib() {
|
public String getCUDALib() {
|
||||||
return "cuda";
|
return "cuda";
|
||||||
|
|||||||
@@ -140,6 +140,11 @@ public class Mac extends OS {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFreeMemory() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||||
List<String> actual_command = command;
|
List<String> actual_command = command;
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public abstract class OS {
|
|||||||
|
|
||||||
public abstract int getMemory();
|
public abstract int getMemory();
|
||||||
|
|
||||||
|
public abstract int getFreeMemory();
|
||||||
|
|
||||||
public abstract String getRenderBinaryPath();
|
public abstract String getRenderBinaryPath();
|
||||||
|
|
||||||
public String getCUDALib() {
|
public String getCUDALib() {
|
||||||
|
|||||||
@@ -102,6 +102,21 @@ public class Windows extends OS {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFreeMemory() {
|
||||||
|
try {
|
||||||
|
MEMORYSTATUSEX _memory = new MEMORYSTATUSEX();
|
||||||
|
if (Kernel32.INSTANCE.GlobalMemoryStatusEx(_memory)) {
|
||||||
|
return (int) (_memory.ullAvailPhys.longValue() / 1024); // size in KB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCUDALib() {
|
public String getCUDALib() {
|
||||||
return "nvcuda";
|
return "nvcuda";
|
||||||
|
|||||||
Reference in New Issue
Block a user