SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante 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
 

Semelhante 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

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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