Scalable IO in Java -Doug Lea

转载 2015年07月10日 23:07:58
Scalable IO in Java  -Doug Lea

Scalable network services
" Event-driven processing
" Reactor pattern
Basic version
Multithreaded versions
Other variants
" Walkthrough of java.nio nonblocking IO APIs

Network Services
Web services, Distributed Objects, etc
Most have same basic structure:
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, ...

Classic Service Designs
  Each handler may be started in its own thread

 Scalability Goals
" Graceful degradation under increasing load (more clients)
" Continuous improvement with increasing
resources (CPU, memory, disk, bandwidth)
" 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

Divide and Conquer
" Divide processing into small tasks
Each task performs an action without blocking
" Execute each task when it is enabled
Here, an IO event usually serves as trigger
Basic mechanisms supported in java.nio
Non-blocking reads and writes
Dispatch tasks associated with sensed IO events
" Endless variation possible
A family of event-driven designs
Event-driven Designs
" Usually more efficient than alternatives
Fewer resources
" Don't usually need a thread per client
Less overhead
" Less context switching, often less locking
But dispatching can be slower
" Must manually bind actions to events
" Usually harder to program
Must break up into simple non-blocking actions
" Similar to GUI event-driven actions
" Cannot eliminate all blocking: GC, page faults, etc
Must keep track of logical state of service
Background: Events in AWT
Event-driven IO uses similar ideas but in different designs

Reactor Pattern
" Reactor responds to IO events by dispatching
the appropriate handler
Similar to AWT thread
" Handlers perform non-blocking actions
Similar to AWT ActionListeners
" Manage by binding handlers to events
Similar to AWT addActionListener
" See Schmidt et al, Pattern-Oriented Software
Architecture, Volume 2 (POSA2)
Also Richard Stevens's networking books, Matt
Welsh's SEDA framework, etc

Basic Reactor Design
java.nio Support
" Channels
Connections to files, sockets etc that support
non-blocking reads
" Buffers
Array-like objects that can be directly read or
written by Channels
" Selectors
Tell which of a set of Channels have IO events
" SelectionKeys
Maintain IO event status and bindings

Multithreaded Designs
" Strategically add threads for scalability
Mainly applicable to multiprocessors
" Worker Threads
Reactors should quickly trigger handlers
" Handler processing slows down Reactor
Offload non-IO processing to other threads
" Multiple Reactor Threads
Reactor threads can saturate doing IO
Distribute load to other reactors
" Load-balance to match CPU and IO rates

Worker Threads
" Offload non-IO processing to speed up
Reactor thread
Similar to POSA2 Proactor designs
" Simpler than reworking compute-bound
processing into event-driven form
Should still be pure nonblocking computation
" Enough processing to outweigh overhead
" But harder to overlap processing with IO
Best when can first read all input into a buffer
" Use thread pool so can tune and control
Normally need many fewer threads than clients


  • 2003年04月30日 00:00
  • 676KB
  • 下载

Scalable IO in Java的代码实现

最近在学习NIO相关的知识部分,在学习的时候,发现Doug Lea大神的一个PPT地址,里面的内容写的非常好, 很值得学习,具体内容可以参见PPT和网上的文章,自己根据PPT中的例子和描述,自己将代码...
  • zxdfc
  • zxdfc
  • 2017年03月10日 22:30
  • 382

Scalable IO in Java——多Reactor的代码实现

首页 分类目录 文章归档 联系我 友情链接 Scalable IO in Java——多Reactor的代码实现  Published: 2015-...


对于同步事件的多路复用和分发的面向对象的行为模式 这篇文章早期的版本作为一章出现在“Pattern Languages of Program Design” ISBN 0-201-6073-4...

Scalable io in java

本文可看成是对Doug Lea Scalable IO in Java一文的翻译。当前分布式计算 Web Services盛行天下,这些网络服务的底层都离不开对socket的操作。他们都有一个共同的结...
  • liu251
  • liu251
  • 2008年07月06日 20:15
  • 1873

Scalable IO in Java -Doug Lea

  • 2015年07月10日 23:09
  • 269KB
  • 下载

关于util.concurrent工具包就有选择的介绍到这,更详细的信息可以阅读这些java源代码的API文档。Doug Lea是个很具有“open”精神的作者,他将util.concurrent工具

Sync:获得/释放(acquire/release) 协议。同步(定制锁、资源管理、其他同步) Channel:放置/取走(put/take) 协议。通信(缓冲和队列服务) Executor...

【Doug Lea系列】Java并发结构

原文链接: 作者:Doug Lea 译者:萧欢  校对:方腾飞 内容 线程同步监视器 ...
您举报文章:Scalable IO in Java -Doug Lea