forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serve] Define BackendConfig protobuf and adapt it in Java (ray-proje…
- Loading branch information
1 parent
ac9a1a2
commit 12bd904
Showing
14 changed files
with
223 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
java/serve/src/main/java/io/ray/serve/util/BackendConfigUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.ray.serve.util; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.Lists; | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import io.ray.runtime.serializer.MessagePackSerializer; | ||
import io.ray.serve.RayServeException; | ||
import io.ray.serve.generated.BackendConfig; | ||
import io.ray.serve.generated.BackendLanguage; | ||
|
||
public class BackendConfigUtil { | ||
|
||
public static BackendConfig parseFrom(byte[] backendConfigBytes) | ||
throws InvalidProtocolBufferException { | ||
|
||
// Parse BackendConfig from byte[]. | ||
BackendConfig inputBackendConfig = BackendConfig.parseFrom(backendConfigBytes); | ||
if (inputBackendConfig == null) { | ||
return null; | ||
} | ||
|
||
// Set default values. | ||
BackendConfig.Builder builder = BackendConfig.newBuilder(); | ||
|
||
if (inputBackendConfig.getNumReplicas() == 0) { | ||
builder.setNumReplicas(1); | ||
} else { | ||
builder.setNumReplicas(inputBackendConfig.getNumReplicas()); | ||
} | ||
|
||
Preconditions.checkArgument( | ||
inputBackendConfig.getMaxConcurrentQueries() >= 0, "max_concurrent_queries must be >= 0"); | ||
if (inputBackendConfig.getMaxConcurrentQueries() == 0) { | ||
builder.setMaxConcurrentQueries(100); | ||
} else { | ||
builder.setMaxConcurrentQueries(inputBackendConfig.getMaxConcurrentQueries()); | ||
} | ||
|
||
builder.setUserConfig(inputBackendConfig.getUserConfig()); | ||
|
||
if (inputBackendConfig.getExperimentalGracefulShutdownWaitLoopS() == 0) { | ||
builder.setExperimentalGracefulShutdownWaitLoopS(2); | ||
} else { | ||
builder.setExperimentalGracefulShutdownWaitLoopS( | ||
inputBackendConfig.getExperimentalGracefulShutdownWaitLoopS()); | ||
} | ||
|
||
if (inputBackendConfig.getExperimentalGracefulShutdownTimeoutS() == 0) { | ||
builder.setExperimentalGracefulShutdownTimeoutS(20); | ||
} else { | ||
builder.setExperimentalGracefulShutdownTimeoutS( | ||
inputBackendConfig.getExperimentalGracefulShutdownTimeoutS()); | ||
} | ||
|
||
builder.setIsCrossLanguage(inputBackendConfig.getIsCrossLanguage()); | ||
|
||
if (inputBackendConfig.getBackendLanguage() == BackendLanguage.UNRECOGNIZED) { | ||
throw new RayServeException( | ||
LogUtil.format( | ||
"Unrecognized backend language {}. Backend language must be in {}.", | ||
inputBackendConfig.getBackendLanguageValue(), | ||
Lists.newArrayList(BackendLanguage.values()))); | ||
} else { | ||
builder.setBackendLanguage(inputBackendConfig.getBackendLanguage()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
public static Object getUserConfig(BackendConfig backendConfig) { | ||
if (backendConfig.getUserConfig() == null || backendConfig.getUserConfig().size() == 0) { | ||
return null; | ||
} | ||
return MessagePackSerializer.decode(backendConfig.getUserConfig().toByteArray(), Object.class); | ||
} | ||
} |
Oops, something went wrong.