Apache MINA: The high-performance protocol construction toolkit.

50 %
50 %
Information about Apache MINA: The high-performance protocol construction toolkit.

Published on November 14, 2007

Author: osi

Source: slideshare.net

Description

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

(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

Hi, I’m Peter http://fotap.org/~osi Wednesday, November 14, 2007 2

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

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

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 http://mina.apache.org Wednesday, November 14, 2007 9

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 14

TCP Wednesday, November 14, 2007 15

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

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

Apache Portable Runtime (APR) (under development, alternate TCP/UDP implementation) Wednesday, November 14, 2007 18

(and more..) Wednesday, November 14, 2007 19

Smartly Designed Wednesday, November 14, 2007 20

Follows Inversion of Control Pattern (plays nicely with PicoContainer, Spring, etc) Wednesday, November 14, 2007 21

Separation of Concerns Wednesday, November 14, 2007 22

Wire Protocol Application Logic Rather than this... Wednesday, November 14, 2007 23

Wire Application Protocol Logic Concerns are Separated Wednesday, November 14, 2007 24

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

Many Protocols & Users (here are a few...) Wednesday, November 14, 2007 26

Apache Directory http://directory.apache.org LDAPv3, NTP, DNS, DHCP and Kerberos Wednesday, November 14, 2007 27

SubEthaSTMP http://subethasmtp.tigris.org/ SMTP Wednesday, November 14, 2007 28

Apache (incubating) Qpid http://cwiki.apache.org/qpid/ Advanced Messaging Queuing Protocol (AMQP) (from Wall Street!) Wednesday, November 14, 2007 29

Openfire http://www.jivesoftware.com/ products/openfire/ XMPP Wednesday, November 14, 2007 30

red5 http://www.osflash.org/red5 RTMP (talk to Flash player) Wednesday, November 14, 2007 31

...and more! (maybe you, next time!) Wednesday, November 14, 2007 32

Key Concepts Wednesday, November 14, 2007 33

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

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 IoHandler Writes IoFilter IoFilter IoFilter Reads IoProcessor IoService Wednesday, November 14, 2007

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Two Versions Wednesday, November 14, 2007 37

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads IoAcceptor “act as server” single thread for new connections Wednesday, November 14, 2007 38

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads IoConnector “act as client” Wednesday, November 14, 2007 39

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Connection instance is an IoSession Wednesday, November 14, 2007 40

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Handles reads and writes Wednesday, November 14, 2007 41

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Instance count scales with CPU/Load Wednesday, November 14, 2007 42

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Session fixed to an Instance (under review for v2) Wednesday, November 14, 2007 43

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Chain of IoFilter’s Wednesday, November 14, 2007 44

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Per Connection Wednesday, November 14, 2007 45

46 IoHandler Writes IoFilter IoFilter Reusable IoFilter Reads IoProcessor IoService Wednesday, November 14, 2007

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Hot Deployable Wednesday, November 14, 2007 47

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Filter all events Read / Write / Idle / etc Wednesday, November 14, 2007 48

Writes IoProcessor IoHandler IoService IoFilter IoFilter IoFilter Reads Application Logic Lives Here Wednesday, November 14, 2007 49

Large Library of IoFilter’s Wednesday, November 14, 2007 50

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

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 56

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

“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, November 14, 2007 61

Lowest latency Scales nicely (connection latency to be addressed in v2) Wednesday, November 14, 2007 62

“multi threaded” Wednesday, November 14, 2007 63

use ExecutorFilter Wednesday, November 14, 2007 64

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

Filters execute on a different thread. (filter location is key!) Wednesday, November 14, 2007 66

Work for a session is serialized (queued per session) Wednesday, November 14, 2007 67

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

Size thread pool to “active” session count (too much in queue == OOM! Use the Read Throttle filter) Wednesday, November 14, 2007 69

“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

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 HAIKU: • (plus a little reason why not) Wednesday, November 14, 2007 74

ProtocolCodecFilter + TextLineCodecFactory Bytes to Java String’s. For free! Wednesday, November 14, 2007 75

ToHaikuIoFilter Three String’s to a Haiku Wednesday, November 14, 2007 76

Filter is very testable (mock objects rock!) Wednesday, November 14, 2007 77

IoHandler is very simple Validate Haiku, send result Wednesday, November 14, 2007 78

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

Add a comment

Related presentations

Related pages

Introduction to MINA - Apache MINA

The high-performance protocol construction toolkit. Apache Peter Royal Originally presented at ApacheCon US 2007 in Atlanta, GA
Read more

Documentation — Apache MINA

Documentation ¶ The MINA 2.0 User ... The High Performance Protocol Construction Toolkit (ApacheCon US 2007) ... Apache MINA, MINA, Apache Vysper, ...
Read more

Apache MINA: The high-performance protocol construction ...

(if you can’t read this, move closer!) Apache The high-performance protocol construction toolkit.
Read more

Apache_MINA_The_High_Performance_Protoco Java ... - pudn.com

Apache MINA - The High Performance Protocol Construction ... apache mina high performance mina the high-performance protocal construction toolkit ...
Read more

Documentation - Apache MINA - Apache Software Foundation

... The High Performance Protocol Construction Toolkit ... Building TCP/IP Servers with Apache MINA ... Source Project License granted to Apache Software ...
Read more

apache-mina-the-high-performance-protocol-construction ...

首页 >IT资料 >IT书籍 >apache-mina-the-high-performance-protocol-const… apache-mina-the-high-performanc…举报. 简介: Apache Mina ...
Read more

Conferences - Apache MINA - Apache Software Foundation

Apache MINA. Pages; Blog; Child pages ...
Read more

Introduction to MINA - ApacheCon

The high-performance protocol construction toolkit. Apache Peter Royal Originally presented at ApacheCon Europe 2007 in Amsterdam
Read more

深入理解Apache Mina (4)---- IoFilter和 ... - CSDN.NET

深入理解Apache Mina (4)---- IoFilter和 ... 在Mina的官方文档《The high-performance protocol construction toolkit》给出了IoFilter ...
Read more