mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 13:37:39 +08:00
[Java] Simplify Java worker configuration (#2938)
## What do these changes do? Previously, Java worker configuration is complicated, because it requires setting environment variables as well as command-line arguments. This PR aims to simplify Java worker's configuration. 1) Configuration management is now migrated to [lightbend config](https://github.com/lightbend/config), thus doesn't require setting environment variables. 2) Many unused config items are removed. 3) Provide a simple `example.conf` file, so users can get started quickly. 4) All possible options and their default values are declared and documented in `ray.default.conf` file. This PR also simplifies and refines the following code: 1) The process of `Ray.init()`. 2) `RunManager`. 3) `WorkerContext`. ### How to use this configuration? 1. Copy `example.conf` into your classpath and rename it to `ray.conf`. 2. Modify/add your configuration items. The all items are declared in `ray.default.conf`. 3. You can also set the items in java system prosperities. Note: configuration is read in this priority: System properties > `ray.conf` > `ray.default.conf` ## Related issue number N/A
This commit is contained in:
@@ -14,4 +14,11 @@
|
||||
<description>java api for ray</description>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.ray.api;
|
||||
|
||||
import java.util.List;
|
||||
import org.ray.api.id.UniqueId;
|
||||
import org.ray.api.runtime.DefaultRayRuntimeFactory;
|
||||
import org.ray.api.runtime.RayRuntime;
|
||||
import org.ray.api.runtime.RayRuntimeFactory;
|
||||
|
||||
@@ -17,7 +16,14 @@ public final class Ray extends RayCall {
|
||||
* Initialize Ray runtime with the default runtime implementation.
|
||||
*/
|
||||
public static void init() {
|
||||
init(new DefaultRayRuntimeFactory());
|
||||
try {
|
||||
Class clz = Class.forName("org.ray.runtime.DefaultRayRuntimeFactory");
|
||||
RayRuntimeFactory factory = (RayRuntimeFactory) clz.newInstance();
|
||||
init(factory);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to initialize Ray runtime.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.ray.api.runtime;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* The default Ray runtime factory. It produces an instance of AbstractRayRuntime.
|
||||
*/
|
||||
public class DefaultRayRuntimeFactory implements RayRuntimeFactory {
|
||||
|
||||
@Override
|
||||
public RayRuntime createRayRuntime() {
|
||||
try {
|
||||
Method m = Class.forName("org.ray.runtime.AbstractRayRuntime").getDeclaredMethod("init");
|
||||
m.setAccessible(true);
|
||||
RayRuntime runtime = (RayRuntime) m.invoke(null);
|
||||
m.setAccessible(false);
|
||||
return runtime;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to initialize ray runtime", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user