Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Building High Performance
Scalable TCP/IP Servers with
Apache MINA
Originally presented at ApacheCon Europe 2006 in Dublin...
Goals of this presentation
•Introduction to MINA
•Demonstration of what it can do
•Converting blocking-IO code to MINA
•Ho...
What is MINA
•Multipurpose Infrastructure for Networked Applications
•A framework (the F word!) for building networked cli...
Brief history of MINA
•Started out as Netty2 from Trustin Lee
•Joined the Directory Project as the SEDA-based directory
 n...
IoHandler




             IoFilter




                         Inbound
             IoFilter
Outbound




             I...
IoSession
•Holder of state for a connection (either client-side or
 server-side)
•Passed along with every event
•Important...
IoHandler
•Akin to a Servlet           IoHandler



•Endpoint of a filter chain
                               IoFilter


•...
IoFilterChain
•Chain of IoFilter's for each IoSession
•Can setup template chains per IoConnector/IoAcceptor
•Dynamic addit...
IoFilters
•Akin to a ServletFilter            IoHandler



•View/Hack/Slash the event stream
                             ...
IoAcceptor
•Server-side entry point.                IoHandler



•Accepts incoming connections and fires
                  ...
IoConnector
•Client-side entry point
•Initiate connections to a remote service, and fires events to
 an IoHandler
•Importan...
IoProcessor
•Internal component                       IoHandler



•Handles reading and writing data to an
               ...
Our Sample Application
•Persistent connections from clients
•Serialize java objects across the wire
•Clients connect and a...
Monitoring Performance
•Thread activity via jconsole
•CPU Activity via Activity Monitor
  •(or your favorite tool)




   ...
Limitations

              15
Scalability
•JVM limit on number of threads
•The lovely java.lang.OutOfMemoryError: unable to
 create new native thread


...
Lets convert to MINA!
•Server side first
  •(Client to come soon)




                           17
Re-testing

             18
New Limitations?
•Java Serialization takes up CPU time
  •(a profiler would reveal this)
•OS limit of per-process open files...
MINA on the client
•Since we will be using MINA's built-in support for building
 protocols, the ProtocolCodecFilter
  •Any...
Client is just like the server
•IoHandler and IoFilter's
•Can re-use filters on both client and server sides.




         ...
Implementing the protocol.

                             22
It still works!

                  23
Filters that ship today
•Logging
•Compression
•Blacklist
•SSL
  •Requires Java 5




                          24
Filters we are working on
•Traffic Shaping
•Rate Limiting
•Performance Monitoring




                            25
Some things built on MINA
•LDAP - Apache DS <http://directory.apache.org/
 subprojects/apacheds/index.html>

•Flash - red5...
Performance Tips
•Set the number of IoProcessor’s to be equal to the number
 of CPU cores.

•Benchmark! Users have found b...
Questions?

             28
Thank You!

             29
Upcoming SlideShare
Loading in …5
×

Building High Performance Scalable TCP/IP Servers with Apache MINA

5,001 views

Published on

Published in: Technology
  • Be the first to comment

Building High Performance Scalable TCP/IP Servers with Apache MINA

  1. 1. Building High Performance Scalable TCP/IP Servers with Apache MINA Originally presented at ApacheCon Europe 2006 in Dublin Latest slides and code samples at http://people.apache.org/~proyal Presented by Peter Royal, <proyal@apache.org> 1
  2. 2. Goals of this presentation •Introduction to MINA •Demonstration of what it can do •Converting blocking-IO code to MINA •Hopefully inspire you to use it :) 2
  3. 3. What is MINA •Multipurpose Infrastructure for Networked Applications •A framework (the F word!) for building networked clients and servers based on non-blocking IO •http://directory.apache.org/subprojects/mina/ 3
  4. 4. Brief history of MINA •Started out as Netty2 from Trustin Lee •Joined the Directory Project as the SEDA-based directory needed an asynchronous I/O layer. 4
  5. 5. IoHandler IoFilter Inbound IoFilter Outbound IoFilter IoProcessor IoAcceptor Network Architectural overview 5
  6. 6. IoSession •Holder of state for a connection (either client-side or server-side) •Passed along with every event •Important Methods •write •close •get/setAttribute 6
  7. 7. IoHandler •Akin to a Servlet IoHandler •Endpoint of a filter chain IoFilter •Important Methods IoFilter •sessionOpened IoFilter •messageReceived IoProcessor •sessionClosed IoAcceptor 7
  8. 8. IoFilterChain •Chain of IoFilter's for each IoSession •Can setup template chains per IoConnector/IoAcceptor •Dynamic addition/removal 8
  9. 9. IoFilters •Akin to a ServletFilter IoHandler •View/Hack/Slash the event stream IoFilter •Important Methods IoFilter •sessionOpened IoFilter •messageReceived IoProcessor •filterWrite IoAcceptor •sessionClosed 9
  10. 10. IoAcceptor •Server-side entry point. IoHandler •Accepts incoming connections and fires IoFilter events to an IoHandler •Important Methods IoFilter •bind IoFilter IoProcessor IoAcceptor 10
  11. 11. IoConnector •Client-side entry point •Initiate connections to a remote service, and fires events to an IoHandler •Important Methods •connect 11
  12. 12. IoProcessor •Internal component IoHandler •Handles reading and writing data to an IoFilter underlying connection •Each connection is associated with a IoFilter single IoProcessor (shared amongst IoFilter multiple connections) IoProcessor IoAcceptor 12
  13. 13. Our Sample Application •Persistent connections from clients •Serialize java objects across the wire •Clients connect and are given a unit of work, which in this case, is just an instruction for how long to wait until getting their next instruction. 13
  14. 14. Monitoring Performance •Thread activity via jconsole •CPU Activity via Activity Monitor •(or your favorite tool) 14
  15. 15. Limitations 15
  16. 16. Scalability •JVM limit on number of threads •The lovely java.lang.OutOfMemoryError: unable to create new native thread 16
  17. 17. Lets convert to MINA! •Server side first •(Client to come soon) 17
  18. 18. Re-testing 18
  19. 19. New Limitations? •Java Serialization takes up CPU time •(a profiler would reveal this) •OS limit of per-process open files •(consult the documentation for your OS) •sysctl / ulimit to view/change on unix-like systems 19
  20. 20. MINA on the client •Since we will be using MINA's built-in support for building protocols, the ProtocolCodecFilter •Any socket client can talk to MINA •We’re using MINA on both sides for simplicity in our examples. 20
  21. 21. Client is just like the server •IoHandler and IoFilter's •Can re-use filters on both client and server sides. 21
  22. 22. Implementing the protocol. 22
  23. 23. It still works! 23
  24. 24. Filters that ship today •Logging •Compression •Blacklist •SSL •Requires Java 5 24
  25. 25. Filters we are working on •Traffic Shaping •Rate Limiting •Performance Monitoring 25
  26. 26. Some things built on MINA •LDAP - Apache DS <http://directory.apache.org/ subprojects/apacheds/index.html> •Flash - red5 <http://www.osflash.org/red5> •HTTP - AsyncWeb <http://asyncweb.safehaus.org/> 26
  27. 27. Performance Tips •Set the number of IoProcessor’s to be equal to the number of CPU cores. •Benchmark! Users have found both heap and direct buffers, pooled and not pooled, to be beneficial depending on their workloads. •For ultra-low latency with small message sizes on a local lan, disable Nagle’s algorithm; the TCP_NODELAY flag. 27
  28. 28. Questions? 28
  29. 29. Thank You! 29

×