Updating zero capacity resource semantics (#4555)

This commit is contained in:
Romil Bhardwaj
2019-04-12 16:53:57 -07:00
committed by Robert Nishihara
parent bb207a205b
commit 0f42f87ebc
17 changed files with 248 additions and 193 deletions
@@ -7,13 +7,19 @@ import java.util.Map;
* The options class for RayCall or ActorCreation.
*/
public abstract class BaseTaskOptions {
public Map<String, Double> resources;
public final Map<String, Double> resources;
public BaseTaskOptions() {
resources = new HashMap<>();
}
public BaseTaskOptions(Map<String, Double> resources) {
for (Map.Entry<String, Double> entry : resources.entrySet()) {
if (entry.getValue().compareTo(0.0) <= 0) {
throw new IllegalArgumentException(String.format("Resource capacity should be " +
"positive, but got resource %s = %f.", entry.getKey(), entry.getValue()));
}
}
this.resources = resources;
}
+1 -1
View File
@@ -14,7 +14,7 @@ ray {
run-mode = CLUSTER
// Available resources on this node.
resources: "CPU:4,GPU:0"
resources: "CPU:4"
// The address of the redis server to connect, in format `ip:port`.
// If not provided, Ray processes will be started locally, including
@@ -32,7 +32,6 @@ import org.ray.runtime.raylet.RayletClient;
import org.ray.runtime.task.ArgumentsBuilder;
import org.ray.runtime.task.TaskLanguage;
import org.ray.runtime.task.TaskSpec;
import org.ray.runtime.util.ResourceUtil;
import org.ray.runtime.util.UniqueIdUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -357,11 +356,6 @@ public abstract class AbstractRayRuntime implements RayRuntime {
resources = new HashMap<>(taskOptions.resources);
}
if (!resources.containsKey(ResourceUtil.CPU_LITERAL)
&& !resources.containsKey(ResourceUtil.CPU_LITERAL.toLowerCase())) {
resources.put(ResourceUtil.CPU_LITERAL, 0.0);
}
int maxActorReconstruction = 0;
if (taskOptions instanceof ActorCreationOptions) {
maxActorReconstruction = ((ActorCreationOptions) taskOptions).maxReconstructions;
@@ -104,10 +104,6 @@ public class RayConfig {
+ "setting it to the number of CPU cores: {}", numCpu);
resources.put("CPU", numCpu * 1.0);
}
if (!resources.containsKey("GPU")) {
LOGGER.warn("No GPU resource is set in configuration, setting it to 0");
resources.put("GPU", 0.0);
}
}
// Driver id.
String driverId = config.getString("ray.driver.id");
+1 -1
View File
@@ -1,5 +1,5 @@
ray {
run-mode = SINGLE_PROCESS
resources = "CPU:4,GPU:0"
resources = "CPU:4"
redis.address = ""
}
@@ -46,22 +46,30 @@ public class ResourcesManagementTest extends BaseTest {
@Test
public void testMethods() {
TestUtils.skipTestUnderSingleProcess();
CallOptions callOptions1 = new CallOptions(ImmutableMap.of("CPU", 4.0, "GPU", 0.0));
CallOptions callOptions1 = new CallOptions(ImmutableMap.of("CPU", 4.0));
// This is a case that can satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
RayObject<Integer> result1 = Ray.call(ResourcesManagementTest::echo, 100, callOptions1);
Assert.assertEquals(100, (int) result1.get());
CallOptions callOptions2 = new CallOptions(ImmutableMap.of("CPU", 4.0, "GPU", 2.0));
CallOptions callOptions2 = new CallOptions(ImmutableMap.of("CPU", 4.0));
// This is a case that can't satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
final RayObject<Integer> result2 = Ray.call(ResourcesManagementTest::echo, 200, callOptions2);
WaitResult<Integer> waitResult = Ray.wait(ImmutableList.of(result2), 1, 1000);
Assert.assertEquals(0, waitResult.getReady().size());
Assert.assertEquals(1, waitResult.getUnready().size());
Assert.assertEquals(1, waitResult.getReady().size());
Assert.assertEquals(0, waitResult.getUnready().size());
try {
CallOptions callOptions3 = new CallOptions(ImmutableMap.of("CPU", 0.0));
Assert.fail();
} catch (RuntimeException e) {
// We should receive a RuntimeException indicates that we should not
// pass a zero capacity resource.
}
}
@Test
@@ -69,7 +77,7 @@ public class ResourcesManagementTest extends BaseTest {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions actorCreationOptions1 =
new ActorCreationOptions(ImmutableMap.of("CPU", 2.0, "GPU", 0.0));
new ActorCreationOptions(ImmutableMap.of("CPU", 2.0));
// This is a case that can satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
@@ -80,7 +88,7 @@ public class ResourcesManagementTest extends BaseTest {
// This is a case that can't satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
ActorCreationOptions actorCreationOptions2 =
new ActorCreationOptions(ImmutableMap.of("CPU", 8.0, "GPU", 0.0));
new ActorCreationOptions(ImmutableMap.of("CPU", 8.0));
RayActor<ResourcesManagementTest.Echo> echo2 =
Ray.createActor(Echo::new, actorCreationOptions2);