diff --git a/src/com/sheepit/client/Configuration.java b/src/com/sheepit/client/Configuration.java index ecb0a61..c9a4871 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 priority; private ComputeType computeMethod; private GPUDevice GPUDevice; private boolean printLog; @@ -63,6 +64,7 @@ public class Configuration { this.static_exeDirName = "exe"; this.maxUploadingJob = 1; this.nbCores = -1; // ie not set + this.priority = 19; this.computeMethod = null; this.GPUDevice = null; this.userSpecifiedACacheDir = false; @@ -125,6 +127,20 @@ public class Configuration { return this.nbCores; } + public void setUsePriority(int priority) { + if (priority > 19) + priority = 19; + if (priority < -19) + priority = -19; + + this.priority = priority; + + } + + public int getPriority() { + return this.priority; + } + public void setPrintLog(boolean val) { this.printLog = val; } diff --git a/src/com/sheepit/client/Job.java b/src/com/sheepit/client/Job.java index 84e0f07..39b01af 100644 --- a/src/com/sheepit/client/Job.java +++ b/src/com/sheepit/client/Job.java @@ -237,6 +237,7 @@ public class Job { new_env.put("BLENDER_USER_CONFIG", config.workingDirectory.getAbsolutePath().replace("\\", "\\\\")); new_env.put("CORES", Integer.toString(config.getNbCores())); + new_env.put("PRIORITY", Integer.toString(config.getPriority())); for (String arg : command1) { switch (arg) { diff --git a/src/com/sheepit/client/os/FreeBSD.java b/src/com/sheepit/client/os/FreeBSD.java index 18f81af..375d7c4 100644 --- a/src/com/sheepit/client/os/FreeBSD.java +++ b/src/com/sheepit/client/os/FreeBSD.java @@ -161,7 +161,12 @@ public class FreeBSD extends OS { } if (this.hasNiceBinary.booleanValue()) { // launch the process in lowest priority - actual_command.add(0, "19"); + if (env_overight != null) { + actual_command.add(0, env_overight.get("PRIORITY")); + } + else { + actual_command.add(0, "19"); + } actual_command.add(0, "-n"); actual_command.add(0, NICE_BINARY_PATH); } diff --git a/src/com/sheepit/client/os/Linux.java b/src/com/sheepit/client/os/Linux.java index 99d363a..c19c0cb 100644 --- a/src/com/sheepit/client/os/Linux.java +++ b/src/com/sheepit/client/os/Linux.java @@ -144,7 +144,12 @@ public class Linux extends OS { } if (this.hasNiceBinary.booleanValue()) { // launch the process in lowest priority - actual_command.add(0, "19"); + if (env_overight != null) { + actual_command.add(0, env_overight.get("PRIORITY")); + } + else { + actual_command.add(0, "19"); + } actual_command.add(0, "-n"); actual_command.add(0, NICE_BINARY_PATH); } diff --git a/src/com/sheepit/client/os/Mac.java b/src/com/sheepit/client/os/Mac.java index fba30cc..8d7f1ac 100644 --- a/src/com/sheepit/client/os/Mac.java +++ b/src/com/sheepit/client/os/Mac.java @@ -148,7 +148,12 @@ public class Mac extends OS { } if (this.hasNiceBinary.booleanValue()) { // launch the process in lowest priority - actual_command.add(0, "19"); + if (env != null) { + actual_command.add(0, env.get("PRIORITY")); + } + else { + actual_command.add(0, "19"); + } actual_command.add(0, "-n"); actual_command.add(0, NICE_BINARY_PATH); } diff --git a/src/com/sheepit/client/os/Windows.java b/src/com/sheepit/client/os/Windows.java index 08fd1bc..c1381b5 100644 --- a/src/com/sheepit/client/os/Windows.java +++ b/src/com/sheepit/client/os/Windows.java @@ -132,7 +132,13 @@ public class Windows extends OS { } Process p = builder.start(); WinProcess wproc = new WinProcess(p); - wproc.setPriority(WinProcess.PRIORITY_BELOW_NORMAL); + if (env != null) { + String priority = env.get("PRIORITY"); + wproc.setPriority(getPriorityClass(Integer.parseInt(priority))); + } + else { + wproc.setPriority(WinProcess.PRIORITY_BELOW_NORMAL); + } if (env != null) { String cores = env.get("CORES"); wproc.setAffinity(Integer.parseInt(cores)); @@ -140,6 +146,65 @@ public class Windows extends OS { return p; } + int getPriorityClass(int priority) { + int process_class = WinProcess.PRIORITY_IDLE; + switch (priority) { + case 19: + case 18: + case 17: + case 16: + case 15: + process_class = WinProcess.PRIORITY_IDLE; + break; + + case 14: + case 13: + case 12: + case 11: + case 10: + case 9: + case 8: + case 7: + case 6: + case 5: + process_class = WinProcess.PRIORITY_BELOW_NORMAL; + break; + case 4: + case 3: + case 2: + case 1: + case 0: + case -1: + case -2: + case -3: + process_class = WinProcess.PRIORITY_NORMAL; + break; + case -4: + case -5: + case -6: + case -7: + case -8: + case -9: + process_class = WinProcess.PRIORITY_ABOVE_NORMAL; + break; + case -10: + case -11: + case -12: + case -13: + case -14: + process_class = WinProcess.PRIORITY_HIGH; + break; + case -15: + case -16: + case -17: + case -18: + case -19: + process_class = WinProcess.PRIORITY_REALTIME; + break; + } + return process_class; + } + @Override public boolean kill(Process process) { if (process != null) { diff --git a/src/com/sheepit/client/standalone/Worker.java b/src/com/sheepit/client/standalone/Worker.java index 5994905..64691a7 100644 --- a/src/com/sheepit/client/standalone/Worker.java +++ b/src/com/sheepit/client/standalone/Worker.java @@ -91,6 +91,9 @@ public class Worker { @Option(name = "--no-systray", usage = "Don't use systray", required = false) private boolean no_systray = false; + @Option(name = "-priority", usage = "Set render process priority (19 lowest to -19 highest)", required = false) + private int priority = 19; + public static void main(String[] args) { new Worker().doMain(args); } @@ -112,6 +115,7 @@ public class Worker { ComputeType compute_method = ComputeType.CPU; Configuration config = new Configuration(null, login, password); config.setPrintLog(print_log); + config.setUsePriority(priority); if (cache_dir != null) { File a_dir = new File(cache_dir);