Skip to content

API Deadlines

Regunath B edited this page Aug 30, 2018 · 4 revisions

gRPC Deadlines

gRPC inherently has support for specifying Deadlines. This is done on the client stub as described here : gRPC and Deadlines

GJEX extends this support to the server side by providing ability to specify and honor Deadlines for gRPC APIs.

API Deadlines

API level Deadlines can be defined for gRPC methods like below:

@Api(deadline = 500)
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
}

or alternatively configured via a config value like @Api(deadlineConfig = "Api.sayhello.deadline") where the config parameter is defined in the service's YAML configuration file.

The annotation gets translated to a Deadline on the gRPC execution Context and this is carried into all @ConcurrentTask() methods' result evaluation i.e. Future.get(timeout). The timeout for Future.get(timeout) is derived from remaining time in the Deadline.

The RPC call fails with Status.DEADLINE_EXCEEDED when the deadline is breached.

Note that this is independent of timeout at the ConcurrentTask. The RPC can therefore time out if the shorter of these two occur:

  • Deadline as specified by @Api(deadline = 500) is exceeded - (returns a Status.DEADLINE_EXCEEDED error)
  • Timeout as specified by @ConcurrentTask(timeout = 300) - (returns a Status.INTERNAL error stating mandatory task failed)

See client side responses below from each of the above two scenarios:

RPC failed: Status{code=DEADLINE_EXCEEDED, description=Deadline exceeded in server execution., cause=null}
RPC failed: Status{code=INTERNAL, description=Error executing mandatory Task : tracedMethod4 timed-out and no fallback available., cause=null}

Caveat

Deadline support is effective only if API implementations use the @ConcurrentTask() methods for invoking network or expensive calls. This will not work if the API implementation invokes code serially i.e continues execution in the same thread.