+ All Categories
Home > Technology > Netty - anfix tech&beers

Netty - anfix tech&beers

Date post: 09-Jul-2015
Category:
Upload: jorgecarabias
View: 96 times
Download: 1 times
Share this document with a friend
21

Click here to load reader

Transcript
Page 1: Netty - anfix tech&beers
Page 2: Netty - anfix tech&beers
Page 3: Netty - anfix tech&beers

¿Qué  narices  es  esto?

Page 4: Netty - anfix tech&beers
Page 5: Netty - anfix tech&beers

Siempre  hay  un  villano

Page 6: Netty - anfix tech&beers

Suppose  you  go  to  +Starbucks  Coffee    ,  you  EnQueue  (brush  up  Data  Structures  :P  )    to  order  your  coffee,  you  stay  in  the  queue  unFl  you  get  your  chance  to  order,  and  once  you  order  and  pay,  you  sFll  stay  there  blocking  the  queue  unFl  you  get  your  coffee,  won't  that  be  awkward  ??  (if  No  then  go  Synchronous,  that's  best  for  you  :)  else  come  to  the  world  of  NeKy  )  because  we  love  Asynchronous  things  in  life  e.g  Chat  vs  Call.  

Page 7: Netty - anfix tech&beers

Síncrono  no....  asíncrono!!!

IO  vs  NIO

1)  IO  streams  versus  NIO  blocksposiblidad  de  recorrer  el  buffer

2)  Synchronous  vs.  Asynchronous  IO  stream  -­‐>  hilo  bloqueado  nio  -­‐>  mismo  hilo  sirve  diferentes  canales

3)  IO  Versus  NIO  APIs  apis  más  sencillas,  no  necesidad  de  crear  buffer

Page 8: Netty - anfix tech&beers

ServidorClienteHTTP

FTP

Mail

Finanzas  -­‐  real  Fme,  otros

Streaming

Ficheros  grandes

Cliente  HTTP

Cliente  FTP

Cliente  Mail

Cliente  Ficheros

Cliente  Finanzas

Cliente  Streaming

Page 9: Netty - anfix tech&beers

-­‐ Complicado  de  programar  por  la  heterogeneidad

-­‐ Mal  rendimiento

-­‐ Mal  escalado

:((((

Page 10: Netty - anfix tech&beers

Framework  para  el  desarrollo  de  clientes  y  servidores.  Facilita  toda  la  programación  del  protocolo.  API  unificada  para  diferentes  transportes  y  protocolos.

Diseñado  para  crear  clientes-­‐servidores  altamente  escalables  y  de  alto  rendimiento.

Desarrollo  fácil  y  rápido  :)

hKp://neKy.io  -­‐  proyecto  de  código  abierto  disponible  en  github

Soporta  SPDY!!!

Page 11: Netty - anfix tech&beers
Page 12: Netty - anfix tech&beers

Features

Design

• Unified  API  for  various  transport  types  -­‐  blocking  and  non-­‐blocking  socket• Based  on  a  flexible  and  extensible  event  model  which  allows  clear  separaBon  of  concerns• Highly  customizable  thread  model  -­‐  single  thread,  one  or  more  thread  pools  such  as  SEDA• True  connecBonless  datagram  socket  support  (since  3.1)

Ease  of  use

• Well-­‐documented  Javadoc,  user  guide  and  examples• No  addiBonal  dependencies  but  JDK  1.5  (or  above)

Performance

• BeTer  throughput,  lower  latency• Less  resource  consumpBon• Minimized  unnecessary  memory  copy

Security

• Complete  SSL/TLS  and  StartTLS  support

Community

• Release  early,  release  oZen• The  author  has  been  wriBng  similar  frameworks  since  2003  and  he  sBll  finds  your  feed  back  precious!

Page 13: Netty - anfix tech&beers

Para  empezar  a  cocinar  con  neKy...

-­‐ Ingredientes:

-­‐ Tener  Java  instalado  (JDK  6)  

-­‐ Tener  descargado  el  proyecto  de  neKy.io

-­‐ 5.0.0  versión  alpha  (jdk  1.7)

-­‐ 4.0.17  la  úlFma  estable  (jdk  1.6)

-­‐ También  en  modo  “maven”

-­‐ Montarlo  en  Eclipse  o  Netbeans  para  un  proyecto

<dependencies>    ...    <dependency>        <groupId>io.neKy</groupId>        <arFfactId>neKy</arFfactId>  <!-­‐-­‐  Use  'neKy-­‐all'  for  4.0  or  above  -­‐-­‐>        <version>X.Y.Z.Q</version>        <scope>compile</scope>    </dependency>    ...</dependencies>

Page 14: Netty - anfix tech&beers

Terminología:

Channel: a abstraction for communication or transfer of data (byte array)

ChannelBuffer: Byte array which can provide random or direct data storage mechanism.

ChannelPipeline: collection of handlers to process your events in the way you

want. ChannelFactory: Resource allocators, like thread pools.

ChannelHandler: Provides method to handle events on channel.ChannelEvents: Events like connected, exception raised, message recieved

etc.

Page 15: Netty - anfix tech&beers

o  lo  vemos  en  acción  o  no  me  entero...

Page 16: Netty - anfix tech&beers

¿y  esto  se  usa?

Page 17: Netty - anfix tech&beers

Twitter

hKps://blog.twiKer.com/2014/neKy-­‐at-­‐twiKer-­‐with-­‐finagle

143,199 TPS

Page 18: Netty - anfix tech&beers

Facebookpublic  void  startServer()  {        //  Create  the  handler        MyService.Iface  serviceInterface  =  new  MyServiceHandler();

       //  Create  the  processor        TProcessor  processor  =  new  MyService.Processor<>(serviceInterface);

       //  Build  the  server  definiFon        ThrisServerDef  serverDef  =  new  ThrisServerDefBuilder().withProcessor(processor)                                                                                                                        .build();

       //  Create  the  server  transport        final  NeKyServerTransport  server  =  new  NeKyServerTransport(serverDef,                                                                                                                                  new  NeKyConfigBuilder(),                                                                                                                                  new  DefaultChannelGroup(),                                                                                                                                  new  HashedWheelTimer());

       //  Create  neKy  boss  and  executor  thread  pools        ExecutorService  bossExecutor  =  Executors.newCachedThreadPool();        ExecutorService  workerExecutor  =  Executors.newCachedThreadPool();

       //  Start  the  server        server.start(bossExecutor,  workerExecutor);

       //  Arrange  to  stop  the  server  at  shutdown        RunFme.getRunFme().addShutdownHook(new  Thread()  {                @Override                public  void  run()  {                        try  {                                server.stop();                        }  catch  (InterruptedExcepFon  e)  {                                Thread.currentThread().interrupt();                        }                }        });}

hKps://github.com/facebook/nisy

Page 19: Netty - anfix tech&beers

Remember  the  milk

hKp://blog.rememberthemilk.com/2011/08/real-­‐Fme-­‐updaFng-­‐comes-­‐to-­‐the-­‐remember-­‐the-­‐milk-­‐web-­‐app/

Page 21: Netty - anfix tech&beers

Gracias!(por  aguantar...)


Recommended