diff --git a/frontend/archive/src/main/java/org/pytorch/serve/archive/model/ModelConfig.java b/frontend/archive/src/main/java/org/pytorch/serve/archive/model/ModelConfig.java index c83da0523c..1693bc8424 100644 --- a/frontend/archive/src/main/java/org/pytorch/serve/archive/model/ModelConfig.java +++ b/frontend/archive/src/main/java/org/pytorch/serve/archive/model/ModelConfig.java @@ -11,6 +11,9 @@ public class ModelConfig { private static final Logger logger = LoggerFactory.getLogger(ModelConfig.class); + public static final int defaultStartupTimeout = 120; // unit: sec + public static final int defaultResponseTimeout = 120; // unit: sec + /** the minimum number of workers of a model */ private int minWorkers; /** the maximum number of workers of a model */ @@ -20,9 +23,9 @@ public class ModelConfig { /** the maximum delay in msec of a batch of a model */ private int maxBatchDelay; /** the timeout in sec of a specific model's response. */ - private int responseTimeout = 120; // unit: sec + private int responseTimeout = defaultResponseTimeout; /** the timeout in sec of a specific model's startup. */ - private int startupTimeout = 120; // unit: sec + private int startupTimeout = defaultStartupTimeout; /** * the device type where the model is loaded. It can be gpu, cpu. The model is loaded on CPU if * deviceType: "cpu" is set on a GPU host. diff --git a/frontend/server/src/main/java/org/pytorch/serve/wlm/Model.java b/frontend/server/src/main/java/org/pytorch/serve/wlm/Model.java index c41a495260..32ae5bcc06 100644 --- a/frontend/server/src/main/java/org/pytorch/serve/wlm/Model.java +++ b/frontend/server/src/main/java/org/pytorch/serve/wlm/Model.java @@ -193,9 +193,17 @@ public void setModelState(JsonObject modelInfo) { minWorkers = modelInfo.get(MIN_WORKERS).getAsInt(); maxWorkers = modelInfo.get(MAX_WORKERS).getAsInt(); maxBatchDelay = modelInfo.get(MAX_BATCH_DELAY).getAsInt(); - responseTimeout = modelInfo.get(RESPONSE_TIMEOUT).getAsInt(); - startupTimeout = modelInfo.get(STARTUP_TIMEOUT).getAsInt(); batchSize = modelInfo.get(BATCH_SIZE).getAsInt(); + responseTimeout = + modelInfo.has(RESPONSE_TIMEOUT) && !modelInfo.get(RESPONSE_TIMEOUT).isJsonNull() + ? modelInfo.get(RESPONSE_TIMEOUT).getAsInt() + : modelArchive.getModelConfig() + .defaultResponseTimeout; // default value for responseTimeout + startupTimeout = + modelInfo.has(STARTUP_TIMEOUT) && !modelInfo.get(STARTUP_TIMEOUT).isJsonNull() + ? modelInfo.get(STARTUP_TIMEOUT).getAsInt() + : modelArchive.getModelConfig() + .defaultStartupTimeout; // default value for startupTimeout JsonElement runtime = modelInfo.get(RUNTIME_TYPE); String runtime_str = Manifest.RuntimeType.PYTHON.getValue();