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

Building a blazing fast gRPC Service with PHP

Building a blazing fast gRPC Service with PHP

Building a blazing fast gRPC Service with PHP using Roadrunner and the Spiral Framework.
Held on the Neos CMS conference 2023

Daniel Lienert

April 28, 2023
Tweet

More Decks by Daniel Lienert

Other Decks in Programming

Transcript

  1. Agenda 1. Motivation 2. What are gRPC and Protocol Buffers?

    3. PHP as gRPC Server? 4. gRPC in Action (code examples included)
  2. Local Function Call vs. Remote Procedure Call (RPC) 6 Server

    A Login Server B User Management Process Login User Management Local function call Remote procedure call (RPC)
  3. Flow Types 9 Unary Client Server Server Streaming Client Server

    Client Streaming Client Server Bi-drectional Streaming Client Server
  4. gRPC vs SOAP (and REST) 11 Protocol Bene fi ts

    Drawbacks gRPC - High performant - Multiplexing - Binary protocol - smaller and faster - Stream processing - API oriented (no constraints) - Limited tooling and documentation compared to REST and SOAP - Requires HTTP/2 support SOAP - Established and widely adopted - Tooling and documentation available - API oriented (no constraints) - Bulky Text-based protocol slow and ine ff i cient - Complex and verbose syntax - Request / Response only - Heavyweight REST - Widely adopted and established - Simple and easy to use - Tooling and documentation available - Text-based protocol slower and less e ff i cient - Request / Response only - Requires additional e f fort for error handling - CRUD oriented
  5. gRPC Use Cases • Microservices • Cloud Native Applications •

    High-performance APIs • IoT and Mobile Applications • Inter-service communication • Real time communication 12
  6. • Data is fully typed • Data efficient binary format

    • Encoding / decoding data is fast • Data can be read across any language • Embedded Documentation • Safe Schema Evolution protobuf Advantages
  7. Initialization Common Libraries User Libraries Cache Warmup Entry Point Routing

    Domain Logic Response Return and Exit Classic Request Lifecycle Con fi guration Bootstrapping Actual Work Roadrunner handled requests
  8. Initialization Common Libraries User Libraries Cache Warmup Entry Point Routing

    Domain Logic Response Return and Exit Classic Request Lifecycle Con fi guration Bootstrapping Actual Work Roadrunner handled requests 2023-04-25T23:46:09.670+0200 DEBUG grpc method was called successfully {"method": "/app.neoscon.UserService/Search", "start": "2023-04-25T23:46:09.640+0200", "elapsed": "30.629458ms"} 2023-04-25T23:46:16.459+0200 DEBUG grpc method was called successfully {"method": "/app.neoscon.UserService/Search", "start": "2023-04-25T23:46:16.458+0200", "elapsed": "992.041µs"} 2023-04-25T23:46:18.806+0200 DEBUG grpc method was called successfully {"method": "/app.neoscon.UserService/Search", "start": "2023-04-25T23:46:18.805+0200", "elapsed": "526.459µs"} 2023-04-25T23:46:32.023+0200 DEBUG grpc method was called successfully {"method": "/app.neoscon.UserService/Search", "start": "2023-04-25T23:46:32.022+0200", "elapsed": "895.875µs"}