SlideShare a Scribd company logo
Asynchronous, Event-driven
Network Application Development
with Netty
Rapid development of maintainable high performance protocol servers & clients
Ankara JUG, June 2015
Ersin Er - @ersiner
About the speaker, Ersin Er
Summary of what’s on LinkedIn
● Computer Sci. Student @ Hacettepe Univ. - BSc (’03), MSc (’06), PhD (~)
● Teaching Assistant [and System Admin.] @ Hacettepe Univ. (’03-’11)
● Committer and PMC Member @ Apache Software Foundation (’05-’10)
● Software Architect @ Peak Games (’11-’13)
● Co-founder and Solutions Architect @ Metasolid (’14-’15)
● Hands-on Solutions and Software Architect.
● Distributed Systems, Concurrency and Performance Programming
enthusiast.
● Does tech biz, manages projects, deals with people.
● Used to be a perfectionist. Does not produce garbage.
How to name your presentation
Today’s Agenda
● Blocking vs Non-Blocking I/O
● NIO and Netty Abstractions
● What sets Netty apart
● Netty Reusables
● Netty & HTTP
● Servlet 3.0 and 3.1 (for our beloved JavaEE friends )
● Netty Ecosystem
Do not expect a 1-1
matched flow with
these titles.
I prefer discussions to
static information
dumping.
Let’s review
Blocking Socket I/O in Java
by examples
in order to steer
our discussions on
Non-Blocking I/O,
Java NIO
and Netty.
Blocking I/O Socket Server Example
Single Client, Single Request
public static void serve1() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
Socket clientSocket = serverSocket.accept();
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
if ((request = in.readLine()) != null) {
response = request + " processed at " + new Date();
out.println(response);
}
in.close();
out.close();
}
Protocol
Implementation
Blocking I/O Socket Server Example
Single Client, Multi Request
public static void serve2() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
Socket clientSocket = serverSocket.accept();
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
while ((request = in.readLine()) != null) {
response = request + " processed at " + new Date();
out.println(response);
}
in.close();
out.close();
}
Wow!
That was
easy!
Blocking I/O Socket Server Example
Single Client, Multi Request, Client Exit Control
public static void serve3() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
Socket clientSocket = serverSocket.accept();
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
while ((request = in.readLine()) != null) {
if ("Exit".equals(request)) {
break;
}
response = request + " processed at " + new Date();
out.println(response);
}
in.close();
out.close();
}
More Protocol
Blocking I/O Socket Server Example
Multi Client, Multi Request, Client Exit Control
public static void serve4() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
while (true) {
Socket clientSocket = serverSocket.accept();
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
while ((request = in.readLine()) != null) {
if ("Exit".equals(request)) {
break;
}
response = request + " processed at " + new Date();
out.println(response);
}
in.close();
out.close();
}
}
A new generation ofInternet servicesupporting multipleusers?..
Blocking I/O Socket Server Example
Concurrent Clients, Multi Request, Client Exit Control
public static void serve5() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
while (true) {
final Socket clientSocket = serverSocket.accept();
new Thread() {
public void run() {
try {
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
while ((request = in.readLine()) != null) {
if ("Exit".equals(request)) { break; }
response = request + " processed at " + new Date(); out.println(response);
}
in.close(); out.close();
} catch (IOException e) { e.printStackTrace(); }
}
}.start();
}
}
!!!
These are far from
being production
code. In fact, they
are terrible ones.
Uncontrolled
Power!
Multi-Threaded Blocking I/O Exhausting Resources
What to do?
public static void serve5() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
while (true) {
final Socket clientSocket = serverSocket.accept();
new Thread() {
public void run() {
try {
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
while ((request = in.readLine()) != null) {
if ("Exit".equals(request)) { break; }
response = request + " processed at " + new Date(); out.println(response);
}
in.close(); out.close();
} catch (IOException e) { e.printStackTrace(); }
}
}.start();
}
}
!!!
These are far from
being production
code. In fact, they
are terrible ones.
Uncontrolled
Power!
What to do?
● Pooling?
● Executors?
● Queuing?
Multi-Threaded Blocking I/O Exhausting Resources
What to do? - Critical Discussion
public static void serve5() throws IOException {
ServerSocket serverSocket = new ServerSocket(10000);
while (true) {
final Socket clientSocket = serverSocket.accept();
new Thread() {
public void run() {
try {
InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String request, response;
while ((request = in.readLine()) != null) {
if ("Exit".equals(request)) { break; }
response = request + " processed at " + new Date(); out.println(response);
}
in.close(); out.close();
} catch (IOException e) { e.printStackTrace(); }
}
}.start();
}
}
!!!
These are far from
being production
code. In fact, they
are terrible ones.
Uncontrolled
Power!
What to do?
● Pooling?
● Executors?
● Queuing?
The discussion here iscritical for switching(our minds) to Non-Blocking I/O, Java NIOand Netty
Non-Blocking I/O
● Sockets in Non-Blocking Mode
● I/O Multiplexing
○ epoll (Linux)
○ kqueue (FreeBSD)
○ IOCP (Windows, Solaris)
● Single Thread for many sockets (or file
descriptors)
● Key to high performance servers
Non-Blocking or
Asynchronous?
(Blocking or Synchronous?)
Simplified definitions that can work for us today:
● Non-Blocking: No waiting for the operation
to complete
● Asynchronous: Notification upon completion
of non-blocking operation
Java NIO
● NIO = Non-Blocking I/O?
● It’s Java New I/O
● It’s no longer new (came with Java 1.4)
○ Java 7 comes with V2
● Not only for Socket I/O
● First Class Citizens
○ Channels
○ Buffers
○ Selectors
NIO - Channels and Buffers
● Channels
○ FileChannel
○ DatagramChannel
○ SocketChannel
○ ServerSocketChannel
● Buffers
○ ByteBuffer
○ CharBuffer
○ DoubleBuffer
○ FloatBuffer
○ IntBuffer
○ LongBuffer
○ ShortBuffer
● Data are read from
Channels into Buffers
● Data are written from
Buffers into Channels
NIO - Buffers are serious business
Buffer capacity, position and limit
in write and read mode.
Buffer.flip() makes the mode
change.
We also have:
● Heap Buffers
○ Array Based
○ ByteBuffer.allocate()
● Direct Buffers
○ Off-Heap
○ ByteBuffer.allocateDirect()
NIO - Selectors & I/O Multiplexing
OIO vs NIO
From NIO to Netty
Using NIO directly is like using
Naked Threads.
Netty replaces NIO APIs
with superiors and
provides incredible
capabilities.
Netty Core Components and Utilities
● Channels and Transports
● ByteBuf and Un/Pooled Allocation
Management
● ChannelHandlers and ChannelPipeline
● The Codec Framework and Reusable
Codecs
● Bootstraps and ChannelInitializers
● Futures and EventLoops
Channels and Transports
Package View
● io.netty.channel.embedded
● io.netty.channel.epoll
● io.netty.channel.local
● io.netty.channel.nio
● io.netty.channel.oio
● io.netty.channel.rxtx
● io.netty.channel.sctp
● io.netty.channel.sctp.nio
● io.netty.channel.sctp.oio
● io.netty.channel.socket
● io.netty.channel.socket.nio
● io.netty.channel.socket.oio
● io.netty.channel.udt
● io.netty.channel.udt.nio
● io.netty.channel.unix
● You can both read from write into Channels
(they are duplex as opposed to streams)
● All I/O operations on channels are
asynchronous and return listenable
futures
● Channels are implemented for various
Transports types:
○ Unified API for NIO and OID (and
others)
○ Epoll transport for extreme
performance
○ Local transport for in VM
communication
○ Embedded transport for Unit Testing
ByteBuf and Un/Pooled Allocation
Management
● ByteBuf is improved version of ByteBuffer
● ByteBuf has both write and read index, does not need
flip()
● CompositeByteBuf enables Zero-Copy
● ByteBufs can be pooled for reducing garbage collector
pressure
https://blog.twitter.com/2013/netty-4-at-twitter-reduced-gc-overhead
ChannelHandlers and ChannelPipeline
Channel
Inbound
Handler
Channel
Inbound
Handler
Channel
Outbound
Handler
Channel
Outbound
Handler
Head Tail
Socket
Channel
Pipeline
ChannelPipeline has been designed
with Intercepting Filter pattern and
resembles Servlet Filters
Codec Framework
● Simplified and focused API on top of
ChannelHandlers
● Decoders are ChannelInboundHandlers
● Encoders are ChannelOutboundHandlers
● Codecs are both CIH and COH
Reusable Codecs
● io.netty.handler.codec.base64
● io.netty.handler.codec.bytes
● io.netty.handler.codec.compression
● io.netty.handler.codec.haproxy
● io.netty.handler.codec.http
● io.netty.handler.codec.http.cookie
● io.netty.handler.codec.http.cors
● io.netty.handler.codec.http.multipart
● io.netty.handler.codec.http.websocketx
● io.netty.handler.codec.marshalling
● io.netty.handler.codec.protobuf
● io.netty.handler.codec.rtsp
● io.netty.handler.codec.sctp
● io.netty.handler.codec.serialization
● io.netty.handler.codec.socks
● io.netty.handler.codec.spdy
● io.netty.handler.codec.string
● io.netty.handler.logging
● io.netty.handler.ssl
● io.netty.handler.stream
● io.netty.handler.timeout
● io.netty.handler.traffic
● DelimiterBasedFrameDecoder
● LengthFieldBasedFrameDecoder
● FixedLengthFrameDecoder
● LineBasedFrameDecoder
Some primitive
ones
All of these
represent
patterns of
protocol
development
Bootstraps and
ChannelInitializers
Bootstraps help bootstrap
channels (server or client
side)
● Set EventLoopGroups
● Set ChannelHandlers
● Bind to Network
Interfaces
ChannelInitializer is a
special ChannelHandler
● Handles
channelRegistered
event and applies its
pipeline config to the
channel
● (Suggested: See its
source code)
Futures and EventLoops
● All I/O operations on Channels return listenable futures
● Each Channel is assigned to a single EventLoop and
stays so during its lifetime
● EventLoops handle all I/O operations of their Channels
● EventLoopGroups are like Thread Pools and number of
EventLoops they manage depends on number of CPU
cores (and possible other factors)
● Listeners registered to Futures are handled by
appropriate EventLoop selected by Netty
Now, Examples
Servlet
● Servlet 3.0 - Async Processing of Response
● Servlet 3.1 - Non-Blocking Processing of
Request (Content)
Did you expect more?
Come on, this is Netty :-)
Netty Versions
● 3.x Old, Stable
● 4.0.x Current, Stable
○ Huge improvements over 3.x
○ https://github.com/netty/netty/wiki/New-and-noteworthy-in-4.0
● 4.1 Beta (Close to be Stable)
○ Mostly backward compatible with 4.0
○ Android support and lots of new codecs
○ https://github.com/netty/netty/wiki/New-and-noteworthy-in-4.1
● 5.0 Alpha - Backward Incompatible Improvements
○ https://github.com/netty/netty/wiki/New-and-noteworthy-in-5.0
Ecosystem - Related Projects
(The ones I’ve been interested in and mostly using Netty at its heart)
● Vert.x - A toolkit for building reactive applications on the JVM
● Ratpack - Simple, lean & powerful HTTP apps
● async-http-client - Asynchronous Http and WebSocket Client
library for Java
● RxNetty - Reactive Extension (Rx) Adaptor for Netty
● nettosphere - A Java WebSocket/HTTP server based on the
Atmosphere and Netty Framework
● grpc-java - The Java gRPC implementation (by Google)
● Play Framework - The High Velocity Web Framework For Java and
Scala
● More at http://netty.io/wiki/related-projects.html and http://netty.
io/wiki/adopters.html
Ecosystem - Resources
● Netty Documentation & Examples
○ http://netty.io/wiki/index.html
● StackOverflow
○ http://stackoverflow.com/questions/tagged/netty
● Netty in Action
○ http://www.manning.com/maurer/
Thanks
● You, attenders!
● Ankara JUG organizers, for having me here
● Jakob Jenkov, for allowing me use his diagrams for
explaining NIO Concepts (http://tutorials.jenkov.
com/java-nio/index.html)

More Related Content

What's hot

Event Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMware
Event Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMwareEvent Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMware
Event Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMwareHostedbyConfluent
 
Apache Sentry for Hadoop security
Apache Sentry for Hadoop securityApache Sentry for Hadoop security
Apache Sentry for Hadoop securitybigdatagurus_meetup
 
Enabling ABAC with Accumulo and Ranger integration
Enabling ABAC with Accumulo and Ranger integrationEnabling ABAC with Accumulo and Ranger integration
Enabling ABAC with Accumulo and Ranger integrationDataWorks Summit
 
Netty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoopsNetty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoopsRick Hightower
 
Rest API Security
Rest API SecurityRest API Security
Rest API SecurityStormpath
 
Apache sqoop with an use case
Apache sqoop with an use caseApache sqoop with an use case
Apache sqoop with an use caseDavin Abraham
 
Spark Summit East 2017: Apache spark and object stores
Spark Summit East 2017: Apache spark and object storesSpark Summit East 2017: Apache spark and object stores
Spark Summit East 2017: Apache spark and object storesSteve Loughran
 
Drone Data Flowing Through Apache NiFi
Drone Data Flowing Through Apache NiFiDrone Data Flowing Through Apache NiFi
Drone Data Flowing Through Apache NiFiTimothy Spann
 
HTTP HOST header attacks
HTTP HOST header attacksHTTP HOST header attacks
HTTP HOST header attacksDefconRussia
 
Airflow를 이용한 데이터 Workflow 관리
Airflow를 이용한  데이터 Workflow 관리Airflow를 이용한  데이터 Workflow 관리
Airflow를 이용한 데이터 Workflow 관리YoungHeon (Roy) Kim
 
Event Streaming in the Telco Industry with Apache Kafka® and Confluent
Event Streaming in the Telco Industry with Apache Kafka® and ConfluentEvent Streaming in the Telco Industry with Apache Kafka® and Confluent
Event Streaming in the Telco Industry with Apache Kafka® and Confluentconfluent
 
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta LakeIntroducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta LakeDatabricks
 
Building layers of defense for your application
Building layers of defense for your applicationBuilding layers of defense for your application
Building layers of defense for your applicationVMware Tanzu
 
Best Practices for Using Apache Spark on AWS
Best Practices for Using Apache Spark on AWSBest Practices for Using Apache Spark on AWS
Best Practices for Using Apache Spark on AWSAmazon Web Services
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...Flink Forward
 
Apache NiFi Crash Course - San Jose Hadoop Summit
Apache NiFi Crash Course - San Jose Hadoop SummitApache NiFi Crash Course - San Jose Hadoop Summit
Apache NiFi Crash Course - San Jose Hadoop SummitAldrin Piri
 

What's hot (20)

Event Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMware
Event Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMwareEvent Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMware
Event Streaming with Kafka Streams and Spring Cloud Stream | Soby Chacko, VMware
 
Apache Sentry for Hadoop security
Apache Sentry for Hadoop securityApache Sentry for Hadoop security
Apache Sentry for Hadoop security
 
Enabling ABAC with Accumulo and Ranger integration
Enabling ABAC with Accumulo and Ranger integrationEnabling ABAC with Accumulo and Ranger integration
Enabling ABAC with Accumulo and Ranger integration
 
Netty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoopsNetty Notes Part 3 - Channel Pipeline and EventLoops
Netty Notes Part 3 - Channel Pipeline and EventLoops
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
Apache sqoop with an use case
Apache sqoop with an use caseApache sqoop with an use case
Apache sqoop with an use case
 
Spark Summit East 2017: Apache spark and object stores
Spark Summit East 2017: Apache spark and object storesSpark Summit East 2017: Apache spark and object stores
Spark Summit East 2017: Apache spark and object stores
 
Drone Data Flowing Through Apache NiFi
Drone Data Flowing Through Apache NiFiDrone Data Flowing Through Apache NiFi
Drone Data Flowing Through Apache NiFi
 
Pentesting ReST API
Pentesting ReST APIPentesting ReST API
Pentesting ReST API
 
Secure coding practices
Secure coding practicesSecure coding practices
Secure coding practices
 
HTTP HOST header attacks
HTTP HOST header attacksHTTP HOST header attacks
HTTP HOST header attacks
 
OAuth 2.0
OAuth 2.0OAuth 2.0
OAuth 2.0
 
Airflow를 이용한 데이터 Workflow 관리
Airflow를 이용한  데이터 Workflow 관리Airflow를 이용한  데이터 Workflow 관리
Airflow를 이용한 데이터 Workflow 관리
 
Event Streaming in the Telco Industry with Apache Kafka® and Confluent
Event Streaming in the Telco Industry with Apache Kafka® and ConfluentEvent Streaming in the Telco Industry with Apache Kafka® and Confluent
Event Streaming in the Telco Industry with Apache Kafka® and Confluent
 
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta LakeIntroducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
 
Building layers of defense for your application
Building layers of defense for your applicationBuilding layers of defense for your application
Building layers of defense for your application
 
Best Practices for Using Apache Spark on AWS
Best Practices for Using Apache Spark on AWSBest Practices for Using Apache Spark on AWS
Best Practices for Using Apache Spark on AWS
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
 
Apache NiFi Crash Course - San Jose Hadoop Summit
Apache NiFi Crash Course - San Jose Hadoop SummitApache NiFi Crash Course - San Jose Hadoop Summit
Apache NiFi Crash Course - San Jose Hadoop Summit
 

Similar to Asynchronous, Event-driven Network Application Development with Netty

Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and howPetr Zapletal
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016Frank Lyaruu
 
Couchbase@live person meetup july 22nd
Couchbase@live person meetup   july 22ndCouchbase@live person meetup   july 22nd
Couchbase@live person meetup july 22ndIdo Shilon
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomyDongmin Yu
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"DataStax Academy
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for CassandraEdward Capriolo
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server InternalsPraveen Gollakota
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3takezoe
 
Go and Uber’s time series database m3
Go and Uber’s time series database m3Go and Uber’s time series database m3
Go and Uber’s time series database m3Rob Skillington
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기NAVER D2
 
A Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQLA Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQLDatabricks
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQLRoberto Franchini
 
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017Codemotion
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartMukesh Singh
 

Similar to Asynchronous, Event-driven Network Application Development with Netty (20)

Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and how
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Couchbase@live person meetup july 22nd
Couchbase@live person meetup   july 22ndCouchbase@live person meetup   july 22nd
Couchbase@live person meetup july 22nd
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3
 
Go and Uber’s time series database m3
Go and Uber’s time series database m3Go and Uber’s time series database m3
Go and Uber’s time series database m3
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
 
A Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQLA Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQL
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQL
 
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
 
Exploring Relay land
Exploring Relay landExploring Relay land
Exploring Relay land
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
Python, do you even async?
Python, do you even async?Python, do you even async?
Python, do you even async?
 
cb streams - gavin pickin
cb streams - gavin pickincb streams - gavin pickin
cb streams - gavin pickin
 

Recently uploaded

Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILNatan Silnitsky
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAlluxio, Inc.
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...rajkumar669520
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfkalichargn70th171
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockSkilrock Technologies
 

Recently uploaded (20)

Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 

Asynchronous, Event-driven Network Application Development with Netty

  • 1. Asynchronous, Event-driven Network Application Development with Netty Rapid development of maintainable high performance protocol servers & clients Ankara JUG, June 2015 Ersin Er - @ersiner
  • 2. About the speaker, Ersin Er Summary of what’s on LinkedIn ● Computer Sci. Student @ Hacettepe Univ. - BSc (’03), MSc (’06), PhD (~) ● Teaching Assistant [and System Admin.] @ Hacettepe Univ. (’03-’11) ● Committer and PMC Member @ Apache Software Foundation (’05-’10) ● Software Architect @ Peak Games (’11-’13) ● Co-founder and Solutions Architect @ Metasolid (’14-’15) ● Hands-on Solutions and Software Architect. ● Distributed Systems, Concurrency and Performance Programming enthusiast. ● Does tech biz, manages projects, deals with people. ● Used to be a perfectionist. Does not produce garbage.
  • 3. How to name your presentation
  • 4. Today’s Agenda ● Blocking vs Non-Blocking I/O ● NIO and Netty Abstractions ● What sets Netty apart ● Netty Reusables ● Netty & HTTP ● Servlet 3.0 and 3.1 (for our beloved JavaEE friends ) ● Netty Ecosystem Do not expect a 1-1 matched flow with these titles. I prefer discussions to static information dumping.
  • 5. Let’s review Blocking Socket I/O in Java by examples in order to steer our discussions on Non-Blocking I/O, Java NIO and Netty.
  • 6. Blocking I/O Socket Server Example Single Client, Single Request public static void serve1() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); Socket clientSocket = serverSocket.accept(); InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; if ((request = in.readLine()) != null) { response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } Protocol Implementation
  • 7. Blocking I/O Socket Server Example Single Client, Multi Request public static void serve2() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); Socket clientSocket = serverSocket.accept(); InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } Wow! That was easy!
  • 8. Blocking I/O Socket Server Example Single Client, Multi Request, Client Exit Control public static void serve3() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); Socket clientSocket = serverSocket.accept(); InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { if ("Exit".equals(request)) { break; } response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } More Protocol
  • 9. Blocking I/O Socket Server Example Multi Client, Multi Request, Client Exit Control public static void serve4() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); while (true) { Socket clientSocket = serverSocket.accept(); InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { if ("Exit".equals(request)) { break; } response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } } A new generation ofInternet servicesupporting multipleusers?..
  • 10. Blocking I/O Socket Server Example Concurrent Clients, Multi Request, Client Exit Control public static void serve5() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); while (true) { final Socket clientSocket = serverSocket.accept(); new Thread() { public void run() { try { InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { if ("Exit".equals(request)) { break; } response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } } !!! These are far from being production code. In fact, they are terrible ones. Uncontrolled Power!
  • 11. Multi-Threaded Blocking I/O Exhausting Resources What to do? public static void serve5() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); while (true) { final Socket clientSocket = serverSocket.accept(); new Thread() { public void run() { try { InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { if ("Exit".equals(request)) { break; } response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } } !!! These are far from being production code. In fact, they are terrible ones. Uncontrolled Power! What to do? ● Pooling? ● Executors? ● Queuing?
  • 12. Multi-Threaded Blocking I/O Exhausting Resources What to do? - Critical Discussion public static void serve5() throws IOException { ServerSocket serverSocket = new ServerSocket(10000); while (true) { final Socket clientSocket = serverSocket.accept(); new Thread() { public void run() { try { InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader in = new BufferedReader(isr); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { if ("Exit".equals(request)) { break; } response = request + " processed at " + new Date(); out.println(response); } in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } } !!! These are far from being production code. In fact, they are terrible ones. Uncontrolled Power! What to do? ● Pooling? ● Executors? ● Queuing? The discussion here iscritical for switching(our minds) to Non-Blocking I/O, Java NIOand Netty
  • 13.
  • 14. Non-Blocking I/O ● Sockets in Non-Blocking Mode ● I/O Multiplexing ○ epoll (Linux) ○ kqueue (FreeBSD) ○ IOCP (Windows, Solaris) ● Single Thread for many sockets (or file descriptors) ● Key to high performance servers
  • 15. Non-Blocking or Asynchronous? (Blocking or Synchronous?) Simplified definitions that can work for us today: ● Non-Blocking: No waiting for the operation to complete ● Asynchronous: Notification upon completion of non-blocking operation
  • 16. Java NIO ● NIO = Non-Blocking I/O? ● It’s Java New I/O ● It’s no longer new (came with Java 1.4) ○ Java 7 comes with V2 ● Not only for Socket I/O ● First Class Citizens ○ Channels ○ Buffers ○ Selectors
  • 17. NIO - Channels and Buffers ● Channels ○ FileChannel ○ DatagramChannel ○ SocketChannel ○ ServerSocketChannel ● Buffers ○ ByteBuffer ○ CharBuffer ○ DoubleBuffer ○ FloatBuffer ○ IntBuffer ○ LongBuffer ○ ShortBuffer ● Data are read from Channels into Buffers ● Data are written from Buffers into Channels
  • 18. NIO - Buffers are serious business Buffer capacity, position and limit in write and read mode. Buffer.flip() makes the mode change. We also have: ● Heap Buffers ○ Array Based ○ ByteBuffer.allocate() ● Direct Buffers ○ Off-Heap ○ ByteBuffer.allocateDirect()
  • 19. NIO - Selectors & I/O Multiplexing
  • 21. From NIO to Netty Using NIO directly is like using Naked Threads. Netty replaces NIO APIs with superiors and provides incredible capabilities.
  • 22. Netty Core Components and Utilities ● Channels and Transports ● ByteBuf and Un/Pooled Allocation Management ● ChannelHandlers and ChannelPipeline ● The Codec Framework and Reusable Codecs ● Bootstraps and ChannelInitializers ● Futures and EventLoops
  • 23. Channels and Transports Package View ● io.netty.channel.embedded ● io.netty.channel.epoll ● io.netty.channel.local ● io.netty.channel.nio ● io.netty.channel.oio ● io.netty.channel.rxtx ● io.netty.channel.sctp ● io.netty.channel.sctp.nio ● io.netty.channel.sctp.oio ● io.netty.channel.socket ● io.netty.channel.socket.nio ● io.netty.channel.socket.oio ● io.netty.channel.udt ● io.netty.channel.udt.nio ● io.netty.channel.unix ● You can both read from write into Channels (they are duplex as opposed to streams) ● All I/O operations on channels are asynchronous and return listenable futures ● Channels are implemented for various Transports types: ○ Unified API for NIO and OID (and others) ○ Epoll transport for extreme performance ○ Local transport for in VM communication ○ Embedded transport for Unit Testing
  • 24. ByteBuf and Un/Pooled Allocation Management ● ByteBuf is improved version of ByteBuffer ● ByteBuf has both write and read index, does not need flip() ● CompositeByteBuf enables Zero-Copy ● ByteBufs can be pooled for reducing garbage collector pressure https://blog.twitter.com/2013/netty-4-at-twitter-reduced-gc-overhead
  • 25. ChannelHandlers and ChannelPipeline Channel Inbound Handler Channel Inbound Handler Channel Outbound Handler Channel Outbound Handler Head Tail Socket Channel Pipeline ChannelPipeline has been designed with Intercepting Filter pattern and resembles Servlet Filters
  • 26. Codec Framework ● Simplified and focused API on top of ChannelHandlers ● Decoders are ChannelInboundHandlers ● Encoders are ChannelOutboundHandlers ● Codecs are both CIH and COH
  • 27. Reusable Codecs ● io.netty.handler.codec.base64 ● io.netty.handler.codec.bytes ● io.netty.handler.codec.compression ● io.netty.handler.codec.haproxy ● io.netty.handler.codec.http ● io.netty.handler.codec.http.cookie ● io.netty.handler.codec.http.cors ● io.netty.handler.codec.http.multipart ● io.netty.handler.codec.http.websocketx ● io.netty.handler.codec.marshalling ● io.netty.handler.codec.protobuf ● io.netty.handler.codec.rtsp ● io.netty.handler.codec.sctp ● io.netty.handler.codec.serialization ● io.netty.handler.codec.socks ● io.netty.handler.codec.spdy ● io.netty.handler.codec.string ● io.netty.handler.logging ● io.netty.handler.ssl ● io.netty.handler.stream ● io.netty.handler.timeout ● io.netty.handler.traffic ● DelimiterBasedFrameDecoder ● LengthFieldBasedFrameDecoder ● FixedLengthFrameDecoder ● LineBasedFrameDecoder Some primitive ones All of these represent patterns of protocol development
  • 28. Bootstraps and ChannelInitializers Bootstraps help bootstrap channels (server or client side) ● Set EventLoopGroups ● Set ChannelHandlers ● Bind to Network Interfaces ChannelInitializer is a special ChannelHandler ● Handles channelRegistered event and applies its pipeline config to the channel ● (Suggested: See its source code)
  • 29. Futures and EventLoops ● All I/O operations on Channels return listenable futures ● Each Channel is assigned to a single EventLoop and stays so during its lifetime ● EventLoops handle all I/O operations of their Channels ● EventLoopGroups are like Thread Pools and number of EventLoops they manage depends on number of CPU cores (and possible other factors) ● Listeners registered to Futures are handled by appropriate EventLoop selected by Netty
  • 31. Servlet ● Servlet 3.0 - Async Processing of Response ● Servlet 3.1 - Non-Blocking Processing of Request (Content) Did you expect more? Come on, this is Netty :-)
  • 32. Netty Versions ● 3.x Old, Stable ● 4.0.x Current, Stable ○ Huge improvements over 3.x ○ https://github.com/netty/netty/wiki/New-and-noteworthy-in-4.0 ● 4.1 Beta (Close to be Stable) ○ Mostly backward compatible with 4.0 ○ Android support and lots of new codecs ○ https://github.com/netty/netty/wiki/New-and-noteworthy-in-4.1 ● 5.0 Alpha - Backward Incompatible Improvements ○ https://github.com/netty/netty/wiki/New-and-noteworthy-in-5.0
  • 33. Ecosystem - Related Projects (The ones I’ve been interested in and mostly using Netty at its heart) ● Vert.x - A toolkit for building reactive applications on the JVM ● Ratpack - Simple, lean & powerful HTTP apps ● async-http-client - Asynchronous Http and WebSocket Client library for Java ● RxNetty - Reactive Extension (Rx) Adaptor for Netty ● nettosphere - A Java WebSocket/HTTP server based on the Atmosphere and Netty Framework ● grpc-java - The Java gRPC implementation (by Google) ● Play Framework - The High Velocity Web Framework For Java and Scala ● More at http://netty.io/wiki/related-projects.html and http://netty. io/wiki/adopters.html
  • 34. Ecosystem - Resources ● Netty Documentation & Examples ○ http://netty.io/wiki/index.html ● StackOverflow ○ http://stackoverflow.com/questions/tagged/netty ● Netty in Action ○ http://www.manning.com/maurer/
  • 35. Thanks ● You, attenders! ● Ankara JUG organizers, for having me here ● Jakob Jenkov, for allowing me use his diagrams for explaining NIO Concepts (http://tutorials.jenkov. com/java-nio/index.html)