SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Netty
List("Asynchronous", "data", "transfer")
      ::: List("practical", "aspects")




                            Victor Cherkassky
                    "vcherkassky@gmail.com"
What is Netty
         IO library



        IO
cat Files > Networking
What is Netty
                   IO library
                   asynchronous

    ChannelFuture future = channel.write(message)
future.addListener(WRITE_COMPLETE_LISTENER)
What is Netty
                          IO library
                          asynchronous
                          non-blocking
      /**
        * This method blocks until input data is available
        */
           InputStream.read()
What is Netty
         IO library
         asynchronous
         non-blocking
         multi-protocol

HTTP | WebSocket | Protobuf
         | Binary
     TCP | UDP
blocking vs non-blocking
              blocking (OIO)
Ipttemi =nwFlIpttem"nu.i";
 nuSra s  e ienuSra(iptbn)
itbt =i.ed) / crettra wisfrrsl o err
 n ye  sra(; / urn hed at o eut r ro




            non-blocking (NIO)
wie(re {
 hl tu)
  slco.eet) / rqetn eet fo mlil canl
   eetrslc(; / eusig vns rm utpe hnes
  Ieao i =slco.eetdes)ieao(;
   trtr t  eetrslceKy(.trtr)
  wie(thset) {
   hl i.aNx()
    SlcoKyky=(eetoKy i.et)
    eetre e   Slcine) tnx(;
    hnlKyky;
    adee(e)
    i.eoe)
    trmv(;
  }
}
blocking vs non-blocking
   Hardware blocking write
blocking vs non-blocking
Hardware non-blocking write: DMA
blocking vs non-blocking
                     OS
select()/poll() - traditional POSIX polling O(n)
epoll() - event-based polling O(1), Linux 2.5.44+
kqueue - FreeBSD, Mac OS X
I/O Completion Ports - Windows NT 3.5+, Solaris 10+
blocking vs non-blocking
                        Java
SelectableChannel.register(selector) - blocking operation,
registers an "interest" for IO events
Selector.select - non-blocking operation, checks for
occurred events
blocking vs non-blocking

            Java                            OS
                                     select() / poll() / kqueue
Channel.register & Selector.select   I/O Completion Ports
                                     epoll() - Java 1.6+
Thread model

    Tomcat
 1 request = 1 thread
fast for ~1000 clients
  too much memory
Thread model

    Node.js
all requests = 1 thread
     super scalable
limited error handling
Thread model

       Netty
many requests = 1 thread
    flexible model
Netty web Server
Netty web Client
Channel Pipeline
All terms together
Channel (socket read/write)
channel Buffer (byte array)
channel Event (message)
channel Pipeline (message bus)
channel Handler (message handler)
  Upstream Event (from socket)
  Downstream Event (to socket)
Creating an HTTP server
        Set up thread pools
   boss pool for handling incoming connections
   worker pool for processing IO

piaefnlEeuo bsPo =Eeuosnwahdhedol)
 rvt ia xctr osol  xctr.eCceTraPo(
;
piaefnlEeuo wrePo =Eeuosnwahdhedol
 rvt ia xctr okrol  xctr.eCceTraPo
(;
 )
Creating an HTTP server
    Provide ChannelFactory
piaefnlCanlatr canlatr =
 rvt ia hneFcoy hneFcoy
   nwNoevrokthneFcoybsPo,wrePo)
   e iSreSceCanlatr(osol okrol;
Creating an HTTP server
         Set up PipelineFactory
piaefnlCanlieieatr pplnFcoy=
 rvt ia hnePplnFcoy ieieatr
   nwCanlieieatr( {
   e hnePplnFcoy)
  @vrie
  Oerd
  pbi Canlieiegtieie)trw Ecpin{
  ulc hnePpln ePpln( hos xeto

      Canlieiep=Canl.ieie)
      hnePpln    hnesppln(;
      padat"tpevroe" nwHtSreCdc);
      .dLs(htSreCdc, e tpevroe()

      padat"ade" nwCsoRqetade(lCanl);
      .dLs(hnlr, e utmeusHnlralhnes)

      rtr p
      eun ;
  }
};
Creating an HTTP server
 Put all together with Bootstrap
piaefnlSreBosrpbosrp=nwSreBosrpca
 rvt ia evrotta otta e evrotta(h
neFcoy;
 nlatr)

 ...

bosrpstieieatr(ieieatr)
 otta.ePplnFcoypplnFcoy;

/ Otosfraprn canl-i acpscnetos
 / pin o aet hne   t cet oncin
bosrpstpin"oaAdes,nwIeSceAdespr);
 otta.eOto(lcldrs" e ntoktdrs(ot)
bosrpstpin"esAdes,tu)
 otta.eOto(ruedrs" re;

/ Otosfriscide -te poesI
 / pin o t hlrn hy rcs O
bosrpstpin"hl.cNDly,tu)
 otta.eOto(cidtpoea" re;
bosrpstpin"hl.eplv" fle;
 otta.eOto(cidkeAie, as)
Creating an HTTP server
    Writing a custom handler
casCsoHnlretnsSmlCanlptemade {
 ls utmade xed ipehneUsraHnlr
   ...
  @vrie
   Oerd
  pbi vi msaeeevdCanladeCnetcx Msae
   ulc od esgRcie(hneHnlrotx t, esgE
vn e trw Ecpin{
 et ) hos xeto
    HtRqetrq=(tpeus)egtesg(;
     tpeus e   HtRqet .eMsae)
    / pouersos adwiei t acanl
     / rdc epne n rt t o hne
    HtRsos rs=nwDfuttpepneHT__,O)
     tpepne e   e ealHtRsos(TP11 K;
    Canluueftr =Canl.rt(t.eCanl) rs;
     hneFtr uue   hneswiecxgthne(, e)
    ftr.dLsee(hneFtrLsee.LS)
     uueaditnrCanluueitnrCOE;
  }
}
Creating an HTTP server
Gather channels for future closing
piaefnlCanlru alhnes=nwDfuthneGop
 rvt ia hneGop lCanl    e ealCanlru(
)
    ...
/ aanisd orcso hnlr
 / gi nie u utm ade
casCsoHnlretnsSmlCanlptemade {
 ls utmade xed ipehneUsraHnlr
    ...
    @vrie
    Oerd
  pbi vi canlpnCanladeCnetcx Canltt
   ulc od hneOe(hneHnlrotx t, hneSae
Eete trw Ecpin{
 vn ) hos xeto
    Canlcanl=egthne(;
    hne hne   .eCanl)
    alhnesadcanl;
    lCanl.d(hne)
  }
}
Creating an HTTP server
        Release resources
         close gathered channels
         release external resources

alhnescoe)aatnnerpil(;
 lCanl.ls(.wiUitrutby)
bosrprlaexenleore(;
 otta.eesEtraRsucs)
TCPnodelay, TCPkeepalive
  Remember that bootstrap code?

 / Otosfriscide -te poesI
  / pin o t hlrn hy rcs O
 bosrpstpin"hl.cNDly,tu)
  otta.eOto(cidtpoea" re;
 bosrpstpin"hl.eplv" fle;
  otta.eOto(cidkeAie, as)




   What do these options mean?
TCP keepAlive

prolongs each TCP connection
makes NAT router happy
TCP noDelay
   Nagle's algorithm

glues up small TCP packets
tries to reduce bandwidth
increases latency
TCPnodelay, TCPkeepalive

    To use,
 or not to use?
Don't ask,
measure!
Thank you
Additional resources
    netty @ github
    introductory article

Más contenido relacionado

La actualidad más candente

Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the networkMu Chun Wang
 
Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...Jaap ter Woerds
 
Developing High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoDeveloping High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoChris Stivers
 
Taking advantage of Prometheus relabeling
Taking advantage of Prometheus relabelingTaking advantage of Prometheus relabeling
Taking advantage of Prometheus relabelingJulien Pivotto
 
Python twisted
Python twistedPython twisted
Python twistedMahendra M
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Codemotion
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Alexey Fyodorov
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsDigitalOcean
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Tom Croucher
 
Twisted logic
Twisted logicTwisted logic
Twisted logicashfall
 
Async await in C++
Async await in C++Async await in C++
Async await in C++cppfrug
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8Ali Habeeb
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴명신 김
 
Nessus scan report using microsoft patchs scan policy - Tareq Hanaysha
Nessus scan report using microsoft patchs scan policy - Tareq HanayshaNessus scan report using microsoft patchs scan policy - Tareq Hanaysha
Nessus scan report using microsoft patchs scan policy - Tareq HanayshaHanaysha
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopyayaria
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkpeleksdev
 

La actualidad más candente (20)

Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the network
 
Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...Building scalable network applications with Netty (as presented on NLJUG JFal...
Building scalable network applications with Netty (as presented on NLJUG JFal...
 
Developing High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoDeveloping High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & Go
 
无锁编程
无锁编程无锁编程
无锁编程
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
 
Taking advantage of Prometheus relabeling
Taking advantage of Prometheus relabelingTaking advantage of Prometheus relabeling
Taking advantage of Prometheus relabeling
 
Python twisted
Python twistedPython twisted
Python twisted
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Twisted logic
Twisted logicTwisted logic
Twisted logic
 
Async await in C++
Async await in C++Async await in C++
Async await in C++
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
Nessus scan report using microsoft patchs scan policy - Tareq Hanaysha
Nessus scan report using microsoft patchs scan policy - Tareq HanayshaNessus scan report using microsoft patchs scan policy - Tareq Hanaysha
Nessus scan report using microsoft patchs scan policy - Tareq Hanaysha
 
The future of async i/o in Python
The future of async i/o in PythonThe future of async i/o in Python
The future of async i/o in Python
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkp
 

Destacado

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
 
Netty - a pragmatic introduction
Netty - a pragmatic introductionNetty - a pragmatic introduction
Netty - a pragmatic introductionRaphael Stary
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyDaniel Bimschas
 
Introduction of netty
Introduction of nettyIntroduction of netty
Introduction of nettyBing Luo
 
Real time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, KafkaReal time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, KafkaTrieu Nguyen
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenchesJordi Gerona
 
深入浅出Netty l.t
深入浅出Netty   l.t深入浅出Netty   l.t
深入浅出Netty l.toleone
 
Asynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyAsynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyErsin Er
 
Nettyらへん
NettyらへんNettyらへん
NettyらへんGo Tanaka
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System DevelopmentAllan Huang
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internalsNgoc Dao
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Baruch Sadogursky
 
Asynchronous serial data transfer, UART and CAN controller
Asynchronous serial data transfer, UART and CAN controllerAsynchronous serial data transfer, UART and CAN controller
Asynchronous serial data transfer, UART and CAN controllerJovan Vlajic
 
High performance network programming on the jvm oscon 2012
High performance network programming on the jvm   oscon 2012 High performance network programming on the jvm   oscon 2012
High performance network programming on the jvm oscon 2012 Erik Onnen
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.jsratankadam
 

Destacado (20)

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
 
Netty - a pragmatic introduction
Netty - a pragmatic introductionNetty - a pragmatic introduction
Netty - a pragmatic introduction
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
Introduction of netty
Introduction of nettyIntroduction of netty
Introduction of netty
 
Notes on Netty baics
Notes on Netty baicsNotes on Netty baics
Notes on Netty baics
 
Real time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, KafkaReal time analytics with Netty, Storm, Kafka
Real time analytics with Netty, Storm, Kafka
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenches
 
深入浅出Netty l.t
深入浅出Netty   l.t深入浅出Netty   l.t
深入浅出Netty l.t
 
Netty
NettyNetty
Netty
 
Asynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyAsynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with Netty
 
Nettyらへん
NettyらへんNettyらへん
Nettyらへん
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
 
Building Netty Servers
Building Netty ServersBuilding Netty Servers
Building Netty Servers
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internals
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
Netty
NettyNetty
Netty
 
Formal Grammars
Formal GrammarsFormal Grammars
Formal Grammars
 
Asynchronous serial data transfer, UART and CAN controller
Asynchronous serial data transfer, UART and CAN controllerAsynchronous serial data transfer, UART and CAN controller
Asynchronous serial data transfer, UART and CAN controller
 
High performance network programming on the jvm oscon 2012
High performance network programming on the jvm   oscon 2012 High performance network programming on the jvm   oscon 2012
High performance network programming on the jvm oscon 2012
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.js
 

Similar a Netty: asynchronous data transfer

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
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Evel xf
 
Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014P. Taylor Goetz
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel ProcessingRTigger
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code ExamplesNaresh Chintalcheru
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commandsRishu Seth
 
Trelles_QnormBOSC2009
Trelles_QnormBOSC2009Trelles_QnormBOSC2009
Trelles_QnormBOSC2009bosc
 
swift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientShinya Mochida
 
Opendaylight app development
Opendaylight app developmentOpendaylight app development
Opendaylight app developmentvjanandr
 
ATS Internals
ATS InternalsATS Internals
ATS InternalsChao Xu
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administrationvceder
 
The Functional Web
The Functional WebThe Functional Web
The Functional WebRyan Riley
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL EnvironmentLeveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL EnvironmentJim Mlodgenski
 

Similar a Netty: asynchronous data transfer (20)

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
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014Scaling Apache Storm - Strata + Hadoop World 2014
Scaling Apache Storm - Strata + Hadoop World 2014
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel Processing
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
 
Trelles_QnormBOSC2009
Trelles_QnormBOSC2009Trelles_QnormBOSC2009
Trelles_QnormBOSC2009
 
swift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClient
 
Opendaylight app development
Opendaylight app developmentOpendaylight app development
Opendaylight app development
 
Scalaxb preso
Scalaxb presoScalaxb preso
Scalaxb preso
 
Storm Anatomy
Storm AnatomyStorm Anatomy
Storm Anatomy
 
ATS Internals
ATS InternalsATS Internals
ATS Internals
 
ATS Internals
ATS InternalsATS Internals
ATS Internals
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 
The Functional Web
The Functional WebThe Functional Web
The Functional Web
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL EnvironmentLeveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL Environment
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
 

Último

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Netty: asynchronous data transfer

  • 1. Netty List("Asynchronous", "data", "transfer") ::: List("practical", "aspects") Victor Cherkassky "vcherkassky@gmail.com"
  • 2. What is Netty IO library IO cat Files > Networking
  • 3. What is Netty IO library asynchronous ChannelFuture future = channel.write(message) future.addListener(WRITE_COMPLETE_LISTENER)
  • 4. What is Netty IO library asynchronous non-blocking       /**         * This method blocks until input data is available         */ InputStream.read()
  • 5. What is Netty IO library asynchronous non-blocking multi-protocol HTTP | WebSocket | Protobuf | Binary TCP | UDP
  • 6. blocking vs non-blocking blocking (OIO) Ipttemi =nwFlIpttem"nu.i"; nuSra s e ienuSra(iptbn) itbt =i.ed) / crettra wisfrrsl o err n ye sra(; / urn hed at o eut r ro non-blocking (NIO) wie(re { hl tu) slco.eet) / rqetn eet fo mlil canl eetrslc(; / eusig vns rm utpe hnes Ieao i =slco.eetdes)ieao(; trtr t eetrslceKy(.trtr) wie(thset) { hl i.aNx() SlcoKyky=(eetoKy i.et) eetre e Slcine) tnx(; hnlKyky; adee(e) i.eoe) trmv(; } }
  • 7. blocking vs non-blocking Hardware blocking write
  • 8. blocking vs non-blocking Hardware non-blocking write: DMA
  • 9. blocking vs non-blocking OS select()/poll() - traditional POSIX polling O(n) epoll() - event-based polling O(1), Linux 2.5.44+ kqueue - FreeBSD, Mac OS X I/O Completion Ports - Windows NT 3.5+, Solaris 10+
  • 10. blocking vs non-blocking Java SelectableChannel.register(selector) - blocking operation, registers an "interest" for IO events Selector.select - non-blocking operation, checks for occurred events
  • 11. blocking vs non-blocking Java OS select() / poll() / kqueue Channel.register & Selector.select I/O Completion Ports epoll() - Java 1.6+
  • 12. Thread model Tomcat 1 request = 1 thread fast for ~1000 clients too much memory
  • 13. Thread model Node.js all requests = 1 thread super scalable limited error handling
  • 14. Thread model Netty many requests = 1 thread flexible model
  • 18. All terms together Channel (socket read/write) channel Buffer (byte array) channel Event (message) channel Pipeline (message bus) channel Handler (message handler) Upstream Event (from socket) Downstream Event (to socket)
  • 19. Creating an HTTP server Set up thread pools boss pool for handling incoming connections worker pool for processing IO piaefnlEeuo bsPo =Eeuosnwahdhedol) rvt ia xctr osol xctr.eCceTraPo( ; piaefnlEeuo wrePo =Eeuosnwahdhedol rvt ia xctr okrol xctr.eCceTraPo (; )
  • 20. Creating an HTTP server Provide ChannelFactory piaefnlCanlatr canlatr = rvt ia hneFcoy hneFcoy nwNoevrokthneFcoybsPo,wrePo) e iSreSceCanlatr(osol okrol;
  • 21. Creating an HTTP server Set up PipelineFactory piaefnlCanlieieatr pplnFcoy= rvt ia hnePplnFcoy ieieatr nwCanlieieatr( { e hnePplnFcoy) @vrie Oerd pbi Canlieiegtieie)trw Ecpin{ ulc hnePpln ePpln( hos xeto Canlieiep=Canl.ieie) hnePpln hnesppln(; padat"tpevroe" nwHtSreCdc); .dLs(htSreCdc, e tpevroe() padat"ade" nwCsoRqetade(lCanl); .dLs(hnlr, e utmeusHnlralhnes) rtr p eun ; } };
  • 22. Creating an HTTP server Put all together with Bootstrap piaefnlSreBosrpbosrp=nwSreBosrpca rvt ia evrotta otta e evrotta(h neFcoy; nlatr) ... bosrpstieieatr(ieieatr) otta.ePplnFcoypplnFcoy; / Otosfraprn canl-i acpscnetos / pin o aet hne t cet oncin bosrpstpin"oaAdes,nwIeSceAdespr); otta.eOto(lcldrs" e ntoktdrs(ot) bosrpstpin"esAdes,tu) otta.eOto(ruedrs" re; / Otosfriscide -te poesI / pin o t hlrn hy rcs O bosrpstpin"hl.cNDly,tu) otta.eOto(cidtpoea" re; bosrpstpin"hl.eplv" fle; otta.eOto(cidkeAie, as)
  • 23. Creating an HTTP server Writing a custom handler casCsoHnlretnsSmlCanlptemade { ls utmade xed ipehneUsraHnlr ... @vrie Oerd pbi vi msaeeevdCanladeCnetcx Msae ulc od esgRcie(hneHnlrotx t, esgE vn e trw Ecpin{ et ) hos xeto HtRqetrq=(tpeus)egtesg(; tpeus e HtRqet .eMsae) / pouersos adwiei t acanl / rdc epne n rt t o hne HtRsos rs=nwDfuttpepneHT__,O) tpepne e e ealHtRsos(TP11 K; Canluueftr =Canl.rt(t.eCanl) rs; hneFtr uue hneswiecxgthne(, e) ftr.dLsee(hneFtrLsee.LS) uueaditnrCanluueitnrCOE; } }
  • 24. Creating an HTTP server Gather channels for future closing piaefnlCanlru alhnes=nwDfuthneGop rvt ia hneGop lCanl e ealCanlru( ) ... / aanisd orcso hnlr / gi nie u utm ade casCsoHnlretnsSmlCanlptemade { ls utmade xed ipehneUsraHnlr ... @vrie Oerd pbi vi canlpnCanladeCnetcx Canltt ulc od hneOe(hneHnlrotx t, hneSae Eete trw Ecpin{ vn ) hos xeto Canlcanl=egthne(; hne hne .eCanl) alhnesadcanl; lCanl.d(hne) } }
  • 25. Creating an HTTP server Release resources close gathered channels release external resources alhnescoe)aatnnerpil(; lCanl.ls(.wiUitrutby) bosrprlaexenleore(; otta.eesEtraRsucs)
  • 26. TCPnodelay, TCPkeepalive Remember that bootstrap code? / Otosfriscide -te poesI / pin o t hlrn hy rcs O bosrpstpin"hl.cNDly,tu) otta.eOto(cidtpoea" re; bosrpstpin"hl.eplv" fle; otta.eOto(cidkeAie, as) What do these options mean?
  • 27. TCP keepAlive prolongs each TCP connection makes NAT router happy
  • 28. TCP noDelay Nagle's algorithm glues up small TCP packets tries to reduce bandwidth increases latency
  • 29. TCPnodelay, TCPkeepalive To use, or not to use?
  • 31. Thank you Additional resources netty @ github introductory article