SlideShare une entreprise Scribd logo
1  sur  95
WebSockets et Atmosphere

       Jeanfrancois Arcand

       twitter.com/jfarcand
facebook.com/jeanfrancois.arcand.3
Who is Wordnik?

• Founded in 2008 by Erin McKean
• "Understand meaning of words
  automatically"
• Patented "Free-Range Definition"
  technology
• Constructed largest (known) English Word
  Graph
      We do Discovery – in real time!!
Atmosphere

 Apache 2      Github ~450
               « followers »
                               Client +
  Supporté                     server
par + de 25
frameworks                     Scala, Groovy,
                                JRuby, Java
   Depuis
                    20 000 et plus
    2008
                 téléchargement par
1.0.0.beta1             mois!
Atmosphere

 Apache 2      Github ~450
               « followers »
                               Client +
  Supporté    Très Très
                               server
par + de 25     actif!!!
frameworks                     Scala, Groovy,
                                JRuby, Java
   Depuis
                     20 000 et plus
    2008
                  téléchargement par
                         mois!
WSJ.com

• 40 millions de requêtes par jours
• Atmosphere 0.9.4/Jetty 8.1.3
• Websockets => long-polling => JSONP
• IE 6/7/8/9/10, Chrome XX, Firefox 3/12,
  Safari XX
• WebSockets: IE 10, Chrome 14, Firefox
  8, Safari 5
Mon WebSocket au Canada!
        WebSocket
Mon WebSocket au Canada!
             WebSocket

C’est quoi
Mon WebSocket au Canada!
             WebSocket

C’est quoi               N’importe
                            quoi!
Mon WebSocket au Canada!
             WebSocket

C’est quoi               N’importe
                            quoi!

             Atmospher
                 e
Mon WebSocket au Canada!
                WebSocket

   C’est quoi               N’importe
                               quoi!

                Atmospher
                    e
Concepts
Mon WebSocket au Canada!
                WebSocket

   C’est quoi               N’importe
                               quoi!

                Atmospher
                    e
Concepts                     Démo
WebSockets


Le protocole WebSocket vise à
développer un canal de
communication bidirectionnel
et « full-duplex » sur un
socket TCP pour les fureteurs
et les serveurs web.
Avant (Long-Polling)

               Requête


Fureteu                          Server
   r
Avant (Long-Polling)

               Requête


Fureteu                          Server
   r
Avant (Long-Polling)

               Requête


Fureteu                          Server
   r
               Réponse
Oups!!


          Requête

Fureteu        Rien   Server
   r
Oups!

          Requête


Fureteu             Server
   r
                    Zzzz
Mieux!


          Requête

Fureteu                 Server
   r

                      Cache
Mieux!

          Requête


Fureteu               Server
   r

                    Cache
A la limite (HTTP Streaming)

            Requête


Fureteu                    Server
   r
A la limite (HTTP Streaming)

            Requête


Fureteu                    Server
   r
A la limite (HTTP Streaming)

            Requête


Fureteu                    Server
   r
            Réponse
A la limite (HTTP Streaming)

            Requête


Fureteu                    Server
   r
            Réponse

            Réponse
Oups!!

           Requête


Fureteu              Server
   r
  L’enfe   Réponse
     r
           Réponse
A la limite (HTTP Streaming)

            Requête


Fureteu                    Server
   r
  L’enfe
   Hack     Réponse
     r
            Réponse
Oups!!!

          Requête


Fureteu              Server
   r
          Réponse
             Proxy
          Réponse
Mieux

          Requête


Fureteu                 Server
   r
          Réponse   Cache

          Réponse
Mieux

           Requête


Fureteu                     Server
   r
          Réponse       Cache
          «Réponse
            HeartBeat
               »
Mieux: Server Side Events (SSE)

           Requête


Fureteu                  Server
   r
           Réponse

           Réponse
Oups!!!

          Requête


Fureteu              Server
   r
          Réponse
             Proxy
          Réponse
Mieux

           Requête


Fureteu                     Server
   r
          Réponse       Cache
          «Réponse
            HeartBeat
               »
WebSockets

           Hanshake


Fureteu                Server
   r
WebSockets

           Hanshake


Fureteu                Server
   r
             OK
WebSockets

           Requête


Fureteu                Server
   r
WebSockets

           Requête


Fureteu                Server
   r
WebSockets




Fureteu                Server
   r
           Réponse
WebSockets

           Requête


Fureteu                Server
   r
WebSockets

           Requête

            Requête
Fureteu                Server
   r
WebSockets

           Requête

            Requête
Fureteu                Server
   r
WebSockets




Fureteu                Server
   r
           Réponse

           Réponse
A TOUS moment




Fureteu                   Server
   r
             Réponse
Ah la belle vie, la vie, la vie ahah!




Fureteu                       Server
   r
             Réponse
Oups!!




Fureteu              Server
   r
          Réponse
             Proxy
Mieux!




Fureteu                 Server
   r
          Réponse   Cache
Première requête
T 127.0.0.1:65062 -> 127.0.0.1:8080 [AP]
GET / HTTP/1.1.
Upgrade: websocket.
Connection: Upgrade.
Host: 127.0.0.1:8080.
Origin: http://127.0.0.1:8080.
Sec-WebSocket-Key: Tz9qdt3lmte6Slf+GvpRqQ==.
Sec-WebSocket-Version: 13.
Sec-WebSocket-Extensions: x-webkit-deflate-
frame.
Réponse
T 127.0.0.1:8080 -> 127.0.0.1:51292 [AP]
HTTP/1.1 101 Switching Protocols.
Upgrade: WebSocket.
Connection: Upgrade.
Sec-WebSocket-Accept:
HVXA7SqH5uYeN6aD9tZ0JQbfTJA=.
Ah la belle vie, la vie, la vie, ahah
T 127.0.0.1:8080 -> 127.0.0.1:51292 [AP]
HTTP/1.1 101 Switching Protocols.
Upgrade: WebSocket.
Connection: Upgrade.
Sec-WebSocket-Accept:
HVXA7SqH5uYeN6aD9tZ0JQbfTJA=.
OUPS!!!
T 127.0.0.1:8080 -> 127.0.0.1:65064 [AP]
HTTP/1.1 501 Not Implemented.
Server: Apache-Coyote/1.1.
X-Atmosphere-error: Websocket protocol not
supported.
Transfer-Encoding: chunked.
Date: Fri, 15 Jun 2012 10:06:30 GMT.
Connection: close.
.
WebSocket API – Standard
           JavaScript
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { …};
websocket.onclose = function(evt) { …};
websocket.onmessage = function(evt) { …};
websocket.onerror = function(evt) { …};


webSocket.send(…)
WebSocket API – Java

Jetty 7, GlassFish 3.1, Netty 3, Tomcat
7.0.27, Resin 4, JBoss Plugin


JSR 356:
http://jcp.org/en/jsr/detail?id=356


AHC (Client -> De facto)
http://github.com/sonatype/async-http-
client
Ah la belle vie,
la vie, la vie, ahah
OUPS!!!
C’est parti!
Safari                   Tomcat
                            7
Firefox                  Jetty7

                          Jetty8
Chrome

                         GlassFis
Opera                      h3.
                         GlassFis
  IE                        h
                           312
N’importe quoi
Safari                     Tomcat
                              7
Firefox                    Jetty7

                            Jetty8
Chrome

                           GlassFis
Opera                        h3.
                           GlassFis
  IE                          h
                             312
N’importe quoi
Safari                     Tomcat
                              7
Firefox                    Jetty7

            Au              Jetty8
Chrome
          Secours
                           GlassFis
Opera        !!              h3.
                           GlassFis
  IE                          h
                             312
N’importe quoi
Safari                         Tomcat
                                  7
          Streamin             Jetty7
Firefox
              g
                  Au            Jetty8
Chrome
                Secours
                               GlassFis
Opera              !!            h3.
                               GlassFis
  IE                              h
                                 312
N’importe quoi
Safari                        Tomcat
                                 7
          Streamin            Jetty7
Firefox
              g
                  Au SSE       Jetty8
Chrome
                Secours
                              GlassFis
Opera              !!           h3.
                              GlassFis
  IE                             h
                                312
N’importe quoi
Safari                         Tomcat
                                  7
          Streamin             Jetty7
Firefox
              g
                  Au SSE   Jetty8
Chrome
                Secours
                          GlassFis
Opera              !!   JSONP
                            h3.
                               GlassFis
  IE                              h
                                 312
N’importe quoi
Safari                         Tomcat
                                  7
        Streamin               Jetty7
Firefox
            g
                Au SSE   Jetty8
Chrome
              Secours
                        GlassFis
 Opera           !!   JSONP
                          h3.
        Long
                               GlassFis
  IE     Polling                  h
                                 312
Safari                    Tomcat
                             7
Firefox                   Jetty7
          Atmosphere à
Chrome          la         Jetty8

           rescousse!!!   GlassFis
Opera                       h3.
                          GlassFis
  IE                         h
                            312
Atmosphere -WebSockets

Safari                                        Tomcat
                                                 7
                                              Jetty7




                             Atmosphere API
Firefox
             atmosphere.js
                                               Jetty8
Chrome

                                              GlassFis
Opera                                           h3.
                                              GlassFis
  IE                                             h
                                                312
Atmosphere - HTML5 Server Side
               Events
Safari                                     Tomcat
                                              7
                                           Jetty7




                          Atmosphere API
Firefox
          atmosphere.js
                                           Servlet
Chrome
                                             3
                                           WebLogi
Opera                                        c
                                           GlassFis
  IE                                          h
                                             312
Atmosphere Long-Polling/HTTP
                Streaming
Safari                                        JBoss

                                              Jetty7




                            Atmosphere API
Firefox
            atmosphere.js
                                             Servlet
Chrome
                                               3
                                             WebLogi
Opera                                          c.
                                             GlassFis
  IE                                            h
Atmosphere

Safari                                                   JBoss

                                                         Jetty7




                                       Atmosphere API
Firefox
          atmosphere.js
               Même API,
Chrome       peut importe                               Servlet
                                                          3
             le transport!!                             WebLogi
Opera                                                     c.
                                                        GlassFis
  IE                                                       h
Socket.IO, GWT, Wicket, JSF, etc.

Safari                                     JBoss

                                           Jetty7




                         Atmosphere API
Firefox
          Socket.IO
                                          Servlet
Chrome
                                            3
                                          WebLogi
Opera                                       c.
                                          GlassFis
  IE                                         h
PORTABLE!!!!!

Safari                                             JBoss

                                                   Jetty7




                                 Atmosphere API
Firefox
          Socket.IO
                      PORTABLE                    Servlet
Chrome
                                                    3
                                                  WebLogi
Opera                                               c.
                                                  GlassFis
  IE                                                 h
Grosse Erreur!!!!!

• Toutframework ne supportant
 que les WebSockets



     Mise en
   production
  IMPOSSIBLE
Atmosphere
Définition

• Suspend: décrocher la ligne
• Resume: racrocher la ligne
• Broadcast: parler sur une ou
 plusieurs lignes, seul, à deux
 ou plusieurs.
Requête Normale

Fureteu
   r


Fureteu                     Server
   r


Fureteu
   r
Requête Normale

Fureteu
   r


Fureteu                     Server
   r


Fureteu
   r
Suspend

Fureteu
   r


Fureteu             Server
   r


Fureteu
   r
Suspend

Fureteu
   r

                    S
Fureteu              Server
   r


Fureteu
   r
Suspend

Fureteu
   r

                    S
Fureteu              Server
   r


Fureteu
   r
Suspend

Fureteu
   r

                    S
Fureteu              Server
   r


Fureteu
   r
Broadcast

Fureteu
   r
                               B
                      S
Fureteu               Server
   r


Fureteu
   r
Broadcast

Fureteu
   r
                               B
                      S
Fureteu               Server
   r


Fureteu
   r
Resume

Fureteu
   r
                                B

Fureteu                Server
   r               R


Fureteu
   r
Resume

Fureteu
   r
                                B

Fureteu                Server
                   S
   r


Fureteu
   r
Broadcaster

• Default:    in-memory
• Nuage
 •   RedisBroadcaster
 •   JMSBroadcaster
 •   XMPPBroadcaster
 •   HazelcastBroadcaster
 •   JGroupsBroascaster
• Multi-Threads,        Async I/O par
 default
Broadcaster Nuage

Fureteu
   r                          S
                              Server

Fureteu
   r


Fureteu                   S Server
   r
Broadcaster Nuage

Fureteu
   r                          S
                              Server

Fureteu
   r


Fureteu                   S Server
   r
Broadcaster Nuage

Fureteu                                B
   r                          S
                              Server

Fureteu
   r


Fureteu                   S Server
   r
Broadcaster Nuage

Fureteu                             B
   r                          Server


Fureteu
   r


Fureteu
   r                          Server
Broadcaster Nuage

Fureteu
   r                          Server


Fureteu
   r
                                       B
Fureteu
   r                          Server
Broadcaster Nuage

Fureteu
   r                          Server


Fureteu
   r


Fureteu
   r                          Server
Composantes Atmosphere

• WebSocketHandler
 •   Seulement WebSocket (ATTENTION)!
• AtmosphereHandler
 •   Tout les protocoles
• Jersey   Resource
 •   Tout les protocoles
• Meteor
 •   Tout les protocoles
WebSocket Sub Protocol

• WebSocketProtocol
 Definir sont propre WebSocket protocol.


• Atmosphere,par default,
 utilise le SimpleHttpProtocol
   Message WebSocket transformé en HTTP
   POST, avec read/write asynchrone.
• SwaggerSocket:REST over
 WebSockets -> Protocol plus
 puissant
Construction d’une appli
Hello, Swagger

• Swagger is…
 •   Spec for declaring an API schema
 •   A framework for auto-generating the spec
 •   A library for client library generation
 •   A JSON-based test framework
What is this Resource Declaration?

• Listing of all available APIs
http://petstore.swagger.wordnik.com/api/resources.json




                                      “It’s like a
                                     sitemap for
                                      your API!”
Démo
But What about Speed?

• Yes!   REST over HTTP is slow
 •   Connection overhead
 •                                 Your
     Marshaling & Unmarshaling overhead prod
 •   Chatter                     Database
 •   JSON/XML need to diet       isn't doing
• It's also…                       REST
 •   Synchronous
 •   GET/POST/PUT/DELETE don't cut it
SwaggerSocket

• REST over WebSocket
• Protocole basé sur JSON
• Performance améliorée
• Simple
• Supporte également sur HTTP.
• Supporte le multi
 requètes/réponses.
Powered By Wordnik



           twitter.com/wordnik
      twitter.com/atmo_framework
       twitter.com/swaggersocket

http://github.com/Atmosphere/atmosphere
http://github.com/wordnik/swaggersocket

Contenu connexe

Similaire à Introduction au WebSockets via le projet Atmosphere

Programmation web asynchrone avec Tornado
Programmation web asynchrone avec TornadoProgrammation web asynchrone avec Tornado
Programmation web asynchrone avec TornadoRonan Amicel
 
Cours 2/3 - Architecture Web
Cours 2/3 - Architecture WebCours 2/3 - Architecture Web
Cours 2/3 - Architecture WebAdyax
 
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...Ouadie LAHDIOUI
 
Performance des sites web - Latence - AFUP 2010
Performance des sites web - Latence - AFUP 2010Performance des sites web - Latence - AFUP 2010
Performance des sites web - Latence - AFUP 2010Eric D.
 
ASFA - Architecture cible du projet COLSA
ASFA - Architecture cible du projet COLSA ASFA - Architecture cible du projet COLSA
ASFA - Architecture cible du projet COLSA Frédéric Sagez
 
"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG
"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG
"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUGAntonio Gomes Rodrigues
 
Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Hugo Hamon
 
Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !VISEO
 
Réu technodejs
Réu technodejsRéu technodejs
Réu technodejsnaholyr
 
NodeJs, une introduction
NodeJs, une introductionNodeJs, une introduction
NodeJs, une introductionToxicode
 
Introduction dans la Programmation Web Course 1
Introduction dans la Programmation Web Course 1Introduction dans la Programmation Web Course 1
Introduction dans la Programmation Web Course 1Vlad Posea
 
La mise en cache et ses secrets
La mise en cache et ses secretsLa mise en cache et ses secrets
La mise en cache et ses secretsAymeric Bouillat
 
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs WebUne visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs WebFrédéric Harper
 
Présentation de CakePHP, 22/04/2010
Présentation de CakePHP, 22/04/2010Présentation de CakePHP, 22/04/2010
Présentation de CakePHP, 22/04/2010Guillaume Sautereau
 
Retour AFUP du forumphp 2017
Retour AFUP du forumphp 2017Retour AFUP du forumphp 2017
Retour AFUP du forumphp 2017AFUP_Limoges
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Jean-Laurent de Morlhon
 
2013 01-08-php-maturite
2013 01-08-php-maturite2013 01-08-php-maturite
2013 01-08-php-maturiteRémi Alvado
 

Similaire à Introduction au WebSockets via le projet Atmosphere (20)

Programmation web asynchrone avec Tornado
Programmation web asynchrone avec TornadoProgrammation web asynchrone avec Tornado
Programmation web asynchrone avec Tornado
 
Cours 2/3 - Architecture Web
Cours 2/3 - Architecture WebCours 2/3 - Architecture Web
Cours 2/3 - Architecture Web
 
WebSocket avec Java EE 7
WebSocket avec Java EE 7WebSocket avec Java EE 7
WebSocket avec Java EE 7
 
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
Real-Time applications avec la spécification Java (JSR 356) et le protocole W...
 
Performance des sites web - Latence - AFUP 2010
Performance des sites web - Latence - AFUP 2010Performance des sites web - Latence - AFUP 2010
Performance des sites web - Latence - AFUP 2010
 
PHP et PHP Framework
PHP et PHP FrameworkPHP et PHP Framework
PHP et PHP Framework
 
ASFA - Architecture cible du projet COLSA
ASFA - Architecture cible du projet COLSA ASFA - Architecture cible du projet COLSA
ASFA - Architecture cible du projet COLSA
 
"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG
"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG
"Apache JMeter, Java et Groovy sont sur un bateau" présentée au Paris JUG
 
Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)
 
Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !
 
Réu technodejs
Réu technodejsRéu technodejs
Réu technodejs
 
NodeJs, une introduction
NodeJs, une introductionNodeJs, une introduction
NodeJs, une introduction
 
Introduction dans la Programmation Web Course 1
Introduction dans la Programmation Web Course 1Introduction dans la Programmation Web Course 1
Introduction dans la Programmation Web Course 1
 
La mise en cache et ses secrets
La mise en cache et ses secretsLa mise en cache et ses secrets
La mise en cache et ses secrets
 
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs WebUne visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
 
Présentation de CakePHP, 22/04/2010
Présentation de CakePHP, 22/04/2010Présentation de CakePHP, 22/04/2010
Présentation de CakePHP, 22/04/2010
 
Réseau MiNET
Réseau MiNETRéseau MiNET
Réseau MiNET
 
Retour AFUP du forumphp 2017
Retour AFUP du forumphp 2017Retour AFUP du forumphp 2017
Retour AFUP du forumphp 2017
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
 
2013 01-08-php-maturite
2013 01-08-php-maturite2013 01-08-php-maturite
2013 01-08-php-maturite
 

Plus de jfarcand

Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!jfarcand
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmospherejfarcand
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Javajfarcand
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scalajfarcand
 
Servlet Async I/O Proposal (NIO.2)
Servlet Async I/O Proposal (NIO.2)Servlet Async I/O Proposal (NIO.2)
Servlet Async I/O Proposal (NIO.2)jfarcand
 
Async Http Client for Java and Scripting Language
Async Http Client for Java and Scripting LanguageAsync Http Client for Java and Scripting Language
Async Http Client for Java and Scripting Languagejfarcand
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Frameworkjfarcand
 

Plus de jfarcand (7)

Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmosphere
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Java
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
 
Servlet Async I/O Proposal (NIO.2)
Servlet Async I/O Proposal (NIO.2)Servlet Async I/O Proposal (NIO.2)
Servlet Async I/O Proposal (NIO.2)
 
Async Http Client for Java and Scripting Language
Async Http Client for Java and Scripting LanguageAsync Http Client for Java and Scripting Language
Async Http Client for Java and Scripting Language
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Framework
 

Introduction au WebSockets via le projet Atmosphere

  • 1. WebSockets et Atmosphere Jeanfrancois Arcand twitter.com/jfarcand facebook.com/jeanfrancois.arcand.3
  • 2. Who is Wordnik? • Founded in 2008 by Erin McKean • "Understand meaning of words automatically" • Patented "Free-Range Definition" technology • Constructed largest (known) English Word Graph We do Discovery – in real time!!
  • 3. Atmosphere Apache 2 Github ~450 « followers » Client + Supporté server par + de 25 frameworks Scala, Groovy, JRuby, Java Depuis 20 000 et plus 2008 téléchargement par 1.0.0.beta1 mois!
  • 4. Atmosphere Apache 2 Github ~450 « followers » Client + Supporté Très Très server par + de 25 actif!!! frameworks Scala, Groovy, JRuby, Java Depuis 20 000 et plus 2008 téléchargement par mois!
  • 5. WSJ.com • 40 millions de requêtes par jours • Atmosphere 0.9.4/Jetty 8.1.3 • Websockets => long-polling => JSONP • IE 6/7/8/9/10, Chrome XX, Firefox 3/12, Safari XX • WebSockets: IE 10, Chrome 14, Firefox 8, Safari 5
  • 6. Mon WebSocket au Canada! WebSocket
  • 7. Mon WebSocket au Canada! WebSocket C’est quoi
  • 8. Mon WebSocket au Canada! WebSocket C’est quoi N’importe quoi!
  • 9. Mon WebSocket au Canada! WebSocket C’est quoi N’importe quoi! Atmospher e
  • 10. Mon WebSocket au Canada! WebSocket C’est quoi N’importe quoi! Atmospher e Concepts
  • 11. Mon WebSocket au Canada! WebSocket C’est quoi N’importe quoi! Atmospher e Concepts Démo
  • 12. WebSockets Le protocole WebSocket vise à développer un canal de communication bidirectionnel et « full-duplex » sur un socket TCP pour les fureteurs et les serveurs web.
  • 13. Avant (Long-Polling) Requête Fureteu Server r
  • 14. Avant (Long-Polling) Requête Fureteu Server r
  • 15. Avant (Long-Polling) Requête Fureteu Server r Réponse
  • 16. Oups!! Requête Fureteu Rien Server r
  • 17. Oups! Requête Fureteu Server r Zzzz
  • 18. Mieux! Requête Fureteu Server r Cache
  • 19. Mieux! Requête Fureteu Server r Cache
  • 20. A la limite (HTTP Streaming) Requête Fureteu Server r
  • 21. A la limite (HTTP Streaming) Requête Fureteu Server r
  • 22. A la limite (HTTP Streaming) Requête Fureteu Server r Réponse
  • 23. A la limite (HTTP Streaming) Requête Fureteu Server r Réponse Réponse
  • 24. Oups!! Requête Fureteu Server r L’enfe Réponse r Réponse
  • 25. A la limite (HTTP Streaming) Requête Fureteu Server r L’enfe Hack Réponse r Réponse
  • 26. Oups!!! Requête Fureteu Server r Réponse Proxy Réponse
  • 27. Mieux Requête Fureteu Server r Réponse Cache Réponse
  • 28. Mieux Requête Fureteu Server r Réponse Cache «Réponse HeartBeat »
  • 29. Mieux: Server Side Events (SSE) Requête Fureteu Server r Réponse Réponse
  • 30. Oups!!! Requête Fureteu Server r Réponse Proxy Réponse
  • 31. Mieux Requête Fureteu Server r Réponse Cache «Réponse HeartBeat »
  • 32. WebSockets Hanshake Fureteu Server r
  • 33. WebSockets Hanshake Fureteu Server r OK
  • 34. WebSockets Requête Fureteu Server r
  • 35. WebSockets Requête Fureteu Server r
  • 36. WebSockets Fureteu Server r Réponse
  • 37. WebSockets Requête Fureteu Server r
  • 38. WebSockets Requête Requête Fureteu Server r
  • 39. WebSockets Requête Requête Fureteu Server r
  • 40. WebSockets Fureteu Server r Réponse Réponse
  • 41. A TOUS moment Fureteu Server r Réponse
  • 42. Ah la belle vie, la vie, la vie ahah! Fureteu Server r Réponse
  • 43. Oups!! Fureteu Server r Réponse Proxy
  • 44. Mieux! Fureteu Server r Réponse Cache
  • 45. Première requête T 127.0.0.1:65062 -> 127.0.0.1:8080 [AP] GET / HTTP/1.1. Upgrade: websocket. Connection: Upgrade. Host: 127.0.0.1:8080. Origin: http://127.0.0.1:8080. Sec-WebSocket-Key: Tz9qdt3lmte6Slf+GvpRqQ==. Sec-WebSocket-Version: 13. Sec-WebSocket-Extensions: x-webkit-deflate- frame.
  • 46. Réponse T 127.0.0.1:8080 -> 127.0.0.1:51292 [AP] HTTP/1.1 101 Switching Protocols. Upgrade: WebSocket. Connection: Upgrade. Sec-WebSocket-Accept: HVXA7SqH5uYeN6aD9tZ0JQbfTJA=.
  • 47. Ah la belle vie, la vie, la vie, ahah T 127.0.0.1:8080 -> 127.0.0.1:51292 [AP] HTTP/1.1 101 Switching Protocols. Upgrade: WebSocket. Connection: Upgrade. Sec-WebSocket-Accept: HVXA7SqH5uYeN6aD9tZ0JQbfTJA=.
  • 48. OUPS!!! T 127.0.0.1:8080 -> 127.0.0.1:65064 [AP] HTTP/1.1 501 Not Implemented. Server: Apache-Coyote/1.1. X-Atmosphere-error: Websocket protocol not supported. Transfer-Encoding: chunked. Date: Fri, 15 Jun 2012 10:06:30 GMT. Connection: close. .
  • 49. WebSocket API – Standard JavaScript websocket = new WebSocket(wsUri); websocket.onopen = function(evt) { …}; websocket.onclose = function(evt) { …}; websocket.onmessage = function(evt) { …}; websocket.onerror = function(evt) { …}; webSocket.send(…)
  • 50. WebSocket API – Java Jetty 7, GlassFish 3.1, Netty 3, Tomcat 7.0.27, Resin 4, JBoss Plugin JSR 356: http://jcp.org/en/jsr/detail?id=356 AHC (Client -> De facto) http://github.com/sonatype/async-http- client
  • 51. Ah la belle vie, la vie, la vie, ahah
  • 53. C’est parti! Safari Tomcat 7 Firefox Jetty7 Jetty8 Chrome GlassFis Opera h3. GlassFis IE h 312
  • 54. N’importe quoi Safari Tomcat 7 Firefox Jetty7 Jetty8 Chrome GlassFis Opera h3. GlassFis IE h 312
  • 55. N’importe quoi Safari Tomcat 7 Firefox Jetty7 Au Jetty8 Chrome Secours GlassFis Opera !! h3. GlassFis IE h 312
  • 56. N’importe quoi Safari Tomcat 7 Streamin Jetty7 Firefox g Au Jetty8 Chrome Secours GlassFis Opera !! h3. GlassFis IE h 312
  • 57. N’importe quoi Safari Tomcat 7 Streamin Jetty7 Firefox g Au SSE Jetty8 Chrome Secours GlassFis Opera !! h3. GlassFis IE h 312
  • 58. N’importe quoi Safari Tomcat 7 Streamin Jetty7 Firefox g Au SSE Jetty8 Chrome Secours GlassFis Opera !! JSONP h3. GlassFis IE h 312
  • 59. N’importe quoi Safari Tomcat 7 Streamin Jetty7 Firefox g Au SSE Jetty8 Chrome Secours GlassFis Opera !! JSONP h3. Long GlassFis IE Polling h 312
  • 60. Safari Tomcat 7 Firefox Jetty7 Atmosphere à Chrome la Jetty8 rescousse!!! GlassFis Opera h3. GlassFis IE h 312
  • 61. Atmosphere -WebSockets Safari Tomcat 7 Jetty7 Atmosphere API Firefox atmosphere.js Jetty8 Chrome GlassFis Opera h3. GlassFis IE h 312
  • 62. Atmosphere - HTML5 Server Side Events Safari Tomcat 7 Jetty7 Atmosphere API Firefox atmosphere.js Servlet Chrome 3 WebLogi Opera c GlassFis IE h 312
  • 63. Atmosphere Long-Polling/HTTP Streaming Safari JBoss Jetty7 Atmosphere API Firefox atmosphere.js Servlet Chrome 3 WebLogi Opera c. GlassFis IE h
  • 64. Atmosphere Safari JBoss Jetty7 Atmosphere API Firefox atmosphere.js Même API, Chrome peut importe Servlet 3 le transport!! WebLogi Opera c. GlassFis IE h
  • 65. Socket.IO, GWT, Wicket, JSF, etc. Safari JBoss Jetty7 Atmosphere API Firefox Socket.IO Servlet Chrome 3 WebLogi Opera c. GlassFis IE h
  • 66. PORTABLE!!!!! Safari JBoss Jetty7 Atmosphere API Firefox Socket.IO PORTABLE Servlet Chrome 3 WebLogi Opera c. GlassFis IE h
  • 67. Grosse Erreur!!!!! • Toutframework ne supportant que les WebSockets Mise en production IMPOSSIBLE
  • 69. Définition • Suspend: décrocher la ligne • Resume: racrocher la ligne • Broadcast: parler sur une ou plusieurs lignes, seul, à deux ou plusieurs.
  • 70. Requête Normale Fureteu r Fureteu Server r Fureteu r
  • 71. Requête Normale Fureteu r Fureteu Server r Fureteu r
  • 72. Suspend Fureteu r Fureteu Server r Fureteu r
  • 73. Suspend Fureteu r S Fureteu Server r Fureteu r
  • 74. Suspend Fureteu r S Fureteu Server r Fureteu r
  • 75. Suspend Fureteu r S Fureteu Server r Fureteu r
  • 76. Broadcast Fureteu r B S Fureteu Server r Fureteu r
  • 77. Broadcast Fureteu r B S Fureteu Server r Fureteu r
  • 78. Resume Fureteu r B Fureteu Server r R Fureteu r
  • 79. Resume Fureteu r B Fureteu Server S r Fureteu r
  • 80. Broadcaster • Default: in-memory • Nuage • RedisBroadcaster • JMSBroadcaster • XMPPBroadcaster • HazelcastBroadcaster • JGroupsBroascaster • Multi-Threads, Async I/O par default
  • 81. Broadcaster Nuage Fureteu r S Server Fureteu r Fureteu S Server r
  • 82. Broadcaster Nuage Fureteu r S Server Fureteu r Fureteu S Server r
  • 83. Broadcaster Nuage Fureteu B r S Server Fureteu r Fureteu S Server r
  • 84. Broadcaster Nuage Fureteu B r Server Fureteu r Fureteu r Server
  • 85. Broadcaster Nuage Fureteu r Server Fureteu r B Fureteu r Server
  • 86. Broadcaster Nuage Fureteu r Server Fureteu r Fureteu r Server
  • 87. Composantes Atmosphere • WebSocketHandler • Seulement WebSocket (ATTENTION)! • AtmosphereHandler • Tout les protocoles • Jersey Resource • Tout les protocoles • Meteor • Tout les protocoles
  • 88. WebSocket Sub Protocol • WebSocketProtocol Definir sont propre WebSocket protocol. • Atmosphere,par default, utilise le SimpleHttpProtocol Message WebSocket transformé en HTTP POST, avec read/write asynchrone. • SwaggerSocket:REST over WebSockets -> Protocol plus puissant
  • 90. Hello, Swagger • Swagger is… • Spec for declaring an API schema • A framework for auto-generating the spec • A library for client library generation • A JSON-based test framework
  • 91. What is this Resource Declaration? • Listing of all available APIs http://petstore.swagger.wordnik.com/api/resources.json “It’s like a sitemap for your API!”
  • 92. Démo
  • 93. But What about Speed? • Yes! REST over HTTP is slow • Connection overhead • Your Marshaling & Unmarshaling overhead prod • Chatter Database • JSON/XML need to diet isn't doing • It's also… REST • Synchronous • GET/POST/PUT/DELETE don't cut it
  • 94. SwaggerSocket • REST over WebSocket • Protocole basé sur JSON • Performance améliorée • Simple • Supporte également sur HTTP. • Supporte le multi requètes/réponses.
  • 95. Powered By Wordnik twitter.com/wordnik twitter.com/atmo_framework twitter.com/swaggersocket http://github.com/Atmosphere/atmosphere http://github.com/wordnik/swaggersocket