Skip to content

Commit

Permalink
adds retrying example details in README, revert change to gradle wrap…
Browse files Browse the repository at this point in the history
…per properties
  • Loading branch information
alexanderscott committed Jun 10, 2020
1 parent d85e6f2 commit 709dcd1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
30 changes: 30 additions & 0 deletions examples/README.md
Expand Up @@ -87,6 +87,36 @@ before trying out the examples.

</details>

- <details>
<summary>Retrying</summary>

The [retrying example](src/main/java/io/grpc/examples/retrying) provides a HelloWorld GRPC client &
server which demos the effect of client retry policy configured on the [ManagedChannel](
../api/src/main/java/io/grpc/ManagedChannel.java) via [GRPC ServiceConfig](
../core/src/main/java/io/grpc/internal/ManagedChannelServiceConfig.java). Retry policy implementation &
configuration details are outlined in the [proposal](https://github.com/grpc/proposal/blob/master/A6-client-retries.md).

This retrying example is very similar to the [hedging example](src/main/java/io/grpc/examples/hedging) in its setup.
The [RetryingHelloWorldServer](src/main/java/io/grpc/examples/retrying/RetryingHelloWorldServer.java) responds with
a status UNAVAILABLE error response to a specified percentage of requests to simulate server resource exhaustion and
general flakiness. The [RetryingHelloWorldClient](src/main/java/io/grpc/examples/retrying/RetryingHelloWorldClient.java) makes
a number of sequential requests to the server, several of which will be retried depending on the configured policy in
[retrying_service_config.json](src/main/resources/io/grpc/examples/retrying/retrying_service_config.json). Although
the requests are blocking unary calls for simplicity, these could easily be changed to future unary calls in order to
test the result of request concurrency with retry policy enabled.

One can experiment with the [RetryingHelloWorldServer](src/main/java/io/grpc/examples/retrying/RetryingHelloWorldServer.java)
failure conditions to simulate server throttling, as well as alter policy values in the [retrying_service_config.json](
src/main/resources/io/grpc/examples/retrying/retrying_service_config.json) to see their effects. To disable retrying
entirely, set environment variable `DISABLE_RETRYING_IN_RETRYING_EXAMPLE=true` before running the client.
Disabling the retry policy should produce many more failed GRPC calls as seen in the output log.

See [the section below](#to-build-the-examples) for how to build and run the example. The
executables for the server and the client are `retrying-hello-world-server` and
`retrying-hello-world-client`.

</details>

### <a name="to-build-the-examples"></a> To build the examples

1. **[Install gRPC Java library SNAPSHOT locally, including code generation plugin](../COMPILING.md) (Only need this step for non-released versions, e.g. master HEAD).**
Expand Down
5 changes: 2 additions & 3 deletions examples/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
#Tue Jun 02 23:49:09 PDT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Expand Up @@ -39,7 +39,7 @@
* A client that requests a greeting from the {@link RetryingHelloWorldServer} with a retrying policy.
*/
public class RetryingHelloWorldClient {
static final String ENV_DISABLE_RETRIES = "DISABLE_RETRIES_IN_RETRIES_EXAMPLE";
static final String ENV_DISABLE_RETRYING = "DISABLE_RETRYING_IN_RETRYING_EXAMPLE";

private static final Logger logger = Logger.getLogger(RetryingHelloWorldClient.class.getName());

Expand Down Expand Up @@ -117,17 +117,17 @@ private void printSummary() {
logger.log(
Level.INFO,
"Retrying enabled. To disable retries, run the client with environment variable {0}=true.",
ENV_DISABLE_RETRIES);
ENV_DISABLE_RETRYING);
} else {
logger.log(
Level.INFO,
"Retrying disabled. To enable retries, unset environment variable {0} and then run the client.",
ENV_DISABLE_RETRIES);
ENV_DISABLE_RETRYING);
}
}

public static void main(String[] args) throws Exception {
boolean enableRetries = !Boolean.parseBoolean(System.getenv(ENV_DISABLE_RETRIES));
boolean enableRetries = !Boolean.parseBoolean(System.getenv(ENV_DISABLE_RETRYING));
final RetryingHelloWorldClient client = new RetryingHelloWorldClient("localhost", 50051, enableRetries);
ForkJoinPool executor = new ForkJoinPool();

Expand Down

0 comments on commit 709dcd1

Please sign in to comment.