mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 21:38:18 +08:00
Add dynamic worker options for worker command. (#4970)
* Add fields for fbs * WIP * Fix complition errors * Add java part * FIx * Fix * Fix * Fix lint * Refine API * address comments and add test * Fix * Address comment. * Address comments. * Fix linting * Refine * Fix lint * WIP: address comment. * Fix java * Fix py * Refin * Fix * Fix * Fix linting * Fix lint * Address comments * WIP * Fix * Fix * minor refine * Fix lint * Fix raylet test. * Fix lint * Update src/ray/raylet/worker_pool.h Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Update java/runtime/src/main/java/org/ray/runtime/AbstractRayRuntime.java Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Address comments. * Address comments. * Fix test. * Update src/ray/raylet/worker_pool.h Co-Authored-By: Hao Chen <chenh1024@gmail.com> * Address comments. * Address comments. * Fix * Fix lint * Fix lint * Fix * Address comments. * Fix linting
This commit is contained in:
@@ -13,9 +13,14 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
||||
|
||||
public final int maxReconstructions;
|
||||
|
||||
private ActorCreationOptions(Map<String, Double> resources, int maxReconstructions) {
|
||||
public final String jvmOptions;
|
||||
|
||||
private ActorCreationOptions(Map<String, Double> resources,
|
||||
int maxReconstructions,
|
||||
String jvmOptions) {
|
||||
super(resources);
|
||||
this.maxReconstructions = maxReconstructions;
|
||||
this.jvmOptions = jvmOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,6 +30,7 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
||||
|
||||
private Map<String, Double> resources = new HashMap<>();
|
||||
private int maxReconstructions = NO_RECONSTRUCTION;
|
||||
private String jvmOptions = "";
|
||||
|
||||
public Builder setResources(Map<String, Double> resources) {
|
||||
this.resources = resources;
|
||||
@@ -36,8 +42,13 @@ public class ActorCreationOptions extends BaseTaskOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setJvmOptions(String jvmOptions) {
|
||||
this.jvmOptions = jvmOptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActorCreationOptions createActorCreationOptions() {
|
||||
return new ActorCreationOptions(resources, maxReconstructions);
|
||||
return new ActorCreationOptions(resources, maxReconstructions, jvmOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.ray.runtime.task.ArgumentsBuilder;
|
||||
import org.ray.runtime.task.TaskLanguage;
|
||||
import org.ray.runtime.task.TaskSpec;
|
||||
import org.ray.runtime.util.IdUtil;
|
||||
import org.ray.runtime.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -363,8 +364,13 @@ public abstract class AbstractRayRuntime implements RayRuntime {
|
||||
}
|
||||
|
||||
int maxActorReconstruction = 0;
|
||||
List<String> dynamicWorkerOptions = ImmutableList.of();
|
||||
if (taskOptions instanceof ActorCreationOptions) {
|
||||
maxActorReconstruction = ((ActorCreationOptions) taskOptions).maxReconstructions;
|
||||
String jvmOptions = ((ActorCreationOptions) taskOptions).jvmOptions;
|
||||
if (!StringUtil.isNullOrEmpty(jvmOptions)) {
|
||||
dynamicWorkerOptions = ImmutableList.of(((ActorCreationOptions) taskOptions).jvmOptions);
|
||||
}
|
||||
}
|
||||
|
||||
TaskLanguage language;
|
||||
@@ -393,7 +399,8 @@ public abstract class AbstractRayRuntime implements RayRuntime {
|
||||
numReturns,
|
||||
resources,
|
||||
language,
|
||||
functionDescriptor
|
||||
functionDescriptor,
|
||||
dynamicWorkerOptions
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -190,9 +190,16 @@ public class RayletClientImpl implements RayletClient {
|
||||
JavaFunctionDescriptor functionDescriptor = new JavaFunctionDescriptor(
|
||||
info.functionDescriptor(0), info.functionDescriptor(1), info.functionDescriptor(2)
|
||||
);
|
||||
|
||||
// Deserialize dynamic worker options.
|
||||
List<String> dynamicWorkerOptions = new ArrayList<>();
|
||||
for (int i = 0; i < info.dynamicWorkerOptionsLength(); ++i) {
|
||||
dynamicWorkerOptions.add(info.dynamicWorkerOptions(i));
|
||||
}
|
||||
|
||||
return new TaskSpec(driverId, taskId, parentTaskId, parentCounter, actorCreationId,
|
||||
maxActorReconstructions, actorId, actorHandleId, actorCounter, newActorHandles,
|
||||
args, numReturns, resources, TaskLanguage.JAVA, functionDescriptor);
|
||||
args, numReturns, resources, TaskLanguage.JAVA, functionDescriptor, dynamicWorkerOptions);
|
||||
}
|
||||
|
||||
private static ByteBuffer convertTaskSpecToFlatbuffer(TaskSpec task) {
|
||||
@@ -275,6 +282,12 @@ public class RayletClientImpl implements RayletClient {
|
||||
functionDescriptorOffset = fbb.createVectorOfTables(functionDescriptorOffsets);
|
||||
}
|
||||
|
||||
int [] dynamicWorkerOptionsOffsets = new int[task.dynamicWorkerOptions.size()];
|
||||
for (int index = 0; index < task.dynamicWorkerOptions.size(); ++index) {
|
||||
dynamicWorkerOptionsOffsets[index] = fbb.createString(task.dynamicWorkerOptions.get(index));
|
||||
}
|
||||
int dynamicWorkerOptionsOffset = fbb.createVectorOfTables(dynamicWorkerOptionsOffsets);
|
||||
|
||||
int root = TaskInfo.createTaskInfo(
|
||||
fbb,
|
||||
driverIdOffset,
|
||||
@@ -293,7 +306,8 @@ public class RayletClientImpl implements RayletClient {
|
||||
requiredResourcesOffset,
|
||||
requiredPlacementResourcesOffset,
|
||||
language,
|
||||
functionDescriptorOffset);
|
||||
functionDescriptorOffset,
|
||||
dynamicWorkerOptionsOffset);
|
||||
fbb.finish(root);
|
||||
ByteBuffer buffer = fbb.dataBuffer();
|
||||
|
||||
|
||||
@@ -319,6 +319,9 @@ public class RunManager {
|
||||
|
||||
cmd.addAll(rayConfig.jvmParameters);
|
||||
|
||||
// jvm options
|
||||
cmd.add("RAY_WORKER_OPTION_0");
|
||||
|
||||
// Main class
|
||||
cmd.add(WORKER_CLASS);
|
||||
String command = Joiner.on(" ").join(cmd);
|
||||
|
||||
@@ -63,6 +63,8 @@ public class TaskSpec {
|
||||
// Language of this task.
|
||||
public final TaskLanguage language;
|
||||
|
||||
public final List<String> dynamicWorkerOptions;
|
||||
|
||||
// Descriptor of the remote function.
|
||||
// Note, if task language is Java, the type is JavaFunctionDescriptor. If the task language
|
||||
// is Python, the type is PyFunctionDescriptor.
|
||||
@@ -93,7 +95,8 @@ public class TaskSpec {
|
||||
int numReturns,
|
||||
Map<String, Double> resources,
|
||||
TaskLanguage language,
|
||||
FunctionDescriptor functionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor,
|
||||
List<String> dynamicWorkerOptions) {
|
||||
this.driverId = driverId;
|
||||
this.taskId = taskId;
|
||||
this.parentTaskId = parentTaskId;
|
||||
@@ -106,6 +109,8 @@ public class TaskSpec {
|
||||
this.newActorHandles = newActorHandles;
|
||||
this.args = args;
|
||||
this.numReturns = numReturns;
|
||||
this.dynamicWorkerOptions = dynamicWorkerOptions;
|
||||
|
||||
returnIds = new ObjectId[numReturns];
|
||||
for (int i = 0; i < numReturns; ++i) {
|
||||
returnIds[i] = IdUtil.computeReturnId(taskId, i + 1);
|
||||
@@ -157,6 +162,7 @@ public class TaskSpec {
|
||||
", resources=" + resources +
|
||||
", language=" + language +
|
||||
", functionDescriptor=" + functionDescriptor +
|
||||
", dynamicWorkerOptions=" + dynamicWorkerOptions +
|
||||
", executionDependencies=" + executionDependencies +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.ray.api.test;
|
||||
|
||||
import org.ray.api.Ray;
|
||||
import org.ray.api.RayActor;
|
||||
import org.ray.api.RayObject;
|
||||
import org.ray.api.TestUtils;
|
||||
import org.ray.api.annotation.RayRemote;
|
||||
import org.ray.api.options.ActorCreationOptions;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class WorkerJvmOptionsTest extends BaseTest {
|
||||
|
||||
@RayRemote
|
||||
public static class Echo {
|
||||
String getOptions() {
|
||||
return System.getProperty("test.suffix");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJvmOptions() {
|
||||
TestUtils.skipTestUnderSingleProcess();
|
||||
ActorCreationOptions options = new ActorCreationOptions.Builder()
|
||||
.setJvmOptions("-Dtest.suffix=suffix")
|
||||
.createActorCreationOptions();
|
||||
RayActor<Echo> actor = Ray.createActor(Echo::new, options);
|
||||
RayObject<String> obj = Ray.call(Echo::getOptions, actor);
|
||||
Assert.assertEquals(obj.get(), "suffix");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user