-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serve] Define BackendConfig protobuf and adapt it in Java #17201
Changes from 17 commits
6b71de0
18e89bd
32829f3
380b0cc
55de40a
cbd548c
f575b51
1f18d2f
c7e1919
4354294
a5ef9d3
4a4d5c8
062cbd0
6e513a4
f69adc2
abc778b
c74adde
45a0ef7
8fe6135
caf80c6
9c8f117
044bdd7
aa59cd5
5b002ed
f9f935b
a05a85b
56a9089
f22e8be
1cec6f6
127eadd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.ray.serve.serializer; | ||
|
||
import com.caucho.hessian.io.Hessian2Input; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we use Hessian as the serialization format here? If it's expected to be used cross language we should use messagepack, if not is Hessian a standard serialization protocol for Java? If so does Ray core use it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hesssian's compatibility is better when adding new properties to the object. But MsgPack performance better in cross-language scenarios. I think MsgPack is the right choice here. |
||
import com.caucho.hessian.io.Hessian2Output; | ||
import com.caucho.hessian.io.SerializerFactory; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
public class Hessian2Seserializer { | ||
|
||
private static SerializerFactory DEFAULT_FACTORY = new SerializerFactory(); | ||
|
||
public static byte[] encode(Object data) throws IOException { | ||
return encode(data, DEFAULT_FACTORY); | ||
} | ||
|
||
public static byte[] encode(Object data, SerializerFactory serializerFactory) throws IOException { | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
Hessian2Output hessian2Output = new Hessian2Output(byteArrayOutputStream); | ||
hessian2Output.setSerializerFactory(serializerFactory); | ||
hessian2Output.writeObject(data); | ||
hessian2Output.flush(); | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
|
||
public static Object decode(byte[] data) throws IOException { | ||
return decode(data, DEFAULT_FACTORY); | ||
} | ||
|
||
public static Object decode(byte[] data, SerializerFactory serializerFactory) throws IOException { | ||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data); | ||
Hessian2Input hessian2Input = new Hessian2Input(byteArrayInputStream); | ||
hessian2Input.setSerializerFactory(serializerFactory); | ||
return hessian2Input.readObject(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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.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(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain the TODO?