第一次翻译,如有错误,请指正
1、Outline 大纲
Scalable network services 高效网络服务
Event-driven processing 事件驱动处理
Reactor pattern Reactor模式
Basic version 基本版本
Multithreaded versions 多线程版本
Other variants 其他变体
2、Network Services 网络服务
Web services, Distributed Objects, etcMost have same basic structure。web服务,分布式对象,等等, 大多是相同的基础结构
Read request 读请求
Decode request 解码请求
Process service 服务处理
Encode reply 加密回复
Send reply。发送响应
But differ in nature and cost of each step XML parsing, File transfer, Web page generation, computational services, ...
但是不同的是每一步的XML解析,文件传输、web网页生成,服务计算
3、Classic Service Designs 经典的服务设计
Each handler may be started in its own thread 每一个handler在自己的线程中启动
4、classic ServerSocket Loop 经典的ServerSocket循环
public class Server implements Runnable{ @Override public void run() { try { ServerSocket serverSocket = new ServerSocket(123456); while (!Thread.interrupted()){ new Thread(new Handler(serverSocket.accept())).start(); } } catch (IOException e) { e.printStackTrace(); } } static class Handler implements Runnable{ final Socket socket; public Handler(Socket socket) { this.socket = socket; } @Override public void run() { try { byte[] input = new byte[]; socket.getInputStream().read(input); byte[] output = process(input); socket.getOutputStream().write(output); } catch (IOException e) { e.printStackTrace(); } } private byte[] process(byte[] input) { return null; } } }
5、Scalability Goals 可伸缩目标
Graceful degradation under increasing load (more clients)
负载下(更多客户端)的优雅降级
Continuous improvement with increasing resources (CPU, memory, disk, bandwidth)
随着资源(CPU、内存、硬盘、带宽)的增加而不断改进
Also meet availability and performance goals Short latencies Meeting peak demand Tunable quality of service
可协调服务同时满足高峰需求的可用性和短延时的性能目标
Divide-and-conquer is usually the best approach for achieving any scalability goal
分而治之通常是实现任何可伸缩性目标最好的方法
6、Divide and Conquer 分而治之
Divide processing into small tasks 拆分小任务处理
Each task performs an action without blocking 每个任务执行无阻塞的执行一个动作
Execute each task when it is enabled 当执行每一个任务时,
an IO event usually serves as trigger IO事件通常用作触发器
Basic mechanisms supported in java.nio java.nio支持的基本机制
Non-blocking reads and writes 非阻塞读写
Dispatch tasks associated with sensed IO events 调度与感知IO事件相关的任务
Endless variation possible 无尽的变化
A family of event-driven designs 一系列事件驱动设计
degradation 退化
latency 潜在的
tunable 可调协的