Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to GRPC

KMKLabs
November 02, 2018

Introduction to GRPC

On this techtalk, the speaker presented the basic knowledge of open-sourced Remote Procedure Call Framework invented and developed by Google for more than ten years as Client-Server communication framework, GRPC. Beside that, this techtalk also mentioned several benefits of GRPC compared with existing popular client-server communication framework, HTTP/json (REST API)

KMKLabs

November 02, 2018
Tweet

More Decks by KMKLabs

Other Decks in Programming

Transcript

  1. What is gRPC? gRPC stands for gRPC Remote Procedure Calls.

    Open sourced version of Stubby RPC used in Google. https://github.com/grpc/grpc/blob/master/doc/g_stands_for.md
  2. Why gRPC? • strict service contracts using Protobuf • data

    serialization • efficient network communication • Support many common languages: C++, Java, Python, Ruby, Node.js, C#, Go, PHP, Objective-C TL;DR gRPC replace HTTP+JSON.
  3. What makes gRPC faster • More efficient data encoding data

    is kept in binary (in client memory and on the wire) • HTTP/2 multiplexed requests over a single connection
  4. Deadline instead of Timeout1 How long the client is willing

    to wait for an answer. When deadline reached RPC will fail with DEADLINE_EXCEEDED status code response = blockingStub.withDeadlineAfter( deadlineMs, TimeUnit.MILLISECONDS) .sayHello(request);
  5. gRPC Deadline1 Deadline are automatically propagated, and can be accessed

    by the receiver Context context = Context.current(); context.getDeadline().isExpired(); context.getDealine().timeRemaining( MILLISECONDS); context.getDeadline().runOnExpiration(() -> { cleaupResources(); logger.info(“Deadline exceded” ); })
  6. gRPC Cancellation When the caller is not interested in the

    result any more… RPC will fail with CANCELLED status code. Server (receiver) access cancellation status by: streamObserver.isCancelled(); streamObserver.setOnCancelHandler(() -> { cleaupResources(); logger.info(“Call canceled by client.” ); })
  7. Existing GGB gRPC Implementation PROS CONS Service Contract Manageable contract

    version No status code for each rpc in protobuf Connection Efficiency Using single TCP connection Infrequently request traffic Logging Can do it in gRPC interceptor Missing readability of HTTP request traffic
  8. Other things about gRPC: - Channel https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-ap i.md - Reflection

    Server https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflectio n-tutorial.md - Client cancel StreamObserver<HelloResponse> response = blockingStub.sayHello(request); ((ClientCallStreamObserver) response.).cancel()