SlideShare a Scribd company logo
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
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
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
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
IoHandler




             IoFilter




                         Inbound
             IoFilter
Outbound




             IoFilter




           IoProcessor


           IoAcceptor




           Network
                                   Architectural overview

                                                        5
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
IoHandler
•Akin to a Servlet           IoHandler



•Endpoint of a filter chain
                               IoFilter


•Important Methods
                               IoFilter


  •sessionOpened
                               IoFilter

  •messageReceived
                             IoProcessor

  •sessionClosed
                             IoAcceptor




                                           7
IoFilterChain
•Chain of IoFilter's for each IoSession
•Can setup template chains per IoConnector/IoAcceptor
•Dynamic addition/removal




                                                        8
IoFilters
•Akin to a ServletFilter            IoHandler



•View/Hack/Slash the event stream
                                      IoFilter


•Important Methods
                                      IoFilter


  •sessionOpened
                                      IoFilter

  •messageReceived
                                    IoProcessor

  •filterWrite
                                    IoAcceptor


  •sessionClosed



                                                  9
IoAcceptor
•Server-side entry point.                IoHandler



•Accepts incoming connections and fires
                                           IoFilter
 events to an IoHandler
•Important Methods                         IoFilter




  •bind                                    IoFilter




                                         IoProcessor


                                         IoAcceptor




                                                       10
IoConnector
•Client-side entry point
•Initiate connections to a remote service, and fires events to
 an IoHandler
•Important Methods
  •connect




                                                                11
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
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
Monitoring Performance
•Thread activity via jconsole
•CPU Activity via Activity Monitor
  •(or your favorite tool)




                                     14
Limitations

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




                                                    16
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
  •(consult the documentation for your OS)
  •sysctl / ulimit to view/change on unix-like systems




                                                         19
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
Client is just like the server
•IoHandler and IoFilter's
•Can re-use filters on both client and server sides.




                                                      21
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 <http://www.osflash.org/red5>

•HTTP - AsyncWeb <http://asyncweb.safehaus.org/>




                                                   26
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
Questions?

             28
Thank You!

             29

More Related Content

Viewers also liked (11)

PPTX
Chalet management system (e cha m)
HoneySah
 
PPT
Intro to Distributed Database Management System
Ali Raza
 
PDF
Programming TCP/IP with Sockets
elliando dias
 
PDF
Distributed Databases
elliando dias
 
PPT
Database fragmentation
Punjab College Of Technical Education
 
PPT
Lecture 11 - distributed database
HoneySah
 
PDF
Clojurescript slides
elliando dias
 
PPT
Distributed Database Management System
Hardik Patil
 
PPT
Socket Programming Tutorial
Jignesh Patel
 
PPTX
Distributed database
ReachLocal Services India
 
PPT
Distributed Database System
Sulemang
 
Chalet management system (e cha m)
HoneySah
 
Intro to Distributed Database Management System
Ali Raza
 
Programming TCP/IP with Sockets
elliando dias
 
Distributed Databases
elliando dias
 
Lecture 11 - distributed database
HoneySah
 
Clojurescript slides
elliando dias
 
Distributed Database Management System
Hardik Patil
 
Socket Programming Tutorial
Jignesh Patel
 
Distributed database
ReachLocal Services India
 
Distributed Database System
Sulemang
 

Similar to Building High Performance Scalable TCP/IP Servers with Apache MINA (20)

PDF
Asynchronous, Event-driven Network Application Development with Netty
Ersin Er
 
PDF
Nio
nextlib
 
PDF
Netty: asynchronous data transfer
Victor Cherkassky
 
PDF
Building Web APIs that Scale
Salesforce Developers
 
PDF
Eventdriven I/O - A hands on introduction
Marc Seeger
 
PDF
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Twilio Inc
 
PDF
Java Network Programming, 4th Edition.pdf
ntrgiang203
 
PDF
04 android
guru472
 
PDF
iPhone meets SOA - 06/2008
Roland Tritsch
 
PPTX
Symbian OS - Client Server Framework
Andreas Jakl
 
KEY
High performance network programming on the jvm oscon 2012
Erik Onnen
 
PPT
Np unit1
vamsitricks
 
PDF
Lecture2
Majid Taghiloo
 
PDF
Asynchronous Io Programming
l xf
 
PDF
Oop2008 RESTful services with GWT and Apache CXF
Adrian Trenaman
 
PPTX
UNIT V DIS.pptx
Premkumar R
 
PPT
many many many many server types all there
Meenakshi Raheja
 
PDF
Java Network Programming Fourth Edition Harold Elliotte
zubinrlondoit
 
PDF
Reliable Distributed Systems Technologies Web Services And Applications Kenne...
tilusdukettk
 
PDF
JJUG CCC 2018 Spring - I-7 (俺が)はじめての Netty
Shinya Mochida
 
Asynchronous, Event-driven Network Application Development with Netty
Ersin Er
 
Nio
nextlib
 
Netty: asynchronous data transfer
Victor Cherkassky
 
Building Web APIs that Scale
Salesforce Developers
 
Eventdriven I/O - A hands on introduction
Marc Seeger
 
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Twilio Inc
 
Java Network Programming, 4th Edition.pdf
ntrgiang203
 
04 android
guru472
 
iPhone meets SOA - 06/2008
Roland Tritsch
 
Symbian OS - Client Server Framework
Andreas Jakl
 
High performance network programming on the jvm oscon 2012
Erik Onnen
 
Np unit1
vamsitricks
 
Lecture2
Majid Taghiloo
 
Asynchronous Io Programming
l xf
 
Oop2008 RESTful services with GWT and Apache CXF
Adrian Trenaman
 
UNIT V DIS.pptx
Premkumar R
 
many many many many server types all there
Meenakshi Raheja
 
Java Network Programming Fourth Edition Harold Elliotte
zubinrlondoit
 
Reliable Distributed Systems Technologies Web Services And Applications Kenne...
tilusdukettk
 
JJUG CCC 2018 Spring - I-7 (俺が)はじめての Netty
Shinya Mochida
 
Ad

More from elliando dias (20)

PDF
Why you should be excited about ClojureScript
elliando dias
 
PDF
Functional Programming with Immutable Data Structures
elliando dias
 
PPT
Nomenclatura e peças de container
elliando dias
 
PDF
Geometria Projetiva
elliando dias
 
PDF
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
PDF
Javascript Libraries
elliando dias
 
PDF
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
PDF
Ragel talk
elliando dias
 
PDF
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
PDF
Introdução ao Arduino
elliando dias
 
PDF
Minicurso arduino
elliando dias
 
PDF
Incanter Data Sorcery
elliando dias
 
PDF
Rango
elliando dias
 
PDF
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
PDF
The Digital Revolution: Machines that makes
elliando dias
 
PDF
Hadoop + Clojure
elliando dias
 
PDF
Hadoop - Simple. Scalable.
elliando dias
 
PDF
Hadoop and Hive Development at Facebook
elliando dias
 
PDF
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
PDF
From Lisp to Clojure/Incanter and RAn Introduction
elliando dias
 
Why you should be excited about ClojureScript
elliando dias
 
Functional Programming with Immutable Data Structures
elliando dias
 
Nomenclatura e peças de container
elliando dias
 
Geometria Projetiva
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
Ragel talk
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
elliando dias
 
Minicurso arduino
elliando dias
 
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
The Digital Revolution: Machines that makes
elliando dias
 
Hadoop + Clojure
elliando dias
 
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
From Lisp to Clojure/Incanter and RAn Introduction
elliando dias
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 

Building High Performance Scalable TCP/IP Servers with Apache MINA

  • 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, <[email protected]> 1
  • 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. 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. 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. IoHandler IoFilter Inbound IoFilter Outbound IoFilter IoProcessor IoAcceptor Network Architectural overview 5
  • 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. IoHandler •Akin to a Servlet IoHandler •Endpoint of a filter chain IoFilter •Important Methods IoFilter •sessionOpened IoFilter •messageReceived IoProcessor •sessionClosed IoAcceptor 7
  • 8. IoFilterChain •Chain of IoFilter's for each IoSession •Can setup template chains per IoConnector/IoAcceptor •Dynamic addition/removal 8
  • 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. 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. IoConnector •Client-side entry point •Initiate connections to a remote service, and fires events to an IoHandler •Important Methods •connect 11
  • 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. 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. Monitoring Performance •Thread activity via jconsole •CPU Activity via Activity Monitor •(or your favorite tool) 14
  • 16. Scalability •JVM limit on number of threads •The lovely java.lang.OutOfMemoryError: unable to create new native thread 16
  • 17. Lets convert to MINA! •Server side first •(Client to come soon) 17
  • 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. 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. Client is just like the server •IoHandler and IoFilter's •Can re-use filters on both client and server sides. 21
  • 24. Filters that ship today •Logging •Compression •Blacklist •SSL •Requires Java 5 24
  • 25. Filters we are working on •Traffic Shaping •Rate Limiting •Performance Monitoring 25
  • 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. 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