So einfach geht modernes Roaming fuer Notes und Nomad.pdf
Apache MINA: The high-performance protocol construction toolkit.
1. (if you can’t read this, move closer!)
Apache
The high-performance protocol construction toolkit.
Peter Royal <proyal@apache.org>
Originally presented at ApacheCon US 2007 in
Atlanta, GA
Wednesday, November 14, 2007 1
2. Hi, I’m Peter
http://fotap.org/~osi
Wednesday, November 14, 2007 2
23. Wire
Protocol
Application
Logic
Rather than this...
Wednesday, November 14, 2007 23
24. Wire Application
Protocol Logic
Concerns are Separated
Wednesday, November 14, 2007 24
25. Stable and Production-
Ready
• v1.0 released Fall 2006
• v1.1 released April 2007
• Same API as v1.0 but uses Java 5 Concurrency primitives
• v2.0 this year
• API simplification based on lessons learned
• Performance boosts too!
Wednesday, November 14, 2007 25
26. Many Protocols & Users
(here are a few...)
Wednesday, November 14, 2007 26
27. Apache
Directory
http://directory.apache.org
LDAPv3, NTP, DNS, DHCP and
Kerberos
Wednesday, November 14, 2007 27
28. SubEthaSTMP
http://subethasmtp.tigris.org/
SMTP
Wednesday, November 14, 2007 28
34. ByteBuffer
• Core NIO construct
• MINA version that wraps and provides
additional convenience methods
• auto-expanding, string encoding
• MINA gives control...
• allocate from the Heap or Stack
• optional Pooling
• (in v2, will be non-pooled and heap-only, as it provides the best
performance)
Wednesday, November 14, 2007 34
35. Future
• Represents a function call that completes
asynchronously
• Provides blocking functions to retrieve the
result
• MINA allows callbacks to be invoked upon
completion, so invoking thread can “fire and
forget”
• (unlike the Java 5 Future)
Wednesday, November 14, 2007 35
37. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Two Versions
Wednesday, November 14, 2007 37
38. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
IoAcceptor
“act as server”
single thread for new connections
Wednesday, November 14, 2007 38
39. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
IoConnector
“act as client”
Wednesday, November 14, 2007 39
40. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Connection instance
is an IoSession
Wednesday, November 14, 2007 40
41. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Handles reads and writes
Wednesday, November 14, 2007 41
42. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Instance count scales
with CPU/Load
Wednesday, November 14, 2007 42
43. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Session fixed to an Instance
(under review for v2)
Wednesday, November 14, 2007 43
44. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Chain of IoFilter’s
Wednesday, November 14, 2007 44
45. Writes
IoProcessor
IoHandler
IoService
IoFilter
IoFilter
IoFilter
Reads
Per Connection
Wednesday, November 14, 2007 45
51. Protocol Conversion
• Framework to plug in your own codecs to
handle conversion to/from a ByteBuffer
• Existing codecs
• Text-based
• Java Serialization
Wednesday, November 14, 2007 51
65. IoProcessor threads
only do reads & writes
(the intent)
Wednesday, November 14, 2007 65
66. Filters execute on a
different thread.
(filter location is key!)
Wednesday, November 14, 2007 66
67. Work for a session is
serialized
(queued per session)
Wednesday, November 14, 2007 67
68. Work is delegated to an
Executor
(generally a java.util.concurrent.ThreadPoolExecutor)
Wednesday, November 14, 2007 68
69. Size thread pool to
“active” session count
(too much in queue == OOM!
Use the Read Throttle filter)
Wednesday, November 14, 2007 69
70. “recommended
application pattern”
• use ExecutorFilter as first in chain
• unless you need really low latency
• use ProtocolCodecFilter
• convert the wire protocol into a Java representation
• put application logic into an IoHandler
• store state in the IoSession
• minimum of Java 5
• java.util.concurrent rocks!
Wednesday, November 14, 2007 70