Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

gRPC:更高效的微服務介面

Title: gRPC: A more efficient microservice interface.
Presented in: Taiwan Cloud Edge Summit 2020 (台灣雲端大會)
https://cloudsummit.ithome.com.tw/speaker.html#s7262

Description:

在 Web service 時代,基於 HTTP 的 REST 簡單易用,是最流行的 API 服務介面。然而,到了微服務時代,服務互連現象更為頻繁緊密,以前 REST 的優點卻變成缺點:過於簡單的模型,欠缺基本的服務治理;過於陽春的 HTTP,欠缺高效的傳輸介面。

新一代的 gRPC,則是在 HTTP/2 的基礎上,盡量維持簡單易用的特性,又具備微服務世界該有的服務治理與高效傳輸。

本演講將示範 gRPC 的工作流程:介面定義、編程、測試、雲端應用實務,讓你可以開始嘗試導入 gRPC。

  • Login to see the comments

gRPC:更高效的微服務介面

  1. 1. gRPC:更⾼效的微服務介⾯ A more efficient microservice interface 葉秉哲 2020-09-08 Sr. Software Engineer
  2. 2. Carousell is a classifieds marketplace that makes selling as easy as taking a photo, buying as simple as cha=ng. Launched in August 2012, Carousell began in Singapore and now has a presence in eight markets across Asia. With over 250 million lisEngs, we are one of the world’s largest and fastest-growing marketplaces in Southeast Asia, Taiwan and Hong Kong, and are backed by Telenor Group, Rakuten Ventures, Sequoia India and Naspers. The Carousell marketplace has a diverse range of products across a variety of categories, including cars, lifestyle, gadgets and fashion accessories.
  3. 3. With over 250 million lisBngs, we are one of the world’s largest and fastest-growing marketplaces in Southeast Asia, Taiwan and Hong Kong. The Carousell marketplace has a diverse range of products across a variety of categories, including cars, lifestyle, gadgets and fashion accessories. We use gRPC!
  4. 4. 簡易 性能 左右擺盪
  5. 5. 簡易 性能左右擺盪 Unix RPC Java RMI SOAP Web Service REST CORBA
  6. 6. hUps://github.com/dotnet-architecture/eShopOnContainers Microservice world…
  7. 7. hUps://github.com/dotnet-architecture/eShopOnContainers Is REST still good enough in the microservice world?
  8. 8. 簡易 REST 過於簡單的模型, ⽋缺基本的服務治理。 過於陽春的 HTTP, ⽋缺⾼效的傳輸介⾯。 HTTP 1.1 Swagger WebSocket OpenAPI 缺點 ➠改進 (個別)
  9. 9. 簡易 性能左右擺盪 gRPC 過於簡單的模型, ⽋缺基本的服務治理。 過於陽春的 HTTP, ⽋缺⾼效的傳輸介⾯。 HTTP/2 Protocol Buffers + = REST (綜合)
  10. 10. 簡易 性能左右擺盪 REST Unix RPC Java RMI SOAP Web Service CORBA gRPC
  11. 11. gRPC app Protobuf HTTP/2 HTTP 1.1 TCP + TLS 1.2 UDP HTTP/3 IP HTTP app QUIC + TLS 1.3
  12. 12. HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP app
  13. 13. Demo #1 HTTP/2 ⾼效的傳輸介⾯
  14. 14. curl http://nghttp2.org/ HTTP 1.1 HTTP/2
  15. 15. curl -vkso /dev/null http://nghttp2.org/ HTTP/1.1 header size = 385
  16. 16. curl --http2 -vkso /dev/null http://nghttp2.org/ HTTP/2 header size = 224
  17. 17. curl http://nghttp2.org/ HTTP 1.1 HTTP/2 http header size 42% ➡
  18. 18. HTTP/2 key differences ✓binary, instead of textual ✓header compression to reduce overhead • fully multiplexed, instead of ordered and blocking • can use one connection for parallelism • server “push” hUps://hUp2.github.io/faq/#what-are-the-key-differences-to-hUp1x
  19. 19. HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP app
  20. 20. gRPC app Protobuf HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP appgRPC Protocol Buffers + = HTTP/2
  21. 21. Demo #2 Protocol buffers 服務治理模型
  22. 22. HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP app Content-Type: xxx/yyy
  23. 23. IDL Swagger Client Server Codegen Client SDK Server stub App REST with Design-First API Strategy java -jar swagger-codegen-cli …
  24. 24. IDL .proto Client Server Codegen Client API Server API App protoc XXX.proto --go_out=plugins=grpc:. gRPC
  25. 25. Protocol buffers and competitors 2008 Protobuf 2 by Google Apache Thril by Facebook 2009 Apache Avro by Hadoop 2016 Protobuf 3 by Google gRPC 1.0 by Google 2017 gRPC donated to CNCF
  26. 26. IDL .proto Client Server Codegen Client API Server API App protoc XXX.proto --go_out=plugins=grpc:. gRPC
  27. 27. IDL .proto Server Mock App grpcurl Server Mock gRPC dev/test with mock & grpcurl 50051 10000 hUps://github.com/William-Yeh/grpcurl-and-ghz-demo
  28. 28. IDL .proto route_guide.proto
  29. 29. IDL .proto Mock Server Mock 50051 docker run -ti --name mock --rm -p 50051:50051 -v $(pwd)/routeguide:/proto -v $(pwd)/mock:/mock williamyeh/grpc-mock /mock/mock.js mock.js
  30. 30. IDL .proto Mock grpcurl Server Mock 50051 grpcurl -plaintext -d '{"latitude":407838351, "longitude":-746143763}' -import-path ./routeguide -proto route_guide.proto 127.0.0.1:50051 routeguide.RouteGuide.GetFeature
  31. 31. IDL .proto App server.go out/server Server 10000 Server API protoc XXX.proto --go_out=plugins=grpc:. Codegen xxx.pb.go
  32. 32. grpcurl -plaintext -d '{"latitude":407838351, "longitude":-746143763}' -import-path ./routeguide -proto route_guide.proto 127.0.0.1:10000 routeguide.RouteGuide.GetFeature IDL .proto Server grpcurl 10000
  33. 33. Protobuf message
  34. 34. IDL .proto Server grpcurl 10000 Try to input invalid message?
  35. 35. gRPC app Protobuf HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP appgRPC Protocol Buffers + = HTTP/2
  36. 36. gRPC benefits ✓ binary, instead of textual ✓ header compression to reduce overhead • fully multiplexed, instead of ordered and blocking • can use one connection for parallelism • server “push” ✓ binary marshaling format ✓ IDL ✓ language neutral HTTP/2 Protobuf Bidirectional streaming
  37. 37. gRPC in the real world
  38. 38. gRPC app Protobuf HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP app
  39. 39. Server gRPC Server Server gRPC:更⾼效的微服務介⾯ ⾼效的傳輸介⾯ 服務治理模型
  40. 40. Server REST gRPC Server Server Desktop app Mobile app ? ? Web browser ? ? Server ? ❶ ❷ ❸ ❸ ❸ Beyond microservices?
  41. 41. Server REST gRPC Server Server Mobile app ? Question ❶
  42. 42. hUps://grpc.io/docs/languages/ Mobile app
  43. 43. gRPC mobile app Protobuf HTTP/2 TCP + TLS 1.2 UDP HTTP/3 IP QUIC + TLS 1.3Challenge! Rescue! Connection migration
  44. 44. Server gRPC Server Server Web browser ? Question ❷
  45. 45. Server gRPC Server Server grpc-web proxy Web browser grpc-web JS client hUps://github.com/grpc/grpc-web Limited gRPC functionalities e.g., Envoy
  46. 46. Server REST gRPC Server Server Mobile app ? Web browser ? Server ? Question ❸
  47. 47. Server REST gRPC Server Server Server grpc-gateway Mobile app Web browser Solution #1
  48. 48. IDL .proto Server Codegen Reverse proxy code App protoc XXX.proto --grpc-gateway_out=. grpc-gateway hUps://github.com/grpc-ecosystem/grpc-gateway protoc XXX.proto --swagger_out=.
  49. 49. REST gRPC Server Server Server Server API gateway Mobile app Web browser Solution #2 Off-the-shelf software Custom software
  50. 50. Conclusion
  51. 51. hUps://github.com/dotnet-architecture/eShopOnContainers Is REST still good enough in the microservice world?
  52. 52. 簡易 性能 gRPC 過於簡單的模型, ⽋缺基本的服務治理。 過於陽春的 HTTP, ⽋缺⾼效的傳輸介⾯。 HTTP/2 Protocol Buffers + = REST
  53. 53. gRPC app Protobuf HTTP/2 HTTP 1.1 TCP + TLS 1.2 IP HTTP app
  54. 54. gRPC benefits ✓ binary, instead of textual ✓ header compression to reduce overhead • fully multiplexed, instead of ordered and blocking • can use one connection for parallelism • server “push” ✓ binary marshaling format ✓ IDL ✓ language neutral HTTP/2 Protobuf Bidirectional streaming
  55. 55. We’re hiring! Software Engineer, Backend (Taiwan) https://grnh.se/c90e0c461us
  56. 56. • Newton's Cradle by Rflor from the Noun Project Attribution

×