RPC 设计与实现
互联网架构演变(微观)
- 单一架构,以实现功能为目的,扩展性差 - 数据访问层问题
- 垂直架构,业务拆分,各司其职 - 控制层
M
|V
解耦
- 分布式服务,服务间的相互调度 - RPC
remote process call
- 流动式计算,伸缩性,扩展性 - SOA治理
高并发互联网架构设计(宏观)
-
X轴
:水平扩展,应用具有可复制性木桶原理
-
Y轴
:垂直拆分各司其职
泳道设计
-
Z轴
:将X/Y打包,做物理隔离
RPC 系统间通讯实现手段
-
即时消息-点对点 消息发送和接收方必须同时在线
WebService-SOAP
tcp/ip数据传输层
- 离线消息- 异步消息 不要求消息发送方和接收方同时在线
email
MQ
TCP/IP通讯 | UDP- 网络编程
-
IO 非常重要 BIO
/NIO
-
BIO
- FileInputStream、FileOutputStream
字节流
- BufferedReader/BufferedWriter
字符流
- InputStreamReader、OutputStreamWriter
桥转换
- PrintStream、PrintWriter
- ObjectInputStream|ObjectOutputStream
序列化
-
NIO
读
:磁盘 --> FileChannel#read–>ByteBuffer(变量)
写
:ByteBuffer(变量)–>FileChannel#write–>磁盘
只读FileChanel
: FileInputStream#getChannel();
可写FileChanel
: FileOutputStream#getChannel();
ByteBuffer常见操作
FileChannel inFileChannel=new FileInputStream("C:\\Users\\Administrator\\Desktop\\FeiQ2013.exe").getChannel();
FileChannel outFileChannel=new FileOutputStream("C:\\Users\\Administrator\\Desktop\\FeiQ2018.exe").getChannel();
//创建ByteBuffer
ByteBuffer buffer=ByteBuffer.allocate(1024);
while(true){
buffer.clear();
int n = inFileChannel.read(buffer);
if(n==-1) break;
buffer.flip();
outFileChannel.write(buffer);
}
inFileChannel.close
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)