Module 5a - Apache Thrift Flashcards
What are the 4 internal software layers involved in a thrift service? What are they for?
- Server - receives incoming connections
- Processor - reads/writes I/O streams
- Protocol - encodes/decodes data (can be into JSON)
- Transport - reads/writes network (can use TCP, or HTTP)
Give an example of a thrift IDL (.thrift file) for an interface that calculates the square root of a number, and throws an exception
service MathService { double sqrt(1: double num) throws (1: IllegalArgument ia) }
exception IllegalArgument {
1: string message;
}
What are the 9 base types for the thrift IDL?
bool byte i16 i32 i64 double binary string void
What are the 3 types of datatype containers in the thrift IDL?
list
set
map
What are the other language constructs that thrift provides in its IDL?
const typedef enum struct exception
What are the field modifiers for function signatures that thrift provides in its IDL?
required
optional
default values
What is the “oneway” keyword used for in the thrift IDL?
building oneway thrift RPCs
What does the service keyword define in the thrift IDL?
A service consists of a set of named functions, each with a list of parameters and a return type
What does the “namespace” keyword determine in the thrift IDL?
Determines the java package
After the IDL has been defined in a thrift file (lets call it file.thrift), what command is used to generate the source code files for the services?
thrift –gen file.thrift
What steps must a synchronous thrift RPC client program execute when calling a service handler and invoking an RPC from the server?
Client must:
1. create a TSocket object using the network address of the server
- Create a TTransport object using the TSocket object from step 1
- Create a TProtocol object using the TTransport object from step 2
- Create the service handler object from the TProtocol object in step 3. The client can now call the server’s service handlers and invoke the RPC
What steps must a single-threaded thrift RPC server program execute when setting up a server which allows clients to invoke RPC calls to it?
- Create a Processor object from the generated service handler files
- Create a TServerSocket object using a port number to bind to
- Create objects for protocolFactory, transportFactory, and processorFactory. The processorFactory will be the processor object from step 1
- Create the TServer object from the arguments in step 3.
- run the blocking “serve()” call
What is the purpose of having the same “Protocol” and the “Transport” on the client and server for thrift RPC?
Protocol ensures that the data encoding formatting matches for the server and the client (JSON or otherwise)
Transport ensures that the network protocols that the server and client use are consistent
In what way does a thrift client violate the principle of location transparency?
The thrift client must know the host name and port number of a given server
In what way does a thrift client-server system violate the principle of location transparency?
Server may throw a variety of exceptions, and the exceptions will be passed along the network to the Client
Thrift _______, ________ and ______ _______ are not thread safe in a multi-threaded client
transports
protocols
client stubs
Asynchronous thrift RPC clients must provide a _______ ______ to be invoked upon completing a request
callback function
Asynchronous thrift RPC clients must use a non-blocking ________ and ________
socket
transport
What are some synchronization primitives used between a callback method on an asynchronous RPC client, and an RPC server (in java)?
Conditions
or
CountDownLatch
What steps must an Asynchronous thrift RPC client program execute when calling a service handler and invoking an RPC from the server?
Client must:
1. Create a TNonblockingTransport object using the network address of the server (internally creates a socket connection)
- Create a TProtocolFactory object
- Create an TAsyncClientManager object
- Access the server async RPC object from the objects created in steps 1, 2, and 3
What steps must a multi-threaded thrift RPC server program execute when setting up a server which allows clients to invoke RPC calls to it?
Server must:
1. Create the server socket object with a port number to bind to
- Create objects for the ProtocolFactory, TransportFactory, and the ProcessorFactory. Pass them into the server object
- Create the server object from the objects in step 2, and pick the appropriate server type (HsHa, ThreadPool, etc)
- Set the max number of worker threads
- run the blocking “serve()” call
What are the names of the 5 thrift server implementations in Java?
- TSimpleServer
- TNonblockingServer
- THsHaServer
- TThreadedSelectorServer
- TThreadPoolServer
How does the thrift TSimpleServer in Java work?
TSimpleServer uses a single thread and blocking I/O
How does the thrift TNonblockingServer in Java work?
TNonblockingServer uses a single thread and non blocking I/O. It can handle parallel connections but executes requests serially just like TSimpleServer.