Allow user to set maximum memory he allows render to use

This commit is contained in:
Laurent Clouet
2017-03-29 22:13:04 +02:00
parent 42e952bddf
commit 905fff3313
6 changed files with 85 additions and 8 deletions

View File

@@ -12,6 +12,7 @@ Parameters as GET:
* cpu_model_name: CPU's model as human readable, on linux it can be get in /proc/cpuinfo via the attribute "model name".
* cpu_cores: Number of core (or thread) available.
* ram: Memory available in kilo bytes.
* ram_max: Maximum memory allowed for render (in kilo bytes).
* extras (optional): Extra data use for the configuration.
* hostname (optional): Hostname of the machine, it's useful when the user have multiple machines with same hardware configuration. It's only used for display for server website.

View File

@@ -47,6 +47,7 @@ public class Configuration {
private String proxy;
private int maxUploadingJob;
private int nbCores;
private int maxMemory; // max memory allowed for render
private int priority;
private ComputeType computeMethod;
private GPUDevice GPUDevice;
@@ -64,6 +65,7 @@ public class Configuration {
this.static_exeDirName = "exe";
this.maxUploadingJob = 1;
this.nbCores = -1; // ie not set
this.maxMemory = -1; // ie not set
this.priority = 19; // default lowest
this.computeMethod = null;
this.GPUDevice = null;
@@ -127,6 +129,14 @@ public class Configuration {
return this.nbCores;
}
public void setMaxMemory(int max) {
this.maxMemory = max;
}
public int getMaxMemory() {
return this.maxMemory;
}
public void setUsePriority(int priority) {
if (priority > 19)
priority = 19;

View File

@@ -310,9 +310,18 @@ public class Job {
log.debug("renderer output");
try {
while ((line = input.readLine()) != null) {
updateRenderingMemoryPeak(line);
log.debug(line);
updateRenderingMemoryPeak(line);
if (process.getMemoryUsed() > config.getMaxMemory()) {
log.debug("Blocking render because process ram used (" + process.getMemoryUsed() + "k) is over user setting (" + config.getMaxMemory() + "k)");
process.finish();
if (script_file != null) {
script_file.delete();
}
return Error.Type.RENDERER_OUT_OF_MEMORY;
}
if ((new Date().getTime() - last_update_status) > 2000) { // only call the update every two seconds
updateRenderingStatus(line);
last_update_status = new Date().getTime();

View File

@@ -291,7 +291,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
HttpURLConnection connection = null;
try {
OS os = OS.getOS();
String url = String.format("%s?computemethod=%s&cpu_cores=%s", this.getPage("request-job"), this.user_config.computeMethodToInt(), ((this.user_config.getNbCores() == -1) ? os.getCPU().cores() : this.user_config.getNbCores()));
String url = String.format("%s?computemethod=%s&cpu_cores=%s&ram_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());
if (this.user_config.getComputeMethod() != ComputeType.CPU && this.user_config.getGPUDevice() != null) {
String gpu_model = "";
try {

View File

@@ -46,6 +46,7 @@ public class SettingsLoader {
private String computeMethod;
private String gpu;
private String cores;
private String ram;
private String cacheDir;
private String autoSignIn;
private String ui;
@@ -60,7 +61,7 @@ public class SettingsLoader {
path = path_;
}
public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_, int priority_) {
public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, int maxRam_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_, int priority_) {
path = getDefaultFilePath();
login = login_;
password = password_;
@@ -73,7 +74,9 @@ public class SettingsLoader {
if (cores_ > 0) {
cores = String.valueOf(cores_);
}
if (maxRam_ > 0) {
ram = String.valueOf(maxRam_);
}
if (computeMethod_ != null) {
try {
computeMethod = computeMethod_.name();
@@ -118,6 +121,10 @@ public class SettingsLoader {
prop.setProperty("cpu-cores", cores);
}
if (ram != null) {
prop.setProperty("ram", ram);
}
if (login != null) {
prop.setProperty("login", login);
}
@@ -185,6 +192,7 @@ public class SettingsLoader {
this.ui = null;
this.tileSize = null;
this.priority = 19; // must be the same default as Configuration
this.ram = null;
if (new File(path).exists() == false) {
return;
@@ -212,6 +220,10 @@ public class SettingsLoader {
this.cores = prop.getProperty("cpu-cores");
}
if (prop.containsKey("ram")) {
this.ram = prop.getProperty("ram");
}
if (prop.containsKey("login")) {
this.login = prop.getProperty("login");
}
@@ -298,6 +310,11 @@ public class SettingsLoader {
if (config.getNbCores() == -1 && cores != null) {
config.setUseNbCores(Integer.valueOf(cores));
}
if (config.getMaxMemory() == -1 && ram != null) {
config.setMaxMemory(Integer.valueOf(ram));
}
if (config.getUserSpecifiedACacheDir() == false && cacheDir != null && new File(cacheDir).exists()) {
config.setCacheDir(new File(cacheDir));
}

View File

@@ -28,6 +28,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
@@ -67,6 +68,7 @@ public class Settings implements Activity {
private JCheckBox useCPU;
private List<JCheckBoxGPU> useGPUs;
private JSlider cpuCores;
private JSlider ram;
private JSlider priority;
private JTextField proxy;
@@ -240,8 +242,38 @@ public class Settings implements Activity {
compute_devices_panel.add(cpuCores);
}
// priority
// max ram allowed to render
OS os = OS.getOS();
int all_ram = os.getMemory();
ram = new JSlider(0, all_ram);
int step = 1000000;
Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
for (int g = 0; g < all_ram; g += step) {
labelTable.put(new Integer(g), new JLabel("" + (g / step)));
}
ram.setMajorTickSpacing(step);
ram.setLabelTable(labelTable);
ram.setPaintTicks(true);
ram.setPaintLabels(true);
ram.setValue(config.getMaxMemory() != -1 ? config.getMaxMemory() : os.getMemory());
JLabel ramLabel = new JLabel("Memory:");
compute_devices_constraints.weightx = 1.0 / gpus.size();
compute_devices_constraints.gridx = 0;
compute_devices_constraints.gridy++;
gridbag.setConstraints(ramLabel, compute_devices_constraints);
compute_devices_panel.add(ramLabel);
compute_devices_constraints.gridx = 1;
compute_devices_constraints.weightx = 1.0;
gridbag.setConstraints(ram, compute_devices_constraints);
compute_devices_panel.add(ram);
parent.getContentPane().add(compute_devices_panel, constraints);
// priority
boolean high_priority_support = os.getSupportHighPriority();
priority = new JSlider(high_priority_support ? -19 : 0, 19);
priority.setMajorTickSpacing(19);
@@ -263,7 +295,6 @@ public class Settings implements Activity {
gridbag.setConstraints(priority, compute_devices_constraints);
compute_devices_panel.add(priority);
currentRow++;
constraints.gridx = 0;
@@ -493,6 +524,15 @@ public class Settings implements Activity {
config.setUseNbCores(cpu_cores);
}
int max_ram = -1;
if (ram != null) {
max_ram = ram.getValue();
}
if (max_ram > 0) {
config.setMaxMemory(max_ram);
}
config.setUsePriority(priority.getValue());
String proxyText = null;
@@ -532,7 +572,7 @@ public class Settings implements Activity {
}
if (saveFile.isSelected()) {
new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()).saveFile();
new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, max_ram, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()).saveFile();
}
else {
try {