[Java] Support direct call for normal tasks (#7193)

This commit is contained in:
Kai Yang
2020-02-21 10:03:34 +08:00
committed by GitHub
parent f27bb6eb47
commit 007333b960
21 changed files with 184 additions and 99 deletions
@@ -10,24 +10,17 @@ public class ActorCreationOptions extends BaseTaskOptions {
public static final int NO_RECONSTRUCTION = 0;
public static final int INFINITE_RECONSTRUCTION = (int) Math.pow(2, 30);
// DO NOT set this environment variable. It's only used for test purposes.
// Please use `setUseDirectCall` instead.
public static final boolean DEFAULT_USE_DIRECT_CALL = "1"
.equals(System.getenv("ACTOR_CREATION_OPTIONS_DEFAULT_USE_DIRECT_CALL"));
public final int maxReconstructions;
public final boolean useDirectCall;
public final String jvmOptions;
public final int maxConcurrency;
private ActorCreationOptions(Map<String, Double> resources, int maxReconstructions,
boolean useDirectCall, String jvmOptions, int maxConcurrency) {
super(resources);
super(resources, useDirectCall);
this.maxReconstructions = maxReconstructions;
this.useDirectCall = useDirectCall;
this.jvmOptions = jvmOptions;
this.maxConcurrency = maxConcurrency;
}
@@ -7,13 +7,21 @@ import java.util.Map;
* The options class for RayCall or ActorCreation.
*/
public abstract class BaseTaskOptions {
// DO NOT set this environment variable. It's only used for test purposes.
// Please use `setUseDirectCall` instead.
public static final boolean DEFAULT_USE_DIRECT_CALL = "1"
.equals(System.getenv("DEFAULT_USE_DIRECT_CALL"));
public final Map<String, Double> resources;
public final boolean useDirectCall;
public BaseTaskOptions() {
resources = new HashMap<>();
useDirectCall = DEFAULT_USE_DIRECT_CALL;
}
public BaseTaskOptions(Map<String, Double> resources) {
public BaseTaskOptions(Map<String, Double> resources, boolean useDirectCall) {
for (Map.Entry<String, Double> entry : resources.entrySet()) {
if (entry.getValue().compareTo(0.0) <= 0) {
throw new IllegalArgumentException(String.format("Resource capacity should be " +
@@ -21,6 +29,7 @@ public abstract class BaseTaskOptions {
}
}
this.resources = resources;
this.useDirectCall = useDirectCall;
}
}
@@ -8,8 +8,8 @@ import java.util.Map;
*/
public class CallOptions extends BaseTaskOptions {
private CallOptions(Map<String, Double> resources) {
super(resources);
private CallOptions(Map<String, Double> resources, boolean useDirectCall) {
super(resources, useDirectCall);
}
/**
@@ -18,14 +18,23 @@ public class CallOptions extends BaseTaskOptions {
public static class Builder {
private Map<String, Double> resources = new HashMap<>();
private boolean useDirectCall = DEFAULT_USE_DIRECT_CALL;
public Builder setResources(Map<String, Double> resources) {
this.resources = resources;
return this;
}
// Since direct call is not fully supported yet (see issue #5559),
// users are not allowed to set the option to true.
// TODO (kfstorm): uncomment when direct call is ready.
// public Builder setUseDirectCall(boolean useDirectCall) {
// this.useDirectCall = useDirectCall;
// return this;
// }
public CallOptions createCallOptions() {
return new CallOptions(resources);
return new CallOptions(resources, useDirectCall);
}
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ echo "Running tests under cluster mode."
ENABLE_MULTI_LANGUAGE_TESTS=1 run_testng java -cp $ROOT_DIR/../bazel-bin/java/all_tests_deploy.jar org.testng.TestNG -d /tmp/ray_java_test_output $ROOT_DIR/testng.xml
echo "Running tests under cluster mode with direct actor call turned on."
ENABLE_MULTI_LANGUAGE_TESTS=1 ACTOR_CREATION_OPTIONS_DEFAULT_USE_DIRECT_CALL=1 run_testng java -cp $ROOT_DIR/../bazel-bin/java/all_tests_deploy.jar org.testng.TestNG -d /tmp/ray_java_test_output $ROOT_DIR/testng.xml
ENABLE_MULTI_LANGUAGE_TESTS=1 DEFAULT_USE_DIRECT_CALL=1 run_testng java -cp $ROOT_DIR/../bazel-bin/java/all_tests_deploy.jar org.testng.TestNG -d /tmp/ray_java_test_output $ROOT_DIR/testng.xml
echo "Running tests under single-process mode."
# bazel test //java:all_tests --jvmopt="-Dray.run-mode=SINGLE_PROCESS" --test_output="errors" || single_exit_code=$?
@@ -1,23 +0,0 @@
package org.ray.api;
import java.util.List;
import org.ray.api.options.ActorCreationOptions;
import org.testng.IAlterSuiteListener;
import org.testng.xml.XmlGroups;
import org.testng.xml.XmlRun;
import org.testng.xml.XmlSuite;
public class RayAlterSuiteListener implements IAlterSuiteListener {
@Override
public void alter(List<XmlSuite> suites) {
XmlSuite suite = suites.get(0);
if (ActorCreationOptions.DEFAULT_USE_DIRECT_CALL) {
XmlGroups groups = new XmlGroups();
XmlRun run = new XmlRun();
run.onInclude("directCall");
groups.setRun(run);
suite.setGroups(groups);
}
}
}
@@ -13,7 +13,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = {"directCall"})
@Test
public class ActorConcurrentCallTest extends BaseTest {
@RayRemote
@@ -17,7 +17,7 @@ import org.ray.api.options.ActorCreationOptions;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = {"directCall"})
@Test
public class ActorReconstructionTest extends BaseTest {
@RayRemote()
@@ -16,7 +16,7 @@ import org.ray.api.id.UniqueId;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = {"directCall"})
@Test
public class ActorTest extends BaseTest {
@RayRemote
@@ -60,7 +60,7 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
Assert.assertEquals(res.get(), "[Python]py_func -> [Java]bytesEcho -> hello".getBytes());
}
@Test(groups = {"directCall"})
@Test
public void testCallingPythonActor() {
// Python worker doesn't support direct call yet.
TestUtils.skipTestIfDirectActorCallEnabled();
@@ -91,14 +91,14 @@ public class FailureTest extends BaseTest {
assertTaskFailedWithRayTaskException(Ray.call(FailureTest::badFunc));
}
@Test(groups = {"directCall"})
@Test
public void testActorCreationFailure() {
TestUtils.skipTestUnderSingleProcess();
RayActor<BadActor> actor = Ray.createActor(BadActor::new, true);
assertTaskFailedWithRayTaskException(Ray.call(BadActor::badMethod, actor));
}
@Test(groups = {"directCall"})
@Test
public void testActorTaskFailure() {
TestUtils.skipTestUnderSingleProcess();
RayActor<BadActor> actor = Ray.createActor(BadActor::new, false);
@@ -117,7 +117,7 @@ public class FailureTest extends BaseTest {
}
}
@Test(groups = {"directCall"})
@Test
public void testActorProcessDying() {
TestUtils.skipTestUnderSingleProcess();
// This test case hangs if the worker to worker connection is implemented with grpc.
@@ -10,7 +10,7 @@ import org.ray.api.exception.RayActorException;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = { "directCall" })
@Test
public class KillActorTest extends BaseTest {
@RayRemote
@@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = {"directCall"})
@Test
public class MultiThreadingTest extends BaseTest {
private static final Logger LOGGER = LoggerFactory.getLogger(MultiThreadingTest.class);
@@ -74,7 +74,7 @@ public class StressTest extends BaseTest {
}
}
@Test(enabled = false, groups = {"directCall"})
@Test(enabled = false)
public void testSubmittingManyTasksToOneActor() throws Exception {
TestUtils.skipTestUnderSingleProcess();
RayActor<Actor> actor = Ray.createActor(Actor::new);
-1
View File
@@ -8,7 +8,6 @@
</packages>
</test>
<listeners>
<listener class-name="org.ray.api.RayAlterSuiteListener" />
<listener class-name="org.ray.api.TestProgressListener" />
</listeners>
</suite>