Skip to content

Commit

Permalink
Fix GRPC address assignment to localhost by default (#3083)
Browse files Browse the repository at this point in the history
* Fix GRPC address assignment to localhost by default

* Update documentation

* fix typos
  • Loading branch information
namannandan authored Apr 11, 2024
1 parent cdba0fd commit aab9950
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docker/config.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
inference_address=http://0.0.0.0:8080
management_address=http://0.0.0.0:8081
metrics_address=http://0.0.0.0:8082
grpc_inference_address=0.0.0.0
grpc_management_address=0.0.0.0
number_of_netty_threads=32
job_queue_size=1000
model_store=/home/model-server/model-store
Expand Down
9 changes: 7 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ inference_address=https://127.0.0.1:8443
inference_address=https://172.16.1.10:8080
```

### Configure TorchServe gRPC listening ports
The inference gRPC API is listening on port 7070, and the management gRPC API is listening on port 7071 by default.
### Configure TorchServe gRPC listening addresses and ports
The inference gRPC API is listening on port 7070, and the management gRPC API is listening on port 7071 on localhost by default.

To configure different addresses use following properties

* `grpc_inference_address`: Inference gRPC API IP address. Default: 127.0.0.1
* `grpc_management_address`: Management gRPC API IP address. Default: 127.0.0.1

To configure different ports use following properties

Expand Down
4 changes: 2 additions & 2 deletions docs/grpc_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ TorchServe provides following gRPCs apis
- **DescribeModel** : Get detail runtime status of default version of a model
- **SetDefault** : Set any registered version of a model as default version

By default, TorchServe listens on port 7070 for the gRPC Inference API and 7071 for the gRPC Management API.
To configure gRPC APIs on different ports refer [configuration documentation](configuration.md)
By default, TorchServe listens on port 7070 for the gRPC Inference API and 7071 for the gRPC Management API on localhost.
To configure gRPC APIs on different addresses and ports refer [configuration documentation](configuration.md)

## Python client example for gRPC APIs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.InetSocketAddress;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -447,7 +448,10 @@ public void startGRPCServers() throws IOException {
private Server startGRPCServer(ConnectorType connectorType) throws IOException {

ServerBuilder<?> s =
NettyServerBuilder.forPort(configManager.getGRPCPort(connectorType))
NettyServerBuilder.forAddress(
new InetSocketAddress(
configManager.getGRPCAddress(connectorType),
configManager.getGRPCPort(connectorType)))
.maxInboundMessageSize(configManager.getMaxRequestSize())
.addService(
ServerInterceptors.intercept(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public final class ConfigManager {
private static final String TS_ALLOWED_URLS = "allowed_urls";
private static final String TS_INSTALL_PY_DEP_PER_MODEL = "install_py_dep_per_model";
private static final String TS_ENABLE_METRICS_API = "enable_metrics_api";
private static final String TS_GRPC_INFERENCE_ADDRESS = "grpc_inference_address";
private static final String TS_GRPC_MANAGEMENT_ADDRESS = "grpc_management_address";
private static final String TS_GRPC_INFERENCE_PORT = "grpc_inference_port";
private static final String TS_GRPC_MANAGEMENT_PORT = "grpc_management_port";
private static final String TS_ENABLE_GRPC_SSL = "enable_grpc_ssl";
Expand Down Expand Up @@ -357,12 +359,27 @@ public Connector getListener(ConnectorType connectorType) {
return Connector.parse(binding, connectorType);
}

public int getGRPCPort(ConnectorType connectorType) {
public InetAddress getGRPCAddress(ConnectorType connectorType)
throws UnknownHostException, IllegalArgumentException {
if (connectorType == ConnectorType.MANAGEMENT_CONNECTOR) {
return InetAddress.getByName(prop.getProperty(TS_GRPC_MANAGEMENT_ADDRESS, "127.0.0.1"));
} else if (connectorType == ConnectorType.INFERENCE_CONNECTOR) {
return InetAddress.getByName(prop.getProperty(TS_GRPC_INFERENCE_ADDRESS, "127.0.0.1"));
} else {
throw new IllegalArgumentException(
"Connector type not supported by gRPC: " + connectorType);
}
}

public int getGRPCPort(ConnectorType connectorType) throws IllegalArgumentException {
String port;
if (connectorType == ConnectorType.MANAGEMENT_CONNECTOR) {
port = prop.getProperty(TS_GRPC_MANAGEMENT_PORT, "7071");
} else {
} else if (connectorType == ConnectorType.INFERENCE_CONNECTOR) {
port = prop.getProperty(TS_GRPC_INFERENCE_PORT, "7070");
} else {
throw new IllegalArgumentException(
"Connector type not supported by gRPC: " + connectorType);
}
return Integer.parseInt(port);
}
Expand Down

0 comments on commit aab9950

Please sign in to comment.