Slide 1

Slide 1 text

A high performance, open-source, universal RPC framework Mete Atamel Developer Advocate for Google Cloud @meteatamel

Slide 2

Slide 2 text

Google Cloud Platform Agenda Introduction RPC, motivation for gRPC gRPC Basics What is gRPC? Design goals Some me the code! HelloWorld gRPC sample and demo gRPC Benefits HTTP/2, Protocol Buffers, multi-language support, connection options Some me more code! Streaming gRPC sample and demo @meteatamel

Slide 3

Slide 3 text

Google Cloud Platform Introduction @meteatamel

Slide 4

Slide 4 text

Google Cloud Platform class GreeterService { String greeating(String text); } class GreeterClient { var greeter = new GreeterService(); greeter.greeting(“World”); } Regular Procedure Call @meteatamel

Slide 5

Slide 5 text

Google Cloud Platform In distributed computing a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in another address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction That is, the programmer writes essentially the same code whether the subroutine is local to the executing program, or remote* Remote Procedure Call (RPC) *Wikipedia @meteatamel

Slide 6

Slide 6 text

Google Cloud Platform GreeterClient RPC GreetService @meteatamel

Slide 7

Slide 7 text

Google Cloud Platform How do clients call the service? How does the server expose the service? How does the data serialized/deserialized over the wire? XML, JSON, Binary? What is the nature of the connection? Request/reply, streaming? What about authentication? RPC Questions @meteatamel

Slide 8

Slide 8 text

Google Cloud Platform 1. Build your own custom RPC framework ++ Exactly how you like it: I did this with Adobe Flex Data Services! -- You need to answer the questions earlier & code 2. Use gRPC: A high performance, open-source universal RPC framework ++ Many of the questions already answered & implemented by community -- You need to buy into gRPC style, gRPC generated code Choices @meteatamel

Slide 9

Slide 9 text

Google Cloud Platform For simple services, HTTP REST is probably enough → HTTP verbs (GET, POST, PUT, DELETE etc.) are rich enough → REST semantics are well understood For more complex services where efficiency is important, RPC can help → Domain specific: imagine a bank transfer scenario → More strongly typed experience via stubs → Efficiency with HTTP/2, Protocol Buffer Why not REST? @meteatamel

Slide 10

Slide 10 text

Google Cloud Platform Basics @meteatamel

Slide 11

Slide 11 text

Google Cloud Platform Stands for gRPC Remote Procedure Calls A high performance, open source, general purpose standards-based, feature-rich RPC framework Open sourced version of Stubby RPC used in Google Actively developed and production-ready, current version is 1.3.4 What is gRPC? @meteatamel

Slide 12

Slide 12 text

Google Cloud Platform Services not Objects, Messages not References Coverage & Simplicity Free & Open Interoperability & Reach General Purpose & Performant Layered Payload Agnostic Streaming Blocking & Non-Blocking Cancellation & Timeout Motivation and Design Principles grpc.io/blog/principles @meteatamel

Slide 13

Slide 13 text

Google Cloud Platform A high level service definition to describe the API using Protocol Buffers Client and server code generated from the service definition in 10+ languages Efficiency in serialization with Protocol Buffers and connection with HTTP/2 Connection options: Unary, server-side streaming, client-side streaming, bi-directional streaming Authentication options: SSL/TLS, token based authentication How does it work? @meteatamel

Slide 14

Slide 14 text

Google Cloud Platform At the high level Java Service gRPC Service Python Service gRPC Stub gRPC Service gRPC Service GoLang Service C++ Service gRPC Stub gRPC Stub gRPC Service gRPC Stub gRPC Stub @meteatamel

Slide 15

Slide 15 text

Google Cloud Platform Show me the code: 4 easy steps @meteatamel

Slide 16

Slide 16 text

Google Cloud Platform service GreetingService { rpc greeting (HelloRequest) returns (HelloResponse) {} } Step 1: Create greeter.proto message HelloRequest { string name = 1; } message HelloResponse { string message = 1; } @meteatamel

Slide 17

Slide 17 text

Google Cloud Platform Generate client and server code to extend from using proto3 compiler For Java, there is protobuf-maven-plugin for Maven and protobuf-gradle-plugin for Gradl to help For .NET, Grpc.Tools.1.0.1 NuGet package has protoc.exe Step 2: Generate client and server stubs @meteatamel

Slide 18

Slide 18 text

Google Cloud Platform Create a service implementation extending from generated base class Create a server with port and using the service implementation Start the server Step 3: Create server @meteatamel

Slide 19

Slide 19 text

Google Cloud Platform Create a channel for the connection Create a blocking or non-blocking client stub with the channel Create a request Send the request using the stub Handle the responses in sync or async mode Step 4: Create client @meteatamel

Slide 20

Slide 20 text

Google Cloud Platform Demo: Greeter Server & Client (Java) @meteatamel https://github.com/meteatamel/grpc-samples-java

Slide 21

Slide 21 text

Google Cloud Platform gRPC Benefits @meteatamel

Slide 22

Slide 22 text

Google Cloud Platform HTTP/2: low latency transport of content Protocol Buffers (or Bond): efficient serialization Multi-language Support Connection Options: Unary, server, client, bi-directional streaming Main benefits @meteatamel

Slide 23

Slide 23 text

Google Cloud Platform Let’s talk about HTTP/2 @meteatamel

Slide 24

Slide 24 text

Google Cloud Platform History of HTTP 1991 1993 1995 1997 1999 HTTP/0.9 2001 2003 2005 2007 2009 2011 2013 HTTP/1.0 2015 2017 HTTP/1.1 ? @meteatamel

Slide 25

Slide 25 text

Google Cloud Platform New TCP connection per HTTP connection Number of parallel HTTP requests = Number of TCP connections. HTTP 1.x: Limited Parallelism @meteatamel

Slide 26

Slide 26 text

Google Cloud Platform HTTP 1.0: Head of line blocking Without pipelining @meteatamel

Slide 27

Slide 27 text

Google Cloud Platform HTTP 1.1: Head of line blocking With pipelining @meteatamel

Slide 28

Slide 28 text

Google Cloud Platform HTTP 1.1: Head of line blocking HTTP/1.1 HOL Blocking With pipelining @meteatamel

Slide 29

Slide 29 text

Google Cloud Platform HTTP Headers Uncompressed plain text headers for each and every HTTP request HTTP 1.x: Protocol Overhead @meteatamel

Slide 30

Slide 30 text

Google Cloud Platform History of HTTP 1991 1993 1995 1997 1999 HTTP/0.9 2001 2003 2005 2007 2009 2011 2013 HTTP/1.0 2015 2017 HTTP/1.1 @meteatamel SPDY HTTP/2.0

Slide 31

Slide 31 text

Google Cloud Platform Released in 2015. Extend (not replace) the semantics of HTTP/1.1 Improve end-user perceived latency Address the "head of line blocking" Not require multiple connections Minimize protocol overhead HTTP/2 @meteatamel

Slide 32

Slide 32 text

Google Cloud Platform HTTP/2 Single TCP connection No Head-of-line blocking Binary framing layer Request –> Stream Header Compression Transport(TCP) Application (HTTP/2) Network (IP) Session (TLS) [optional] Binary Framing HEADERS Frame DATA Frame HTTP/2 POST: /upload HTTP/1.1 Host: www.javaday.org.ua Content-Type: application/json Content-Length: 27 HTTP/1.x {“msg”: “Welcome to 2016!”} @meteatamel

Slide 33

Slide 33 text

Google Cloud Platform Stream is a bidirectional flow of bytes within an established connection, which may carry one or more messages. Message is a complete sequence of frames that map to a logical request or response message. Frame is the smallest unit of communication in HTTP/2, each containing a frame header, which at a minimum identifies the stream to which the frame belongs: HEADERS for metadata, DATA for payload, RST_STREAM SETTINGS, PUSH_PROMISE, PING, GOAWAY, WINDOW_UPDATE, etc. HTTP/2 Binary Framing @meteatamel

Slide 34

Slide 34 text

Google Cloud Platform Interleave multiple requests and responses in parallel without blocking on any one Use a single TCP connection to deliver multiple requests and responses in parallel. Enable flow-control, server push, etc. HTTP/2 Request/Response Multiplexing Stream 1 HEADERS Stream 2 DATA Stream 3 HEADERS Stream 3 DATA Stream 1 DATA Stream Y HEADERS Stream X DATA Requests Responses HTTP/2 connection Client Server @meteatamel

Slide 35

Slide 35 text

Google Cloud Platform Client and server maintain and update an indexed list of previously seen header fields Indexes are sent for already seen headers Values are encoded with a static Huffman code HPACK: Header compression for HTTP/2 :method GET :scheme HTTPS :host myhost.com :path /image custom_header some_value :method GET :scheme HTTPS :host myhost.com :path /image custom_header some_value HEADERS Frame :method GET :scheme HTTPS :host myhost.com :path /resource custom_header some_value Request #2 Request #1 :method GET :scheme HTTPS :host myhost.com :path /resource custom_header some_value :path /resource + indexes for already seen values HEADERS Frame @meteatamel

Slide 36

Slide 36 text

Google Cloud Platform HTTP/2: What it means for you? HTTP/2 HTTP/1.1 http2demo.io/ @meteatamel

Slide 37

Slide 37 text

Google Cloud Platform Protocol Buffers Publishing 50KB messages at maximum throughput from a single n1-highcpu-16 GPE VM instance, using 9 gRPC channels. More impressive than the almost 3x increase in throughput, is that it took only 1/4 of the CPU resources. 11x difference per CPU 3x increase in throughput https://cloud.google.com/blog/big-data/2016/03/announcing-grpc-alpha-for-google-cloud-pubsub gRPC vs JSON/HTTP for Google Cloud Pub/Sub @meteatamel

Slide 38

Slide 38 text

Google Cloud Platform Multi-Language Support Java/Android Go C/C++ C# Node.js PHP Ruby Python Objective-C Service definitions and client libraries MacOS Linux Windows Android iOS Platforms supported @meteatamel

Slide 39

Slide 39 text

Google Cloud Platform Demo: Greeter Server & Client (C#) @meteatamel https://github.com/meteatamel/grpc-samples-dotnet

Slide 40

Slide 40 text

Google Cloud Platform Connection Options The client send a sequence of messages to the server using a provided stream. Once the client has finished writing the messages, it waits for the server to read them and return its response. Client streaming Both sides send a sequence of messages using a read-write stream. The two streams operate independently. The order of messages in each stream is preserved. Bi-di streaming Unary RPCs where the client sends a single request to the server and gets a single response back, just like a normal function call. Unary The client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. Server streaming @meteatamel

Slide 41

Slide 41 text

Google Cloud Platform Demo: Chat app using gRPC streaming @meteatamel

Slide 42

Slide 42 text

Confidential & Proprietary Google Cloud Platform 42 grpc.io Mete Atamel @meteatamel atamel.dev Thank You Send talk feedback bit.ly/atamel