mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 02:01:24 +08:00
[Java] Enable direct call by default. (#7408)
* WIP * Address comments. * Linting * Fix * Fix * Fix test * Fix * Fix single process ci * Fix ut * Update java/test/src/main/java/org/ray/api/test/PlasmaFreeTest.java * Address comments * Fix linting * Minor update comments. * Fix streaming CI
This commit is contained in:
@@ -17,7 +17,6 @@ import org.ray.api.options.ActorCreationOptions;
|
||||
import org.ray.api.options.CallOptions;
|
||||
import org.ray.api.runtime.RayRuntime;
|
||||
import org.ray.api.runtimecontext.RuntimeContext;
|
||||
import org.ray.runtime.actor.NativeRayActor;
|
||||
import org.ray.runtime.config.RayConfig;
|
||||
import org.ray.runtime.context.RuntimeContextImpl;
|
||||
import org.ray.runtime.context.WorkerContext;
|
||||
@@ -166,7 +165,7 @@ public abstract class AbstractRayRuntime implements RayRuntime {
|
||||
private RayObject callNormalFunction(FunctionDescriptor functionDescriptor,
|
||||
Object[] args, int numReturns, CallOptions options) {
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder
|
||||
.wrap(args, functionDescriptor.getLanguage(), /*isDirectCall*/false);
|
||||
.wrap(args, functionDescriptor.getLanguage());
|
||||
List<ObjectId> returnIds = taskSubmitter.submitTask(functionDescriptor,
|
||||
functionArgs, numReturns, options);
|
||||
Preconditions.checkState(returnIds.size() == numReturns && returnIds.size() <= 1);
|
||||
@@ -180,7 +179,7 @@ public abstract class AbstractRayRuntime implements RayRuntime {
|
||||
private RayObject callActorFunction(RayActor rayActor,
|
||||
FunctionDescriptor functionDescriptor, Object[] args, int numReturns) {
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder
|
||||
.wrap(args, functionDescriptor.getLanguage(), isDirectCall(rayActor));
|
||||
.wrap(args, functionDescriptor.getLanguage());
|
||||
List<ObjectId> returnIds = taskSubmitter.submitActorTask(rayActor,
|
||||
functionDescriptor, functionArgs, numReturns, null);
|
||||
Preconditions.checkState(returnIds.size() == numReturns && returnIds.size() <= 1);
|
||||
@@ -194,7 +193,7 @@ public abstract class AbstractRayRuntime implements RayRuntime {
|
||||
private RayActor createActorImpl(FunctionDescriptor functionDescriptor,
|
||||
Object[] args, ActorCreationOptions options) {
|
||||
List<FunctionArg> functionArgs = ArgumentsBuilder
|
||||
.wrap(args, functionDescriptor.getLanguage(), /*isDirectCall*/false);
|
||||
.wrap(args, functionDescriptor.getLanguage());
|
||||
if (functionDescriptor.getLanguage() != Language.JAVA && options != null) {
|
||||
Preconditions.checkState(Strings.isNullOrEmpty(options.jvmOptions));
|
||||
}
|
||||
@@ -202,13 +201,6 @@ public abstract class AbstractRayRuntime implements RayRuntime {
|
||||
return actor;
|
||||
}
|
||||
|
||||
private boolean isDirectCall(RayActor rayActor) {
|
||||
if (rayActor instanceof NativeRayActor) {
|
||||
return ((NativeRayActor) rayActor).isDirectCallActor();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public WorkerContext getWorkerContext() {
|
||||
return workerContext;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.ray.api.RayActor;
|
||||
import org.ray.api.id.JobId;
|
||||
import org.ray.api.id.UniqueId;
|
||||
import org.ray.runtime.actor.NativeRayActor;
|
||||
import org.ray.runtime.config.RayConfig;
|
||||
import org.ray.runtime.context.NativeWorkerContext;
|
||||
import org.ray.runtime.functionmanager.FunctionManager;
|
||||
@@ -137,9 +136,6 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
|
||||
|
||||
@Override
|
||||
public void killActor(RayActor<?> actor) {
|
||||
if (!((NativeRayActor) actor).isDirectCallActor()) {
|
||||
throw new UnsupportedOperationException("Only direct call actors can be killed.");
|
||||
}
|
||||
nativeKillActor(nativeCoreWorkerPointer, actor.getId().getBytes());
|
||||
}
|
||||
|
||||
|
||||
@@ -64,10 +64,6 @@ public abstract class NativeRayActor implements RayActor, Externalizable {
|
||||
return Language.forNumber(nativeGetLanguage(nativeCoreWorkerPointer, actorId));
|
||||
}
|
||||
|
||||
public boolean isDirectCallActor() {
|
||||
return nativeIsDirectCallActor(nativeCoreWorkerPointer, actorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeObject(toBytes());
|
||||
@@ -119,9 +115,6 @@ public abstract class NativeRayActor implements RayActor, Externalizable {
|
||||
private static native int nativeGetLanguage(
|
||||
long nativeCoreWorkerPointer, byte[] actorId);
|
||||
|
||||
private static native boolean nativeIsDirectCallActor(
|
||||
long nativeCoreWorkerPointer, byte[] actorId);
|
||||
|
||||
static native List<String> nativeGetActorCreationTaskFunctionDescriptor(
|
||||
long nativeCoreWorkerPointer, byte[] actorId);
|
||||
|
||||
|
||||
@@ -2,12 +2,8 @@ package org.ray.runtime.task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.ray.api.Ray;
|
||||
import org.ray.api.RayObject;
|
||||
import org.ray.api.id.ObjectId;
|
||||
import org.ray.api.runtime.RayRuntime;
|
||||
import org.ray.runtime.AbstractRayRuntime;
|
||||
import org.ray.runtime.RayMultiWorkerNativeRuntime;
|
||||
import org.ray.runtime.generated.Common.Language;
|
||||
import org.ray.runtime.object.NativeRayObject;
|
||||
import org.ray.runtime.object.ObjectSerializer;
|
||||
@@ -32,27 +28,17 @@ public class ArgumentsBuilder {
|
||||
/**
|
||||
* Convert real function arguments to task spec arguments.
|
||||
*/
|
||||
public static List<FunctionArg> wrap(Object[] args, Language language, boolean isDirectCall) {
|
||||
public static List<FunctionArg> wrap(Object[] args, Language language) {
|
||||
List<FunctionArg> ret = new ArrayList<>();
|
||||
for (Object arg : args) {
|
||||
ObjectId id = null;
|
||||
NativeRayObject value = null;
|
||||
if (arg instanceof RayObject) {
|
||||
if (isDirectCall) {
|
||||
throw new IllegalArgumentException(
|
||||
"Passing RayObject to a direct call actor is not supported.");
|
||||
}
|
||||
id = ((RayObject) arg).getId();
|
||||
} else {
|
||||
value = ObjectSerializer.serialize(arg);
|
||||
if (!isDirectCall && value.data.length > LARGEST_SIZE_PASS_BY_VALUE) {
|
||||
RayRuntime runtime = Ray.internal();
|
||||
if (runtime instanceof RayMultiWorkerNativeRuntime) {
|
||||
runtime = ((RayMultiWorkerNativeRuntime) runtime).getCurrentRuntime();
|
||||
}
|
||||
id = ((AbstractRayRuntime) runtime).getObjectStore()
|
||||
.putRaw(value);
|
||||
value = null;
|
||||
if (value.data.length > LARGEST_SIZE_PASS_BY_VALUE) {
|
||||
// Do nothing since we are not support pass by reference in direct call.
|
||||
}
|
||||
}
|
||||
if (language == Language.PYTHON) {
|
||||
|
||||
Reference in New Issue
Block a user