examples: Added README files for all missing Examples (#11676) · grpc/grpc-java@9e86299

@@ -27,114 +27,32 @@ before trying out the examples.

27272828

- [Json serialization](src/main/java/io/grpc/examples/advanced)

292930-

- <details>

31-

<summary>Hedging</summary>

32-33-

The [hedging example](src/main/java/io/grpc/examples/hedging) demonstrates that enabling hedging

34-

can reduce tail latency. (Users should note that enabling hedging may introduce other overhead;

35-

and in some scenarios, such as when some server resource gets exhausted for a period of time and

36-

almost every RPC during that time has high latency or fails, hedging may make things worse.

37-

Setting a throttle in the service config is recommended to protect the server from too many

38-

inappropriate retry or hedging requests.)

39-40-

The server and the client in the example are basically the same as those in the

41-

[hello world](src/main/java/io/grpc/examples/helloworld) example, except that the server mimics a

42-

long tail of latency, and the client sends 2000 requests and can turn on and off hedging.

43-44-

To mimic the latency, the server randomly delays the RPC handling by 2 seconds at 10% chance, 5

45-

seconds at 5% chance, and 10 seconds at 1% chance.

46-47-

When running the client enabling the following hedging policy

48-49-

```json

50-

"hedgingPolicy": {

51-

"maxAttempts": 3,

52-

"hedgingDelay": "1s"

53-

}

54-

```

55-

Then the latency summary in the client log is like the following

56-57-

```text

58-

Total RPCs sent: 2,000. Total RPCs failed: 0

59-

[Hedging enabled]

60-

========================

61-

50% latency: 0ms

62-

90% latency: 6ms

63-

95% latency: 1,003ms

64-

99% latency: 2,002ms

65-

99.9% latency: 2,011ms

66-

Max latency: 5,272ms

67-

========================

68-

```

69-70-

See [the section below](#to-build-the-examples) for how to build and run the example. The

71-

executables for the server and the client are `hedging-hello-world-server` and

72-

`hedging-hello-world-client`.

73-74-

To disable hedging, set environment variable `DISABLE_HEDGING_IN_HEDGING_EXAMPLE=true` before

75-

running the client. That produces a latency summary in the client log like the following

76-77-

```text

78-

Total RPCs sent: 2,000. Total RPCs failed: 0

79-

[Hedging disabled]

80-

========================

81-

50% latency: 0ms

82-

90% latency: 2,002ms

83-

95% latency: 5,002ms

84-

99% latency: 10,004ms

85-

99.9% latency: 10,007ms

86-

Max latency: 10,007ms

87-

========================

88-

```

89-90-

</details>

91-92-

- <details>

93-

<summary>Retrying</summary>

94-95-

The [retrying example](src/main/java/io/grpc/examples/retrying) provides a HelloWorld gRPC client &

96-

server which demos the effect of client retry policy configured on the [ManagedChannel](

97-

../api/src/main/java/io/grpc/ManagedChannel.java) via [gRPC ServiceConfig](

98-

https://github.com/grpc/grpc/blob/master/doc/service_config.md). Retry policy implementation &

99-

configuration details are outlined in the [proposal](https://github.com/grpc/proposal/blob/master/A6-client-retries.md).

100-101-

This retrying example is very similar to the [hedging example](src/main/java/io/grpc/examples/hedging) in its setup.

102-

The [RetryingHelloWorldServer](src/main/java/io/grpc/examples/retrying/RetryingHelloWorldServer.java) responds with

103-

a status UNAVAILABLE error response to a specified percentage of requests to simulate server resource exhaustion and

104-

general flakiness. The [RetryingHelloWorldClient](src/main/java/io/grpc/examples/retrying/RetryingHelloWorldClient.java) makes

105-

a number of sequential requests to the server, several of which will be retried depending on the configured policy in

106-

[retrying_service_config.json](src/main/resources/io/grpc/examples/retrying/retrying_service_config.json). Although

107-

the requests are blocking unary calls for simplicity, these could easily be changed to future unary calls in order to

108-

test the result of request concurrency with retry policy enabled.

109-110-

One can experiment with the [RetryingHelloWorldServer](src/main/java/io/grpc/examples/retrying/RetryingHelloWorldServer.java)

111-

failure conditions to simulate server throttling, as well as alter policy values in the [retrying_service_config.json](

112-

src/main/resources/io/grpc/examples/retrying/retrying_service_config.json) to see their effects. To disable retrying

113-

entirely, set environment variable `DISABLE_RETRYING_IN_RETRYING_EXAMPLE=true` before running the client.

114-

Disabling the retry policy should produce many more failed gRPC calls as seen in the output log.

115-116-

See [the section below](#to-build-the-examples) for how to build and run the example. The

117-

executables for the server and the client are `retrying-hello-world-server` and

118-

`retrying-hello-world-client`.

119-120-

</details>

121-122-

- <details>

123-

<summary>Health Service</summary>

124-125-

The [health service example](src/main/java/io/grpc/examples/healthservice)

126-

provides a HelloWorld gRPC server that doesn't like short names along with a

127-

health service. It also provides a client application which makes HelloWorld

128-

calls and checks the health status.

129-130-

The client application also shows how the round robin load balancer can

131-

utilize the health status to avoid making calls to a service that is

132-

not actively serving.

133-

</details>

30+

- [Hedging example](src/main/java/io/grpc/examples/hedging)

1343132+

- [Retrying example](src/main/java/io/grpc/examples/retrying)

33+34+

- [Health Service example](src/main/java/io/grpc/examples/healthservice)

1353513636

- [Keep Alive](src/main/java/io/grpc/examples/keepalive)

1373738+

- [Cancellation](src/main/java/io/grpc/examples/cancellation)

39+40+

- [Custom Load Balance](src/main/java/io/grpc/examples/customloadbalance)

41+42+

- [Deadline](src/main/java/io/grpc/examples/deadline)

43+44+

- [Error Details](src/main/java/io/grpc/examples/errordetails)

45+46+

- [GRPC Proxy](src/main/java/io/grpc/examples/grpcproxy)

47+48+

- [Load Balance](src/main/java/io/grpc/examples/loadbalance)

49+50+

- [Multiplex](src/main/java/io/grpc/examples/multiplex)

51+52+

- [Name Resolve](src/main/java/io/grpc/examples/nameresolve)

53+54+

- [Pre-Serialized Messages](src/main/java/io/grpc/examples/preserialized)

55+13856

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

1395714058

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).**