Module 5a - Apache Thrift Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the 4 internal software layers involved in a thrift service? What are they for?

A
  1. Server - receives incoming connections
  2. Processor - reads/writes I/O streams
  3. Protocol - encodes/decodes data (can be into JSON)
  4. Transport - reads/writes network (can use TCP, or HTTP)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give an example of a thrift IDL (.thrift file) for an interface that calculates the square root of a number, and throws an exception

A
service MathService {
   double sqrt(1: double num) throws (1: IllegalArgument ia)
}

exception IllegalArgument {
1: string message;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 9 base types for the thrift IDL?

A
bool
byte
i16
i32
i64
double
binary
string
void
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 types of datatype containers in the thrift IDL?

A

list
set
map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the other language constructs that thrift provides in its IDL?

A
const
typedef
enum
struct
exception
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the field modifiers for function signatures that thrift provides in its IDL?

A

required
optional
default values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the “oneway” keyword used for in the thrift IDL?

A

building oneway thrift RPCs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the service keyword define in the thrift IDL?

A

A service consists of a set of named functions, each with a list of parameters and a return type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the “namespace” keyword determine in the thrift IDL?

A

Determines the java package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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?

A

thrift –gen file.thrift

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What steps must a synchronous thrift RPC client program execute when calling a service handler and invoking an RPC from the server?

A

Client must:
1. create a TSocket object using the network address of the server

  1. Create a TTransport object using the TSocket object from step 1
  2. Create a TProtocol object using the TTransport object from step 2
  3. 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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?

A
  1. Create a Processor object from the generated service handler files
  2. Create a TServerSocket object using a port number to bind to
  3. Create objects for protocolFactory, transportFactory, and processorFactory. The processorFactory will be the processor object from step 1
  4. Create the TServer object from the arguments in step 3.
  5. run the blocking “serve()” call
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of having the same “Protocol” and the “Transport” on the client and server for thrift RPC?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In what way does a thrift client violate the principle of location transparency?

A

The thrift client must know the host name and port number of a given server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In what way does a thrift client-server system violate the principle of location transparency?

A

Server may throw a variety of exceptions, and the exceptions will be passed along the network to the Client

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Thrift _______, ________ and ______ _______ are not thread safe in a multi-threaded client

A

transports
protocols
client stubs

17
Q

Asynchronous thrift RPC clients must provide a _______ ______ to be invoked upon completing a request

A

callback function

18
Q

Asynchronous thrift RPC clients must use a non-blocking ________ and ________

A

socket

transport

19
Q

What are some synchronization primitives used between a callback method on an asynchronous RPC client, and an RPC server (in java)?

A

Conditions
or
CountDownLatch

20
Q

What steps must an Asynchronous thrift RPC client program execute when calling a service handler and invoking an RPC from the server?

A

Client must:
1. Create a TNonblockingTransport object using the network address of the server (internally creates a socket connection)

  1. Create a TProtocolFactory object
  2. Create an TAsyncClientManager object
  3. Access the server async RPC object from the objects created in steps 1, 2, and 3
21
Q

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?

A

Server must:
1. Create the server socket object with a port number to bind to

  1. Create objects for the ProtocolFactory, TransportFactory, and the ProcessorFactory. Pass them into the server object
  2. Create the server object from the objects in step 2, and pick the appropriate server type (HsHa, ThreadPool, etc)
  3. Set the max number of worker threads
  4. run the blocking “serve()” call
22
Q

What are the names of the 5 thrift server implementations in Java?

A
  • TSimpleServer
  • TNonblockingServer
  • THsHaServer
  • TThreadedSelectorServer
  • TThreadPoolServer
23
Q

How does the thrift TSimpleServer in Java work?

A

TSimpleServer uses a single thread and blocking I/O

24
Q

How does the thrift TNonblockingServer in Java work?

A

TNonblockingServer uses a single thread and non blocking I/O. It can handle parallel connections but executes requests serially just like TSimpleServer.

25
Q

How does the thrift THsHaServer in Java work?

A

THsHaServer uses one thread for network I/O and a pool of worker threads. It can process multiple requests in parallel.

26
Q

How does the thrift TThreadedSelectorServer in Java work?

A

TThreadedSelectorServer uses a pool of threads for network I/O and a pool of worker threads for request processing

27
Q

How does the thrift TThreadPoolServer in Java work?

A

TThreadPoolServer uses one thread to accept connections and then handles each connection using a dedicated thread drawn from a pool of worker threads

28
Q

When creating a multi-threaded thrift server in Java, where how does the following error:

“OutOfMemoryError: Unable to create new native thread”

happen?

A

When a Java program attempts to create a large number of threads (eg 100+)

29
Q

Why does TThreadedPoolServer yield the best performance internally?

What is the drawback with this type of server?

A
  • Performance is maximized because it uses minimal synchronization internally
  • Drawback is that it consumes 1 thread per connection leading to resource exhaustion when there are many parallel connections
30
Q

What should be the maximum number of size of the worker thread pool when creating a multi-threaded server in java?

A

64 threads

This avoids resource exhaustion

31
Q

What is the purpose of the thrift middleware layer protocols (on top of the transport layer)?

A

The middleware layer protocols are used to encode RPC requests and responses (such as raw text, JSON, XML, etc)

32
Q

What are 3 thrift middleware protocol types?

A
  • TBinaryProtocol
  • TCompactProtocol
  • TJSONProtocol
33
Q

What is the difference between TBinaryProtocol and TCompactProtocol?

A

BinaryProtocol encodes numeric values in a straightforward binary format whereas CompactProtocol is more compact and uses variable-length encoding for integers

34
Q

Thrift fields can be modified in a manner that provides compatibility between old and new protocol versions, under 4 rules. What are these 4 rules?

A
  1. The manually assigned numeric tags of existing fields should never be changed
  2. New fields can be added as long as they are declared “optional” and have appropriate default values
  3. Fields that are no longer needed can be removed as long as their tag numbers are never reused.

Unrecognized fields are skipped by the parser, but old servers may be unable to process requests from new clients

  1. Default values can be changed