Skip to content

Commit

Permalink
[wlm] Sets default maxWorkers based on OMP_NUM_THREADS (deepjavalibra…
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu authored and KexinFeng committed Aug 16, 2023
1 parent 70df327 commit 499eb4f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wlm/src/main/java/ai/djl/serving/wlm/util/WlmConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ai.djl.Device;
import ai.djl.Model;
import ai.djl.ndarray.NDManager;
import ai.djl.util.Utils;

/** This manages some configurations used by the {@link ai.djl.serving.wlm.WorkLoadManager}. */
public final class WlmConfigManager {
Expand Down Expand Up @@ -199,7 +200,16 @@ public int getDefaultMaxWorkers(Model model) {
}
return 2;
}
return Runtime.getRuntime().availableProcessors();

int cpuCores = Runtime.getRuntime().availableProcessors();
int ompThreads = Integer.parseInt(Utils.getenv("OMP_NUM_THREADS", "-1"));
if (ompThreads > 0) {
if (ompThreads > cpuCores) {
ompThreads = cpuCores;
}
return cpuCores * 2 / ompThreads;
}
return 2;
}

private static int getWorkersProperty(Model model, String key, int def) {
Expand Down

0 comments on commit 499eb4f

Please sign in to comment.