in frontend/server/src/main/java/com/amazonaws/ml/mms/wlm/WorkerLifeCycle.java [110:178]
public void startBackendServer(int port)
throws WorkerInitializationException, InterruptedException {
File workingDir = new File(configManager.getModelServerHome());
File modelPath;
setPort(port);
try {
modelPath = model.getModelDir().getCanonicalFile();
} catch (IOException e) {
throw new WorkerInitializationException("Failed get MMS home directory", e);
}
String[] args = new String[16];
Manifest.RuntimeType runtime = model.getModelArchive().getManifest().getRuntime();
if (runtime == Manifest.RuntimeType.PYTHON) {
args[0] = configManager.getPythonExecutable();
} else {
args[0] = runtime.getValue();
}
args[1] = new File(workingDir, "mms/model_service_worker.py").getAbsolutePath();
args[2] = "--sock-type";
args[3] = connector.getSocketType();
args[4] = connector.isUds() ? "--sock-name" : "--port";
args[5] = connector.getSocketPath();
args[6] = "--handler";
args[7] = model.getModelArchive().getManifest().getModel().getHandler();
args[8] = "--model-path";
args[9] = model.getModelDir().getAbsolutePath();
args[10] = "--model-name";
args[11] = model.getModelName();
args[12] = "--preload-model";
args[13] = model.preloadModel();
args[14] = "--tmp-dir";
args[15] = System.getProperty("java.io.tmpdir");
String[] envp =
getEnvString(
workingDir.getAbsolutePath(),
modelPath.getAbsolutePath(),
model.getModelArchive().getManifest().getModel().getHandler());
try {
latch = new CountDownLatch(1);
synchronized (this) {
String threadName =
"W-"
+ port
+ '-'
+ model.getModelName()
.substring(0, Math.min(model.getModelName().length(), 25));
process = Runtime.getRuntime().exec(args, envp, modelPath);
attachIOStreams(threadName, process.getInputStream(), process.getErrorStream());
}
if (latch.await(2, TimeUnit.MINUTES)) {
if (!success) {
throw new WorkerInitializationException("Backend stream closed.");
}
return;
}
throw new WorkerInitializationException("Backend worker startup time out.");
} catch (IOException e) {
throw new WorkerInitializationException("Failed start worker process", e);
} finally {
if (!success) {
exit();
}
}
}