diff --git a/protocol.txt b/protocol.txt index c3a3712..3d769c7 100644 --- a/protocol.txt +++ b/protocol.txt @@ -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. diff --git a/src/com/sheepit/client/Configuration.java b/src/com/sheepit/client/Configuration.java index 714dd5d..a30f9d7 100644 --- a/src/com/sheepit/client/Configuration.java +++ b/src/com/sheepit/client/Configuration.java @@ -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; diff --git a/src/com/sheepit/client/Job.java b/src/com/sheepit/client/Job.java index 6005eb3..d200ae0 100644 --- a/src/com/sheepit/client/Job.java +++ b/src/com/sheepit/client/Job.java @@ -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(); diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index 59b8114..300a145 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -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 { diff --git a/src/com/sheepit/client/SettingsLoader.java b/src/com/sheepit/client/SettingsLoader.java index efae589..07df79b 100644 --- a/src/com/sheepit/client/SettingsLoader.java +++ b/src/com/sheepit/client/SettingsLoader.java @@ -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)); } diff --git a/src/com/sheepit/client/standalone/swing/activity/Settings.java b/src/com/sheepit/client/standalone/swing/activity/Settings.java index 684ff32..e15b445 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/com/sheepit/client/standalone/swing/activity/Settings.java @@ -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 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 labelTable = new Hashtable(); + 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 {