(if you can’t read this, move closer!)




                          Apache
                     The high-performance prot...
Hi, I’m Peter
                                http://fotap.org/~osi

Wednesday, November 14, 2007                         ...
MINA hacker since
                         Fall 2005


Wednesday, November 14, 2007              3
Radar Networks
                               http://radarnetworks.com

Wednesday, November 14, 2007                      ...
San Francisco
Wednesday, November 14, 2007                   5
Apache Member
                                  http://apache.org

Wednesday, November 14, 2007                          6
What is MINA?



Wednesday, November 14, 2007                   7
MINA?
Wednesday, November 14, 2007           8
Multipurpose
                   Infrastructure
                   Networked
                   Applications
              ...
Built on Java NIO



Wednesday, November 14, 2007                  10
Non-Blocking



Wednesday, November 14, 2007                  11
Asynchronous



Wednesday, November 14, 2007                  12
Event-Driven
                                   (SEDA!)




Wednesday, November 14, 2007                  13
Multiple Transports
                               (framework is really agnostic)




Wednesday, November 14, 2007        ...
TCP



Wednesday, November 14, 2007         15
UDP
                               (being re-written for 2.0)




Wednesday, November 14, 2007                            ...
In-VM
                               (great for testing)




Wednesday, November 14, 2007                         17
Apache Portable
                           Runtime (APR)
                               (under development, alternate
    ...
(and more..)



Wednesday, November 14, 2007                  19
Smartly Designed



Wednesday, November 14, 2007                 20
Follows Inversion of
                      Control Pattern
                      (plays nicely with PicoContainer, Spring,...
Separation of Concerns



Wednesday, November 14, 2007          22
Wire
                                Protocol
                               Application
                                 ...
Wire     Application
                     Protocol     Logic




            Concerns are Separated
Wednesday, November 14...
Stable and Production-
                        Ready
              • v1.0 released Fall 2006
              • v1.1 released...
Many Protocols & Users
                               (here are a few...)




Wednesday, November 14, 2007                ...
Apache
                Directory
           http://directory.apache.org

       LDAPv3, NTP, DNS, DHCP and
               ...
SubEthaSTMP
         http://subethasmtp.tigris.org/

                               SMTP




Wednesday, November 14, 2007 ...
Apache
               (incubating)
                   Qpid
          http://cwiki.apache.org/qpid/

        Advanced Messa...
Openfire
         http://www.jivesoftware.com/
               products/openfire/

                               XMPP




We...
red5
          http://www.osflash.org/red5

                        RTMP
                (talk to Flash player)




Wednesd...
...and more!
                               (maybe you, next time!)




Wednesday, November 14, 2007                      ...
Key Concepts



Wednesday, November 14, 2007                  33
ByteBuffer
              • Core NIO construct
              • MINA version that wraps and provides
                    add...
Future
              • Represents a function call that completes
                    asynchronously
              • Provid...
36




         IoHandler
Writes




           IoFilter
           IoFilter
           IoFilter
                       Re...
Writes




                                            IoProcessor




                                                   ...
Writes




                                                IoProcessor




                                               ...
Writes




                                             IoProcessor




                                                  ...
Writes




                                           IoProcessor




                                                    ...
Writes




                                           IoProcessor




                                                    ...
Writes




                                           IoProcessor




                                                    ...
Writes




                                           IoProcessor




                                                    ...
Writes




                                           IoProcessor




                                                    ...
Writes




                                             IoProcessor




                                                  ...
46




         IoHandler
Writes




           IoFilter
           IoFilter
                               Reusable
     ...
Writes




                                             IoProcessor




                                                  ...
Writes




                                             IoProcessor




                                                  ...
Writes




                                           IoProcessor




                                                    ...
Large Library of
                                  IoFilter’s


Wednesday, November 14, 2007                      50
Protocol Conversion

              • Framework to plug in your own codecs to
                    handle conversion to/from...
Blacklist



Wednesday, November 14, 2007               52
Logging
                               (great for debugging!)




Wednesday, November 14, 2007                            53
SSL / TLS



Wednesday, November 14, 2007               54
Compression



Wednesday, November 14, 2007                 55
Read Throttling
                                 (write throttling is in 2.0)




Wednesday, November 14, 2007            ...
Thread Models
                                  (a necessary evil)




Wednesday, November 14, 2007                       ...
“single threaded”



Wednesday, November 14, 2007                  58
One IoProcessor
                              Thread


Wednesday, November 14, 2007                59
Scalability sucks



Wednesday, November 14, 2007                       60
Add more IoProcessor
                    Threads
                               (at least one per CPU core)




Wednesday,...
Lowest latency
                                Scales nicely
                       (connection latency to be addressed in...
“multi threaded”



Wednesday, November 14, 2007                  63
use ExecutorFilter



Wednesday, November 14, 2007                 64
IoProcessor threads
               only do reads & writes
                               (the intent)




Wednesday, Novem...
Filters execute on a
                       different thread.
                               (filter location is key!)




...
Work for a session is
                      serialized
                               (queued per session)




Wednesday, ...
Work is delegated to an
                  Executor
              (generally a java.util.concurrent.ThreadPoolExecutor)



...
Size thread pool to
                “active” session count
                               (too much in queue == OOM!
     ...
“recommended
                      application pattern”
              • use ExecutorFilter as first in chain
              ...
Example Time!



Wednesday, November 14, 2007                   71
Everybody loves a Haiku



Wednesday, November 14, 2007         72
This is our Haiku validator
Wednesday, November 14, 2007         73
Simple Protocol

              • Connect
              • Send 3 lines of text
              • Receive HAIKU! or NOT A HAIK...
ProtocolCodecFilter +
               TextLineCodecFactory
                               Bytes to Java String’s. For free!...
ToHaikuIoFilter
                                 Three String’s to a Haiku
Wednesday, November 14, 2007                   ...
Filter is very testable
                               (mock objects rock!)
Wednesday, November 14, 2007                  ...
IoHandler is very simple
                               Validate Haiku, send result
Wednesday, November 14, 2007          ...
Also very testable
Wednesday, November 14, 2007                  79
Very easy to hook it all up
Wednesday, November 14, 2007          80
Questions?
                                (I’m here all week!)
Wednesday, November 14, 2007                           81
Thank You!
Wednesday, November 14, 2007                82
http://mina.apache.org



Wednesday, November 14, 2007             83
Upcoming SlideShare
Loading in...5
×

Apache MINA: The high-performance protocol construction toolkit.

10,680

Published on

An introduction to Apache MINA, a toolkit for building scalable clients and servers in Java leveraging NIO.

Published in: Technology, Education
1 Comment
14 Likes
Statistics
Notes
No Downloads
Views
Total Views
10,680
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
428
Comments
1
Likes
14
Embeds 0
No embeds

No notes for slide

Apache MINA: The high-performance protocol construction toolkit.

  1. 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. 2. Hi, I’m Peter http://fotap.org/~osi Wednesday, November 14, 2007 2
  3. 3. MINA hacker since Fall 2005 Wednesday, November 14, 2007 3
  4. 4. Radar Networks http://radarnetworks.com Wednesday, November 14, 2007 4
  5. 5. San Francisco Wednesday, November 14, 2007 5
  6. 6. Apache Member http://apache.org Wednesday, November 14, 2007 6
  7. 7. What is MINA? Wednesday, November 14, 2007 7
  8. 8. MINA? Wednesday, November 14, 2007 8
  9. 9. Multipurpose Infrastructure Networked Applications http://mina.apache.org Wednesday, November 14, 2007 9
  10. 10. Built on Java NIO Wednesday, November 14, 2007 10
  11. 11. Non-Blocking Wednesday, November 14, 2007 11
  12. 12. Asynchronous Wednesday, November 14, 2007 12
  13. 13. Event-Driven (SEDA!) Wednesday, November 14, 2007 13
  14. 14. Multiple Transports (framework is really agnostic) Wednesday, November 14, 2007 14
  15. 15. TCP Wednesday, November 14, 2007 15
  16. 16. UDP (being re-written for 2.0) Wednesday, November 14, 2007 16
  17. 17. In-VM (great for testing) Wednesday, November 14, 2007 17
  18. 18. Apache Portable Runtime (APR) (under development, alternate TCP/UDP implementation) Wednesday, November 14, 2007 18
  19. 19. (and more..) Wednesday, November 14, 2007 19
  20. 20. Smartly Designed Wednesday, November 14, 2007 20
  21. 21. Follows Inversion of Control Pattern (plays nicely with PicoContainer, Spring, etc) Wednesday, November 14, 2007 21
  22. 22. Separation of Concerns Wednesday, November 14, 2007 22
  23. 23. Wire Protocol Application Logic Rather than this... Wednesday, November 14, 2007 23
  24. 24. Wire Application Protocol Logic Concerns are Separated Wednesday, November 14, 2007 24
  25. 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. 26. Many Protocols & Users (here are a few...) Wednesday, November 14, 2007 26
  27. 27. Apache Directory http://directory.apache.org LDAPv3, NTP, DNS, DHCP and Kerberos Wednesday, November 14, 2007 27
  28. 28. SubEthaSTMP http://subethasmtp.tigris.org/ SMTP Wednesday, November 14, 2007 28
  29. 29. Apache (incubating) Qpid http://cwiki.apache.org/qpid/ Advanced Messaging Queuing Protocol (AMQP) (from Wall Street!) Wednesday, November 14, 2007 29
  30. 30. Openfire http://www.jivesoftware.com/ products/openfire/ XMPP Wednesday, November 14, 2007 30
  31. 31. red5 http://www.osflash.org/red5 RTMP (talk to Flash player) Wednesday, November 14, 2007 31
  32. 32. ...and more! (maybe you, next time!) Wednesday, November 14, 2007 32
  33. 33. Key Concepts Wednesday, November 14, 2007 33
  34. 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. 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
  36. 36. 36 IoHandler Writes IoFilter IoFilter IoFilter Reads IoProcessor IoService Wednesday, November 14, 2007
  37. 37. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Two Versions Wednesday, November 14, 2007 37
  38. 38. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads IoAcceptor “act as server” single thread for new connections Wednesday, November 14, 2007 38
  39. 39. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads IoConnector “act as client” Wednesday, November 14, 2007 39
  40. 40. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Connection instance is an IoSession Wednesday, November 14, 2007 40
  41. 41. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Handles reads and writes Wednesday, November 14, 2007 41
  42. 42. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Instance count scales with CPU/Load Wednesday, November 14, 2007 42
  43. 43. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Session fixed to an Instance (under review for v2) Wednesday, November 14, 2007 43
  44. 44. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Chain of IoFilter’s Wednesday, November 14, 2007 44
  45. 45. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Per Connection Wednesday, November 14, 2007 45
  46. 46. 46 IoHandler Writes IoFilter IoFilter Reusable IoFilter Reads IoProcessor IoService Wednesday, November 14, 2007
  47. 47. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Hot Deployable Wednesday, November 14, 2007 47
  48. 48. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Filter all events Read / Write / Idle / etc Wednesday, November 14, 2007 48
  49. 49. Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Application Logic Lives Here Wednesday, November 14, 2007 49
  50. 50. Large Library of IoFilter’s Wednesday, November 14, 2007 50
  51. 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
  52. 52. Blacklist Wednesday, November 14, 2007 52
  53. 53. Logging (great for debugging!) Wednesday, November 14, 2007 53
  54. 54. SSL / TLS Wednesday, November 14, 2007 54
  55. 55. Compression Wednesday, November 14, 2007 55
  56. 56. Read Throttling (write throttling is in 2.0) Wednesday, November 14, 2007 56
  57. 57. Thread Models (a necessary evil) Wednesday, November 14, 2007 57
  58. 58. “single threaded” Wednesday, November 14, 2007 58
  59. 59. One IoProcessor Thread Wednesday, November 14, 2007 59
  60. 60. Scalability sucks Wednesday, November 14, 2007 60
  61. 61. Add more IoProcessor Threads (at least one per CPU core) Wednesday, November 14, 2007 61
  62. 62. Lowest latency Scales nicely (connection latency to be addressed in v2) Wednesday, November 14, 2007 62
  63. 63. “multi threaded” Wednesday, November 14, 2007 63
  64. 64. use ExecutorFilter Wednesday, November 14, 2007 64
  65. 65. IoProcessor threads only do reads & writes (the intent) Wednesday, November 14, 2007 65
  66. 66. Filters execute on a different thread. (filter location is key!) Wednesday, November 14, 2007 66
  67. 67. Work for a session is serialized (queued per session) Wednesday, November 14, 2007 67
  68. 68. Work is delegated to an Executor (generally a java.util.concurrent.ThreadPoolExecutor) Wednesday, November 14, 2007 68
  69. 69. Size thread pool to “active” session count (too much in queue == OOM! Use the Read Throttle filter) Wednesday, November 14, 2007 69
  70. 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
  71. 71. Example Time! Wednesday, November 14, 2007 71
  72. 72. Everybody loves a Haiku Wednesday, November 14, 2007 72
  73. 73. This is our Haiku validator Wednesday, November 14, 2007 73
  74. 74. Simple Protocol • Connect • Send 3 lines of text • Receive HAIKU! or NOT A HAIKU: • (plus a little reason why not) Wednesday, November 14, 2007 74
  75. 75. ProtocolCodecFilter + TextLineCodecFactory Bytes to Java String’s. For free! Wednesday, November 14, 2007 75
  76. 76. ToHaikuIoFilter Three String’s to a Haiku Wednesday, November 14, 2007 76
  77. 77. Filter is very testable (mock objects rock!) Wednesday, November 14, 2007 77
  78. 78. IoHandler is very simple Validate Haiku, send result Wednesday, November 14, 2007 78
  79. 79. Also very testable Wednesday, November 14, 2007 79
  80. 80. Very easy to hook it all up Wednesday, November 14, 2007 80
  81. 81. Questions? (I’m here all week!) Wednesday, November 14, 2007 81
  82. 82. Thank You! Wednesday, November 14, 2007 82
  83. 83. http://mina.apache.org Wednesday, November 14, 2007 83
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×