Skip to content

Commit

Permalink
Optimize and update some code
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliguov5 committed Feb 8, 2021
1 parent f825e97 commit 2ed6974
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,39 @@ public static synchronized ServerOptions instance() {
"0.0.0.0"
);

public static final ConfigOption<Integer> RPC_CLIENT_CONNECTION_TIMEOUT =
public static final ConfigOption<Integer> RPC_SERVER_TIMEOUT =
new ConfigOption<>(
"rpc.server_timeout",
"The timeout(in seconds) of rpc server execution.",
rangeInt(1, Integer.MAX_VALUE),
30
);

public static final ConfigOption<Integer> CLIENT_CONNECTION_TIMEOUT =
new ConfigOption<>(
"rpc.client_connection_timeout",
"The timeout(in seconds) of rpc client connect to rpc " +
"server.",
rangeInt(1, Integer.MAX_VALUE),
8000
20
);

public static final ConfigOption<Integer> CLIENT_RECONNECTION_TIMEOUT =
new ConfigOption<>(
"rpc.client_reconnection_timeout",
"The timeout(in seconds) of rpc client connect to rpc " +
"server.",
rangeInt(1, Integer.MAX_VALUE),
20
);

public static final ConfigOption<Integer> RPC_CLIENT_READ_TIMEOUT =
public static final ConfigOption<Integer> CLIENT_READ_TIMEOUT =
new ConfigOption<>(
"rpc.client_read_timeout",
"The timeout(in seconds) of rpc client read from rpc " +
"server.",
rangeInt(1, Integer.MAX_VALUE),
8000
40
);

public static final ConfigOption<Integer> RPC_CLIENT_RETRIES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public <T> void addConsumerConfig(Class<T> clazz, HugeConfig conf) {
.setInterfaceId(clazz.getName())
.setProtocol(conf.get(ServerOptions.RPC_PROTOCOL))
.setDirectUrl(conf.get(ServerOptions.AUTH_REMOTE_URL))
.setTimeout(conf.get(ServerOptions.RPC_CLIENT_READ_TIMEOUT))
.setTimeout(conf.get(ServerOptions.CLIENT_READ_TIMEOUT)*1000)
.setConnectTimeout(conf.get(
ServerOptions.RPC_CLIENT_CONNECTION_TIMEOUT))
ServerOptions.CLIENT_CONNECTION_TIMEOUT)*1000)
.setReconnectPeriod(conf.get(
ServerOptions.CLIENT_RECONNECTION_TIMEOUT) *1000)
.setRetries(conf.get(ServerOptions.RPC_CLIENT_RETRIES))
.setLoadBalancer(conf.get(
ServerOptions.RPC_CLIENT_LOAD_BALANCER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SofaRpcServer {

private Map<String, ProviderConfig> providerConfigs;
private ServerConfig serverConfig;
private final int rpcServerTimeout;

static {
if (RpcConfigs.getOrDefaultValue(RpcOptions.JVM_SHUTDOWN_HOOK, true)) {
Expand All @@ -54,6 +55,7 @@ public SofaRpcServer(HugeConfig conf, RpcProviderConfig providerConfig) {
.setHost(conf.get(ServerOptions.RPC_SERVER_HOST))
.setDaemon(false);
this.providerConfigs = providerConfig.providerConfigs();
this.rpcServerTimeout = conf.get(ServerOptions.RPC_SERVER_TIMEOUT)*1000;
}

public void exportAll() {
Expand All @@ -63,6 +65,7 @@ public void exportAll() {
}
for (ProviderConfig providerConfig : this.providerConfigs.values()) {
providerConfig.setServer(this.serverConfig);
providerConfig.setTimeout(this.rpcServerTimeout);
providerConfig.export();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ server.role=master
#auth.remote_url=10.103.168.25:8899,10.103.168.25:8898,10.103.168.25:8897
rpc.server_port=8899
rpc.server_host=127.0.0.1
rpc.client_connection_timeout=8000
rpc.client_read_timeout=8000
rpc.server_timeout=30
rpc.client_connection_timeout=20
rpc.client_reconnection_timeout=20
rpc.client_read_timeout=40
rpc.client_retries=3
rpc.client_load_balancer=consistentHash
rpc.protocol=bolt

0 comments on commit 2ed6974

Please sign in to comment.