search
HomeDatabaseMysql Tutorial解析MapReduce原理–笔记(9)hadoopRPC基础

基本概念 模块 RPC 通常采用客户机/服务器模型。请求程序是客户机,服务提供程序则是一个服务器。包括以下几个模块 通信模块:两个相互协作的通信模块实现请求-应答协议。同步方式和异步方式。 Stub程序:客户端和服务器端均包含Stub程序,代理程序。它使得

基本概念
模块
RPC通常采用客户机/服务器模型。请求程序是客户机,服务提供程序则是一个服务器。包括以下几个模块
通信模块:两个相互协作的通信模块实现请求-应答协议。同步方式和异步方式。
Stub程序:客户端和服务器端均包含Stub程序,代理程序。它使得远程函数调用表现的跟本地调用一样,对用户程序完全透明。
在客户端,它表现的就像一个本地程序,但不直接执行本地调用,而是将请求信息通过网络模块发送给服务器端。
在服务器端,解码请求消息中的参数,调用相应的服务过程和编码应答结果的返回值。
调度程序:接收来自通信模块的请求消息,并根据其中的标识选择一个Stub程序处理。线程池处理。
客户程序/服务过程:请求的发出者和请求的处理者。
步骤
1.客户程序以本地方式调用系统产生的Stub程序。
2.该Stub程序将函数调用信息按照网络通信模块的要求封装成消息包。并交给通信模块发送到远程服务器端。
3.远程服务器端接收此消息后,将此消息发送给相应的Stub程序。
4.Stub程序拆封消息,形成被调过程要求的形式,并调用对应的函数。
5.被调用函数按照所获参数执行,并将结果返回给Stub程序。
6.Stub程序将此结果封装成消息,通过网络通信模块逐级地传送给客户程序。

HadoopRPC
接口:

public static VersionedProtocol getProxy/waitForProxy():构造一个客户端代理对象,用于向服务器发送RPC请求。public static Server getServer():为某个协议示例构造一个服务器对象,用于处理客户端发送的请求。

步骤:
1.定义RPC协议。RPC协议是客户端与服务器端之间的通信接口,它定义了服务器端对外提供的服务接口。interface ClientProtocol extends org.apache.hadoop.ipc.VersionedProtocol{public static final long versionID=1L;String echo(String value) throws IOException;int add(int v1,int v2) throws IOException;}2.实现RPC协议。public static class ClientProtocolImpl implements ClientProtocl{public long getProtocolVersion(String protocol,long clientVersion){return ClientProtocol.versionID ;}public String echo(String value) throws IOException{return value;}public int add(int v1,int v2) throws IOException{return v1+v2;}}3.构造并启动RPC Serverserver = RPC.getServer(new ClientProtocolImpl(),serverHost,serverPort,numHandlers,false,conf);//numHandlers表示服务器端处理请求的线程数目。server.start();4.构造RPC Client,并发送RPC请求。proxy = (ClientProtocol)RPC.getProxy(ClientProtocol.class,ClientProtocol.versionID,addr,conf);int result = proxy.add(4,5);String echoResult = proxy.echo("hello");
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.