In-depth analysis of the implementation mechanism of HBaseRPC (Protobuf)

Source: Internet
Author: User
Background: An RpcServer instance is created in HMaster and RegionServer, and Rpc is called between the RpcServer and the Client. In HBase0.95, Google-Protobuf is introduced as the intermediate data organization mode, based on the Rpc interface provided by Protobuf, service-based Rpc is implemented. This article describes the implementation details of HBase-Rpc. HBase

Background: An RpcServer instance is created in HMaster and RegionServer, and Rpc is called between the RpcServer and the Client. In HBase0.95, Google-Protobuf is introduced as the intermediate data organization mode, based on the Rpc interface provided by Protobuf, service-based Rpc is implemented. This article describes the implementation details of HBase-Rpc. HBase

Background

In HMaster and RegionServer, RpcServer instances are created and Rpc calls are implemented between the two clients. In HBase0.95, Google-Protobuf is introduced as the intermediate data organization mode, based on the Rpc interface provided by Protobuf, service-based Rpc is implemented. This article describes the implementation details of HBase-Rpc.

HBase RPC Protocol

? In HMaster and RegionServer, multiple rpc protocols are implemented to complete management and application logic. The specific protocol is as follows:

Rpc protocols supported by HMaster:
MasterMonitorProtocol: communication between the Client and the Master. The Master is the RpcServer, which is mainly used for HBase Cluster Monitoring.

MasterAdminProtocol: communication between the Client and the Master. The Master is the RpcServer, which mainly implements HBase table management. For example, TableSchema changes, Table-Region migration, merging, Offline, Online, and load balancing, as well as Table deletion and snapshot functions.

RegionServerStatusProtoco: Communication Between RegionServer and Master. The Master is an RpcServer that provides services for RegionServer to report the status of HMaster.

RegionServer supports the following Rpc protocols:

Communication between Client and RegionServer. RegionServer is an RpcServer that implements User read/write requests. For example, get, multiGet, mutate, scan, bulkLoadHFile, and execute Coprocessor.

AdminProtocols: communication between the Client and RegionServer. RegionServer is an RpcServer that manages Region, services, and files. For example, storefile information, Region operations, WAL operations, Server switches, and so on.

(Note: The Client mentioned above can be a user Api, RegionServer, or HMaster)


? HBase-RPC implementation mechanism analysis

Configure three queues for RpcServer:

1) in the common queue callQueue, most Call requests exist in this queue: maxQueueLength on callQueue is $ {ipc. server. max. callqueue. length}. The default value is $ {hbase. master. handler. count} * DEFAULT_MAX_CALLQUEUE_LENGTH_PER_HANDLER. Currently, in 0.95.1, the maximum number of CallQueue on each Handler is 10 by default (DEFAULT_MAX_CALLQUEUE_LENGTH_PER_HANDLER.

2) priority queue: PriorityQueue. If you set the number of priorityHandlerCount, a queue storage Call equivalent to callQueue will be created. The number of Handler corresponding to this priority queue will be passed in when rpcServer is instantiated.

3) Copy queue: replicationQueue. Since the RpcServer is shared by the HMaster and RegionServer, this function is only available for RegionServer, And the queue size is $ {ipc. server. max. callqueue. size} is specified. The default value is 1024*1024*1024. The number of handler is hbase. regionserver. replication. handler. count.

RpcServer consists of three modules:

Listener === Queue === Responder

?

The following uses HBaseAdmin. listTables as an example to analyze the function call process of an Rpc request:

1) RpcClient creates a BlockingRpcChannel.

2) use the channel as the parameter to create the stub required to execute the RPC request. At this time, stub has been encapsulated in a specific Service, and stub defines an executable rpc interface.

3) stub calls the corresponding interface, and the actual internal channel calls the callBlockingMethod method.

The BlockingRpcChannel interface method callBlockingMethod provided by protobuf is implemented in RpcClient,

? @Overridepublic Message callBlockingMethod(MethodDescriptor md, RpcController controller,Message param, Message returnType)throws ServiceException {return this.rpcClient.callBlockingMethod(md, controller, param, returnType, this.ticket,this.isa, this.rpcTimeout);}

The above implementation details are finally converted into calling rpcClient. Different rpc functions are encapsulated using MethodDescriptor. The Message base class can be used to receive different Request and Response Objects Based on Message.

4) RpcClient creates a Call object, finds or creates a suitable Connection, and wakes up the Connection.

5) The Connection waits for the Response of the Call. When the rpcClient calls the function, connection. writeRequest (Call call) is used to write the request to the network stream of the RpcServer.

6) wait for the Call Response and return it to the upper-layer interface layer by layer to complete the RPC Call.

The internal structure of the Rpc packet received by RPCServer is as follows:

Magic

(4 Byte)

Version

(1 Byte)

AuthMethod

(1 Byte)

Connection

HeaderLength

(4 Byte)

ConnectionHeader

Request

"HBas"

Verify the CURRENT_VERSION of RpcServer

Consistent with RPC packets

Currently, three types are supported:

AuthMethod. SIMPLE

AuthMethod. KERBEROS

AuthMethod. DIGEST

RPC. proto Definition
RPCProtos. ConnectionHeader
Message ConnectionHeader {
Optional UserInformation userInfo = 1;
Optional string serviceName = 2;
// Cell block codec we will use sending over optional cell blocks .? Server throws exception
// If cannot deal.
Optional string cellBlockCodecClass = 3 [default = "org. apache. hadoop. hbase. codec. KeyValueCodec"];
// Compressor we will use if cell block is compressed .? Server will throw exception if not supported.
// Class must implement hadoop's CompressionCodec Interface
Optional string cellBlockCompressorClass = 4;
}
Serialized data

The entire Request storage is an encoded byte array, which includes the following parts:

RequestHeaderLength (RawVarint32)

RequestHeader

ParamSize(RawVarint32)

Param

Cellpattern

RPC. proto definition:
Message RequestHeader {
// Monotonically increasing callId to keep track of RPC requests and their response
Optional uint32 callId = 1;
Optional RPCTInfo traceInfo = 2;
Optional string methodName = 3;
// If true, then a pb Message param follows.
Optional bool requestParam = 4;
// If present, then an encoded data block follows.
Optional CellBlockMeta cellBlockMeta = 5;
// TODO: Have client specify priority
}
Serialized data
Check whether Param and cellparts exist in the Header. If yes, the access will continue.

The basic Message type of Protobuf,
The Request Param inherits the Message,
The type of the Method to be obtained is determined.

The RpcServer includes three modules,

1) Listener. Contains multiple Reader threads. The Selector obtains the ServerSocketChannel to receive the Connection sent from the RpcClient, reconstructs the Call instance, and adds it to the CallQueue queue.

?" IPC Server listener on 60021 "daemon prio = 10 tid = 0x00007f7210a97800 nid = 0x14c6 runnable [0x00007f720e8d0000]
Java. lang. Thread. State: RUNNABLE
At sun. nio. ch. EPollArrayWrapper. epollWait (Native Method)
At sun. nio. ch. EPollArrayWrapper. poll (EPollArrayWrapper. java: 210)
At sun. nio. ch. EPollSelectorImpl. doSelect (EPollSelectorImpl. java: 65)
At sun. nio. ch. SelectorImpl. lockAndDoSelect (SelectorImpl. java: 69)
-Locked <0x00000000c43cae68> (a sun. nio. ch. Util $2)
-Locked <0x00000000c43cae50> (a java. util. Collections $ UnmodifiableSet)
-Locked <0x00000000c4322ca8> (a sun. nio. ch. EPollSelectorImpl)
At sun. nio. ch. SelectorImpl. select (SelectorImpl. java: 80)
At sun. nio. ch. SelectorImpl. select (SelectorImpl. java: 84)
At org. apache. hadoop. hbase. ipc. RpcServer $ Listener. run (RpcServer. java: 646)

2) Handler. Executes Call, calls the Service method, and returns Pair

"IPC Server handler 0 on 60021" daemon prio = 10 tid = 0x00007f7210eab000 nid = 0x14c7 waiting on condition [0x00007f720e7cf000]
Java. lang. Thread. State: WAITING (parking)
At sun. misc. Unsafe. park (Native Method)
-Parking to wait? <0x00000000c43cad90> (a java. util. concurrent. locks. AbstractQueuedSynchronizer $ ConditionObject)
At java. util. concurrent. locks. LockSupport. park (LockSupport. java: 156)
At java. util. concurrent. locks. AbstractQueuedSynchronizer $ ConditionObject. await (AbstractQueuedSynchronizer. java: 1987)
At java. util. concurrent. Define blockingqueue. take (define blockingqueue. java: 399)
At org. apache. hadoop. hbase. ipc. RpcServer $ Handler. run (RpcServer. java: 1804)

3) Responder. Returns the Call result to RpcClient.

?" IPC Server Responder "daemon prio = 10 tid = 0x00007f7210a97000 nid = 0x14c5 runnable [0x00007f720e9d1000]
Java. lang. Thread. State: RUNNABLE
At sun. nio. ch. EPollArrayWrapper. epollWait (Native Method)
At sun. nio. ch. EPollArrayWrapper. poll (EPollArrayWrapper. java: 210)
At sun. nio. ch. EPollSelectorImpl. doSelect (EPollSelectorImpl. java: 65)
At sun. nio. ch. SelectorImpl. lockAndDoSelect (SelectorImpl. java: 69)
-Locked <0x00000000c4407078> (a sun. nio. ch. Util $2)
-Locked <0x00000000c4407060> (a java. util. Collections $ UnmodifiableSet)
-Locked <0x00000000c4345b68> (a sun. nio. ch. EPollSelectorImpl)
At sun. nio. ch. SelectorImpl. select (SelectorImpl. java: 80)
At org. apache. hadoop. hbase. ipc. RpcServer $ Responder. doRunLoop (RpcServer. java: 833)
At org. apache. hadoop. hbase. ipc. RpcServer $ Responder. run (RpcServer. java: 816)

RpcClient establishes a Connection for the Rpc request, sends the Call to RpcServer through the Connection, and then RpcClient waits for the result to be returned.

? Thoughts

1) Why does HBase use Protobuf in the new version and implement the RPC interface?

HBase is an important distributed database in the Hadoop ecosystem. Hadoop2.0 widely uses Protobuf as the intermediate data organization mode, and the unified requirements of Wire-Compatible in the entire system.

2) What is the impact of the Rpc framework implemented in HBase on service performance?

Currently, Protobuf is used as the data format for user requests and internal data exchange. It adopts a more compact encoding format to improve data transmission efficiency. However, some optimizations can still be explored within this framework:

Implement multiple Request reuse connections (Merge multiple short connections into one persistent Connection );

Create multiple CallQueue in the RpcServer to process different services separately, and separate the queues of management logic and application logic to ensure mutual interference;

Is Responder's single-threaded mode a bottleneck for High-concurrency applications?

Can I separate the queues occupied by Read/Write requests and handler processed to balance the Read/Write performance?

Based on the features of read/write applications, the applications are classified at the RpcServer level, and CallQueue with different priorities is established. According to the Hadoop-FairScheduler mode, then configure the central Scheduling (similar to OMega or Spallow lightweight scheduling scheme) to ensure the high throughput of real-time applications with low latency and non-real-time applications. A Call with a higher priority will be scheduled to Handler first, and a non-real-time application can merge multiple calls to increase the throughput.

3) can Protobuf built-in encoding be used in combination with traditional compression technology?

Tcpdump is used to obtain the information reported by the RegionServer obtained by the HMaster:

The above information is almost plain text in TCP/IP connections. Therefore, whether to adopt certain compression policies in Protobuf-RPC data format, it will provide an optimization idea for Data Interaction intensive applications such as scan and multiGet.

References:

[1] HBase Rpc Protocols :? Http://blog.zahoor.in/2012/08/protocol-buffers-in-hbase/

[2] HBase project 0.95.1
This series of articles is original in Binos_ICT personal technology blog in Binospace.

FromBinospace,PostIn-depth analysis of HBase RPC (Protobuf) Implementation Mechanism

The footer information of the article is automatically generated by WordPress's wp-posturl plug-in.

Copyright©2008
This feed is for personal, non-inclucial use only.
The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.