Primer On Remote Procedure Calls
These are my notes on the primer for RPC lesson
Summary
- Client-Server Architecture
- Role of RPC
- Architecture of RPC System
- Anatomy of RPC Call
- Invocation Semantics
- Examples
- gRPC
Client-Server Architecture
Simple pattern for distributed system
- Client sends request to server
- Server sends response to client
Challenges with Client-Server
- Discovery and binding
- Identifying the interface and parameter types
- Agreeing on data representation
- Null terminated strings?
- Array ordering?
- Eplicit data management
- Unpredictable delays
- Unknown cause of failures
Role of RPC
- Aims to hide complexity of distrubted programming from application and developers.
- Make distributed programming appear similar to local node programming.
Functionality
- Service registration mechanism
- Connection management
- Interface specification
- Type system
- Data management
- (De)Serialization/(Un)Marshaling
- Error management
Architecture of RPC System
- API
- Calling a remote procedure
- Stubs
- Data marshaling
- Runtime
- Connection management, failures
Interface Definition Language (IDL) := The agreed-upon way in which servers describe the services the provide and their associated data requirements.
Creation Sequence
- Programmer writes IDL
- Compiler compiles IDL into stubs
- Server code implements stubs
- Server added to registry
- Programmer writes client against API
- When code is run, rumtime handles everything else
Anatomy of RPC Call
- Client calls procedure
- (Client) Stub builds message
- Message is sent (potentially over the network)
- Server OS hands message
- (Server) Stub unpacks message
- Stub makes local call to procedure
Invocation Semantics
Synchronous vs Async
Synchronous
Thread blocks when making a call
Asynchronous
Threads do not block when they make a call
Hides latency
Can register a callback function that gets called when data is returned.
On a local PC, no response => deadlock or full failure - Has to restart and redo everything
Using Remote PC, No response doesn’t tell us why it failed
At Most Once
=> if client knows calls may not be called, timeout/retransmit
logic can be moved to client
Examples
- Sun RPC
- SOAP
- CORBA
- Apache Thrift
- gRPC
- Other specialized implementations
- useful for when you can make certain gaurantees about the environment
- high speed, reliable network
- low resource/embedded footprint
- useful for when you can make certain gaurantees about the environment
gRPC
Googles RPC implementations
Inspired by SunRPC
Relies on Protocol Buffers
Protocol Buffers := An IDL that allows programmers to define types and operations used in an RPC system. RPC mechanisms then use the protocol buffers to perform data serialization.
protoc
compiler translates *.proto
-> stubs
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Example proto file from https://github.com/grpc/grpc/blob/master/examples/protos/helloworld.proto
syntax = proto3;
option java_multiple_files = true;
option java_package = io.grpc.examples.helloworld;
option java_outer_classname = HelloWorldProto;
option objc_class_prefix = HLW;
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
// Sends another greeting
rpc SayHelloAgain(HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
service
blocks define methods/interfaces
message
blocks define data types
do NOT change index of message field after publishing