Writing highly scalable WebSocket using the Atmosphere Framework Jeanfrancois Arcand Wordnik.com
Well Funded Silicon Valley based Startup Creators of Meaning Discovery Engine Wordnik extracts Meaning from Text Lexicographic and Computational Linguistic algorithms Data & Algorithms exposed via Swagger API Self-updating English Language Dictionary Based on in-context usage Proprietary Text Corpus Word Graph relates all words in English Micro Service Architecture Infrastructure Java/Scala/MongoDB Who is Wordnik
Who I am Twitter: @jfarcand Creator of Grizzly Framework
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Twitter: @jfarcand
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of the AsyncHttpClient Twitter: @jfarcand
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpClient Twitter: @jfarcand
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpClient Twitter: @jfarcand Tomcat,  Apache Digester, Sitebricks, Jersey, Aether/Maven, etc.
The Atmosphere Framework A Portable Comet Framework
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin  Support available WebSocket Native API
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin  Support available WebSocket Native API Plugs in for Redis, Active MQ (JMS), JGroups, XMPP, etc.
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin  Support available WebSocket Native API Plugs in for Redis, Active MQ (JMS), JGroups, XMPP, etc.  Supported/Integrated by almost all major frameworks and javascript library
The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side
The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10)
The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10) Atmosphere JQuery Plug In hide that and propose a uniform API
The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10) Atmosphere JQuery Plug In hide that and propose a uniform API Decide the best transport, negociate it with the server
Java Landscape Jetty 7.0: First to Support WebSocket
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz WOUAAAAAAAAAAAAAAA Atmosphere to the rescue!!
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz WOUAAAAAAAAAAAAAAA Atmosphere to the rescue!! Are you crazy enough to rewrite your entire app?
Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz WOUAAAAAAAAAAAAAAA Atmosphere to the rescue!! Are you  crazy  enough to rewrite your entire app? Really want to use  proprietary  solution like ?
How? Integrate with  all  framework? Check!
How? Integrate with  all  framework? Check! Want Servlet API? Check!
How? Integrate with  all  framework? Check! Want Servlet API? Check! Want REST like API? Check!
How? Integrate with  all  framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check!
How? Integrate with  all  framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check!
How? Integrate with  all  framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check! WebSocket Sub Protocol? Check
How? Integrate with  all  framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check! WebSocket Sub Protocol? Check Atmosphere provides a uniform API and hides the underlying transport details (async I/O included)
Concepts Upgrade/Suspend
Concepts Upgrade/Suspend Broadcast
Concepts Upgrade/Suspend Broadcast Resume
Concepts Upgrade/Suspend Broadcast Resume Client choose the best technique  (ws or comet) Async I/O (Input/Output Stream)
Concepts Upgrade/Suspend Broadcast Resume Cloud enabled (zzzzzz) Async I/O (Input/Output Stream) Survive Proxy Cloud Enabled
Zzzzzzzzz Enough Bla Bla Bla, let ’s do Scala!
API Atmosphere Handler
API Jersey to the rescue! (@ and Prog API) Atmosphere Handler
API Atmosphere Handler WebSocket Protocol Jersey to the rescue! (@ and Prog API)
API Atmosphere Handler WebSocket Protocol Servlet API Jersey to the rescue! (@ and Prog API)
The Demo Jetty 8 Tomcat 6 Redis Chrome Redis CLI Safari WebSocket WebSocket FAIL -> Streaming Broadcaster Broadcaster
def onRequest(r: AtmosphereResource[HttpServletRequest, HttpServletResponse]): Unit = { var req: HttpServletRequest = r.getRequest var res: HttpServletResponse = r.getResponse var method: String = req.getMethod if (" GET ".equalsIgnoreCase(method)) { var b: Broadcaster = lookupBroadcaster(req.getPathInfo) r.setBroadcaster(b) if (req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT).equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT)) { req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, true) r.suspend(-1, false) }  else { r.suspend(-1) } } else if (" POST ".equalsIgnoreCase(method)) { var b: Broadcaster = lookupBroadcaster(req.getPathInfo) var message: String = req.getReader.readLine if (message != null && message.indexOf("message") != -1) { b.broadcast(message.substring("message=".length)) } } } 2005- AtmosphereHandler http://is.gd/hH3AaH
override def  doGet (req: HttpServletRequest, res: HttpServletResponse): Unit = { var m:  org.atmosphere.cpr.Meteor = org.atmosphere.cpr.Meteor.build(req) m.addListener(new Console) res.setContentType("text/html;charset=ISO-8859-1") var b: Broadcaster = lookupBroadcaster(req.getPathInfo) m.setBroadcaster(b) if (req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT).equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT)) { req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, true) m.suspend(-1, false) } else { m.suspend(-1) } } override def  doPost (req: HttpServletRequest, res: HttpServletResponse): Unit = { var b: Broadcaster = lookupBroadcaster(req.getPathInfo) var message: String = req.getReader.readLine if (message != null && message.indexOf("message") != -1) { b.broadcast(message.substring("message=".length)) } } 1999 – Servlet API http://is.gd/GcnG0A
@Path("/resource/{topic}") @Produces(Array("text/html;charset=ISO-8859-1")) class Resource { @ PathParam ("topic") private var topic: Broadcaster = null @ GET def subscribe: SuspendResponse[String] = { return new  SuspendResponse.SuspendResponseBuilder[String]() .broadcaster(topic) .outputComments(true) .addListener(new Console) .build } @ POST @Broadcast def publish(@FormParam("message") message: String): Broadcastable = { return new Broadcastable(message, "", topic) } 2007 – REST API http://is.gd/Df9Uvm
2011 – WebSocket API http://is.gd/SEa4AK
2011 – Client API http://is.gd/9jumKt
SwaggerSocket Protocol HTTP/REST Over WebSocket
SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol
SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol Support Pipelined Requests
SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol Support Pipelined Requests Fully ASYNCHRONOUS
SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol Support Pipelined Request Fully ASYNCHRONOUS Work with ANY existing technology, without any changes No need to use Atmosphere API directly Protocol easily extensible
SwaggerSocket Protocol WebServer Atmosphere WebSocket WebSocket Protocol Jersey REST Resource
Comparing HTTP/keep-alive vs WebSocket Benchmark
Writing WebSocket doesn ’t have to be complex Use technology/API that you know, don’t re-invent the wheel again! Twitter: @atmo_framework Github:  http://github.com/Atmosphere/atmosphere Wordnik:  http://wordnik.com Conclusion

Writing highly scalable WebSocket using the Atmosphere Framework and Scala

  • 1.
    Writing highly scalableWebSocket using the Atmosphere Framework Jeanfrancois Arcand Wordnik.com
  • 2.
    Well Funded SiliconValley based Startup Creators of Meaning Discovery Engine Wordnik extracts Meaning from Text Lexicographic and Computational Linguistic algorithms Data & Algorithms exposed via Swagger API Self-updating English Language Dictionary Based on in-context usage Proprietary Text Corpus Word Graph relates all words in English Micro Service Architecture Infrastructure Java/Scala/MongoDB Who is Wordnik
  • 3.
    Who I amTwitter: @jfarcand Creator of Grizzly Framework
  • 4.
    Who I amCreator of Grizzly Framework Significant contributor of GlassFish Twitter: @jfarcand
  • 5.
    Who I amCreator of Grizzly Framework Significant contributor of GlassFish Creator of the AsyncHttpClient Twitter: @jfarcand
  • 6.
    Who I amCreator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpClient Twitter: @jfarcand
  • 7.
    Who I amCreator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpClient Twitter: @jfarcand Tomcat, Apache Digester, Sitebricks, Jersey, Aether/Maven, etc.
  • 8.
    The Atmosphere FrameworkA Portable Comet Framework
  • 9.
    The Atmosphere FrameworkA Portable Comet Framework Support All native Comet API and Servlet 3.0
  • 10.
    The Atmosphere FrameworkA Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin
  • 11.
    The Atmosphere FrameworkA Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin Support available WebSocket Native API
  • 12.
    The Atmosphere FrameworkA Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin Support available WebSocket Native API Plugs in for Redis, Active MQ (JMS), JGroups, XMPP, etc.
  • 13.
    The Atmosphere FrameworkA Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin Support available WebSocket Native API Plugs in for Redis, Active MQ (JMS), JGroups, XMPP, etc. Supported/Integrated by almost all major frameworks and javascript library
  • 14.
    The Atmosphere FrameworkWebSocket Spec is evolving fast on both Browser and Server Side
  • 15.
    The Atmosphere FrameworkWebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10)
  • 16.
    The Atmosphere FrameworkWebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10) Atmosphere JQuery Plug In hide that and propose a uniform API
  • 17.
    The Atmosphere FrameworkWebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10) Atmosphere JQuery Plug In hide that and propose a uniform API Decide the best transport, negociate it with the server
  • 18.
    Java Landscape Jetty7.0: First to Support WebSocket
  • 19.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility
  • 20.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change
  • 21.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support
  • 22.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes
  • 23.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz
  • 24.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz WOUAAAAAAAAAAAAAAA Atmosphere to the rescue!!
  • 25.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz WOUAAAAAAAAAAAAAAA Atmosphere to the rescue!! Are you crazy enough to rewrite your entire app?
  • 26.
    Java Landscape Jetty7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility Jetty 7.4.5 and 8.0.2 and up: Spec change GlassFish 3.0 -> some support GlassFish 3.1.2 -> API Changes Tomcat 7 zzzzzzzzzzzz WOUAAAAAAAAAAAAAAA Atmosphere to the rescue!! Are you crazy enough to rewrite your entire app? Really want to use proprietary solution like ?
  • 27.
    How? Integrate with all framework? Check!
  • 28.
    How? Integrate with all framework? Check! Want Servlet API? Check!
  • 29.
    How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check!
  • 30.
    How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check!
  • 31.
    How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check!
  • 32.
    How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check! WebSocket Sub Protocol? Check
  • 33.
    How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check! WebSocket Sub Protocol? Check Atmosphere provides a uniform API and hides the underlying transport details (async I/O included)
  • 34.
  • 35.
  • 36.
  • 37.
    Concepts Upgrade/Suspend BroadcastResume Client choose the best technique (ws or comet) Async I/O (Input/Output Stream)
  • 38.
    Concepts Upgrade/Suspend BroadcastResume Cloud enabled (zzzzzz) Async I/O (Input/Output Stream) Survive Proxy Cloud Enabled
  • 39.
    Zzzzzzzzz Enough BlaBla Bla, let ’s do Scala!
  • 40.
  • 41.
    API Jersey tothe rescue! (@ and Prog API) Atmosphere Handler
  • 42.
    API Atmosphere HandlerWebSocket Protocol Jersey to the rescue! (@ and Prog API)
  • 43.
    API Atmosphere HandlerWebSocket Protocol Servlet API Jersey to the rescue! (@ and Prog API)
  • 44.
    The Demo Jetty8 Tomcat 6 Redis Chrome Redis CLI Safari WebSocket WebSocket FAIL -> Streaming Broadcaster Broadcaster
  • 45.
    def onRequest(r: AtmosphereResource[HttpServletRequest,HttpServletResponse]): Unit = { var req: HttpServletRequest = r.getRequest var res: HttpServletResponse = r.getResponse var method: String = req.getMethod if (" GET ".equalsIgnoreCase(method)) { var b: Broadcaster = lookupBroadcaster(req.getPathInfo) r.setBroadcaster(b) if (req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT).equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT)) { req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, true) r.suspend(-1, false) } else { r.suspend(-1) } } else if (" POST ".equalsIgnoreCase(method)) { var b: Broadcaster = lookupBroadcaster(req.getPathInfo) var message: String = req.getReader.readLine if (message != null && message.indexOf("message") != -1) { b.broadcast(message.substring("message=".length)) } } } 2005- AtmosphereHandler http://is.gd/hH3AaH
  • 46.
    override def doGet (req: HttpServletRequest, res: HttpServletResponse): Unit = { var m: org.atmosphere.cpr.Meteor = org.atmosphere.cpr.Meteor.build(req) m.addListener(new Console) res.setContentType("text/html;charset=ISO-8859-1") var b: Broadcaster = lookupBroadcaster(req.getPathInfo) m.setBroadcaster(b) if (req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT).equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT)) { req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, true) m.suspend(-1, false) } else { m.suspend(-1) } } override def doPost (req: HttpServletRequest, res: HttpServletResponse): Unit = { var b: Broadcaster = lookupBroadcaster(req.getPathInfo) var message: String = req.getReader.readLine if (message != null && message.indexOf("message") != -1) { b.broadcast(message.substring("message=".length)) } } 1999 – Servlet API http://is.gd/GcnG0A
  • 47.
    @Path("/resource/{topic}") @Produces(Array("text/html;charset=ISO-8859-1")) classResource { @ PathParam ("topic") private var topic: Broadcaster = null @ GET def subscribe: SuspendResponse[String] = { return new SuspendResponse.SuspendResponseBuilder[String]() .broadcaster(topic) .outputComments(true) .addListener(new Console) .build } @ POST @Broadcast def publish(@FormParam("message") message: String): Broadcastable = { return new Broadcastable(message, "", topic) } 2007 – REST API http://is.gd/Df9Uvm
  • 48.
    2011 – WebSocketAPI http://is.gd/SEa4AK
  • 49.
    2011 – ClientAPI http://is.gd/9jumKt
  • 50.
  • 51.
    SwaggerSocket Protocol HTTP/RESTOver WebSocket JSON based protocol
  • 52.
    SwaggerSocket Protocol HTTP/RESTOver WebSocket JSON based protocol Support Pipelined Requests
  • 53.
    SwaggerSocket Protocol HTTP/RESTOver WebSocket JSON based protocol Support Pipelined Requests Fully ASYNCHRONOUS
  • 54.
    SwaggerSocket Protocol HTTP/RESTOver WebSocket JSON based protocol Support Pipelined Request Fully ASYNCHRONOUS Work with ANY existing technology, without any changes No need to use Atmosphere API directly Protocol easily extensible
  • 55.
    SwaggerSocket Protocol WebServerAtmosphere WebSocket WebSocket Protocol Jersey REST Resource
  • 56.
    Comparing HTTP/keep-alive vsWebSocket Benchmark
  • 57.
    Writing WebSocket doesn’t have to be complex Use technology/API that you know, don’t re-invent the wheel again! Twitter: @atmo_framework Github: http://github.com/Atmosphere/atmosphere Wordnik: http://wordnik.com Conclusion