踏着前人的脚印学hadoop——ipc中的Client
1、Client有五个内部类,分别是Call,ParallelCall,ParallelResult,Connetion,ConnectionId
其实这五个类就是去完成两件事情的,一件事情是连接,另外一件事情是调用,而连接呢主要通过Connection来完成,ConnectionId是它的辅助类。调用呢,Call为主,由于会同时和NameNode和其他DataNode通讯,所以需要一个ParallelCall来完成这件事,调用完了总有个返回值吧,所以要有ParallelResult这个类。
2、先来看ConnectionId
This class holds the address and the user ticket. The client connections to servers are uniquely identified by <remoteAddress, protocol, ticket>这个是源码的解释,
下边有10个属性,最核心也就是address,ticket,protocol,连接相关的有rpcTimeout,serverPrincipal,maxIdleTime,connectionRetryPolicy,tcpNoDelay,pingInterval
Nagle算法是以他的发明人John Nagle的名字命名的,它用于自动连接许多的小缓冲器消息;这一过程(称为nagling)通过减少必须发送包的个数来增加网络软件系统的效率。Nagle的算 法通常会在TCP程 序里添加两行代码,在未确认数据发送的时候让发送器把数据送到缓存里。任何数据随后继续直到得到明显的数据确认或者直到攒到了一定数量的数据了再发包。
InetSocketAddress address;
UserGroupInformation ticket;
Class<?> protocol;
private static final int PRIME = 16777619;//这个家伙也就是在hashcode里边用了一下
private int rpcTimeout;
private String serverPrincipal;
private int maxIdleTime; //connections will be culled if it was idle for maxIdleTime msecs
private final RetryPolicy connectionRetryPolicy;
private boolean tcpNoDelay; // if T then disable Nagle's Algorithm
private int pingInterval; // how often sends ping to the server in msecs
3、再来看看Connection,
Thread that reads responses and notifies callers. Each connection owns a socket connected to a remote address. Calls are multiplexed through this socket: responses may be delivered out of order.
这个家伙继承了Thread这个类,主要读取相应通知调用者,每个连接都维护一个到远端的连接。调用时多路复用:响应不是按序的?
里边也包含了一个内部类PingInputStream
This class sends a ping to the remote side when timeout on reading. If no failure is detected, it retries until at least a byte is read.
如果没有检测到失败,它会坚持重试到最后一个字节被读取
private class PingInputStream extends FilterInputStream {}
下面的属性
private InetSocketAddress server; // server ip:port,这个ConnectionId里边有
private String serverPrincipal; // server's krb5 principal name kerberos这个是一种安全认证系统,如果失败了会用SASL :简单认证与安全层(Simple Authentication And Security Layer),简单认证和安全层,简单身份验证和安全层 ?
private ConnectionHeader header; // connection header
private final ConnectionId remoteId; // connection id
private AuthMethod authMethod; // authentication method
private boolean useSasl;
private Token<? extends TokenIdentifier> token;
private SaslRpcClient saslRpcClient;
private Socket socket = null; // connected socket
private DataInputStream in;
private DataOutputStream out;
下面这几个ConnectionId里边也有
private int rpcTimeout;
private int maxIdleTime; //connections will be culled if it was idle for maxIdleTime msecs
private final RetryPolicy connectionRetryPolicy;
private boolean tcpNoDelay; // if T then disable Nagle's Algorithm
private int pingInterval; // how often sends ping to the server in msecs
// currently active calls,并发的这几个要注意下,自己不是很熟,以前自己也没见过把Exception定义为属性变量
private Hashtable<Integer, Call> calls = new Hashtable<Integer, Call>();
private AtomicLong lastActivity = new AtomicLong();// last I/O activity time
private AtomicBoolean shouldCloseConnection = new AtomicBoolean(); // indicate if the connection is closed
private IOException closeException; // close reason
4、上边的calls里边出现了Call这个类,
A call waiting for a value.
这个简单,就5个属性,分别是id,参数,返回值,异常,结束标志位,平时我们一个方法调用也不过是个参数列表,返回值,异常,只不过这个加了个id和结束标志位done。
int id; // call id
Writable param; // parameter
Writable value; // value, null if error
IOException error; // exception, null if value
boolean done; // true when call is done
5、在看看这个ParallelCall
Call implementation used for parallel calls.
这个里边就两个属性,当然它继承至Call的属性暂时忽略
private ParallelResults results;
private int index;
6、上面的第一个属性ParallelResults,看看这个内部类
Result collector for parallel calls.
三个属性,也很简单
private Writable[] values;// store the value
private int size;//if (count == size) notify(); // if all values are in then notify waiting caller
private int count; // count it
踏着前人的脚印学hadoop——ipc中的Client的更多相关文章
- 踏着前人的脚印学hadoop——ipc中的Server
1.An abstract IPC service. IPC calls take a single {@link Writable} as a parameter, and return a {@ ...
- 踏着前人的脚印学Hadoop——RPC源码
A simple RPC mechanism.A protocol is a Java interface. All parameters and return types must be one ...
- 踏着前人的脚印学Hadoop——结构、重点
HDFS作为一个分布式文件系统,是所有这些项目的基础.分析好HDFS,有利于了解其他系统.由于Hadoop的HDFS和MapReduce是同一个项目,我们就把他们放在一块,进行分析. 如果把整个had ...
- 踏着前人的脚印学Hadoop——序列化,Writerable
package org.apache.hadoop.io; import java.io.DataOutput;import java.io.DataInput;import java.io.IOEx ...
- org.apache.hadoop.ipc.RemoteException(java.io.IOException)
昨晚突然之间mr跑步起来了 jps查看 进程都在的,但是在reduce任务跑了85%的时候会抛异常 异常情况如下: 2016-09-21 21:32:28,538 INFO [org.apache.h ...
- Hadoop IPC的代码结构分析
与IPC相关的代码在org.apache.hadoop.ipc包下.共七个文件,其中4个辅助类: RemoteException Status VersionedProtocol Connection ...
- 一张图解释Hadoop IPC
基于hadoop2.6.2.... 一张图Server启动,Client访问..... RPC是IPC的一种,IPC还有另外一种LPC,相关请看参考中的3 使用hadoop ipc步骤: 1.定义RP ...
- 运行基准测试hadoop集群中的问题:org.apache.hadoop.ipc.RemoteException: java.io.IOException: File /benchmarks/TestDFSIO/io_data/test_
在master(即:host2)中执行 hadoop jar hadoop-test-1.1.2.jar DFSCIOTest -write -nrFiles 12 -fileSize 10240 - ...
- hive运行query语句时提示错误:org.apache.hadoop.ipc.RemoteException: java.io.IOException: java.io.IOException:
hive> select product_id, track_time from trackinfo limit 5; Total MapReduce jobs = 1 Launching Jo ...
随机推荐
- 转:21副GIF动图让你了解各种数学概念
21副GIF动图让你了解各种数学概念
- JAVA EE 第一阶段项目问题
一: 乱码 原因: 由于同组的其他同学的myeclipse默认的编码方式是GBK,而我的默认的是UTF-8.所以当我使用svn把其他同学提交到组长那里去的代码下载下来的时候,就全乱码了! 解决问题: ...
- listToString
http://www.oschina.net/code/snippet_109648_2229
- JSON对象如何转化为字符串?
序列化 定义 指将 JavaScript 值转化为 JSON 字符串的过程. JSON.stringify() 能够将 JavaScript 值转换成 JSON 字符串.JSON.stringify( ...
- Django缓存优化之redis
Redis 概述 Redis 是一个开源的Inmemory key-value 存储系统,性能高,很大程度上补偿了 memcached 的不足.支持多种存储类型,包括 string, list, se ...
- 销售 >> 当今社会生产力最大的源泉为 >>自助服务 与推销员随之消失
销售可能是变化最大的企业职能.比如,经济学家喜欢提出陷阱问题“什么概念或者想法成为当今社会生产力最大的源泉?” 大多数人回答计算机, 正确的回答是自助服务与推销员随之消失 ...
- Windows 调色板
目录 第1章调色板 1 1.1 为什么要使用调色板 1 1.2 使用调色板 2 1.2.1 创建逻辑调色板 2 1.2.2 使用 3 1.2.3 销毁逻辑调色板 4 ...
- 【转】 STL中的set容器的一点总结
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构 ...
- 三种语言(c++、as、lua)中函数的差异性
对于不同的语言, 尤其是静态语言和动态语言, 对于函数的定义(即如何看待一个函数)和处理截然不同.具体来说可以分为两类: 1.将函数视为第一类型值, 即函数和其他的对象一样, 都是语言中一个普通的对象 ...
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...