Writing highly scalable WebSocket using the Atmosphere Framework <ul><li>Jeanfrancois Arcand </li></ul><ul><li>Wordnik.com...
<ul><li>Well Funded Silicon Valley based Startup </li></ul><ul><ul><li>Creators of Meaning Discovery Engine </li></ul></ul...
Who I am <ul><li>Twitter: @jfarcand </li></ul>Creator of Grizzly Framework
Who I am Creator of Grizzly Framework Significant contributor of GlassFish <ul><li>Twitter: @jfarcand </li></ul>
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of the AsyncHttpClient <ul><li>Twitter:...
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpC...
Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpC...
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 ...
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery ...
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery ...
The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery ...
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...
The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF...
The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF...
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...
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...
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...
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...
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...
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...
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...
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! ...
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! ...
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
<ul><li>def onRequest(r: AtmosphereResource[HttpServletRequest, HttpServletResponse]): Unit = { </li></ul><ul><li>var req:...
<ul><li>override def  doGet (req: HttpServletRequest, res: HttpServletResponse): Unit = { </li></ul><ul><li>var m:  org.at...
<ul><li>@Path(&quot;/resource/{topic}&quot;) </li></ul><ul><li>@Produces(Array(&quot;text/html;charset=ISO-8859-1&quot;)) ...
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 <ul><li>W...
SwaggerSocket Protocol WebServer Atmosphere WebSocket WebSocket Protocol Jersey REST Resource
<ul><li>Comparing HTTP/keep-alive vs WebSocket </li></ul>Benchmark
<ul><li>Writing WebSocket doesn ’t have to be complex </li></ul><ul><li>Use technology/API that you know, don’t re-invent ...
Upcoming SlideShare
Loading in...5
×

Writing highly scalable WebSocket using the Atmosphere Framework and Scala

11,643

Published on

Devoxx 2011 Atmosphere Framework talk on WebSocket, Redis and Scala

Published in: Technology, Education
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,643
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
167
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Writing highly scalable WebSocket using the Atmosphere Framework and Scala

  1. 1. Writing highly scalable WebSocket using the Atmosphere Framework <ul><li>Jeanfrancois Arcand </li></ul><ul><li>Wordnik.com </li></ul>
  2. 2. <ul><li>Well Funded Silicon Valley based Startup </li></ul><ul><ul><li>Creators of Meaning Discovery Engine </li></ul></ul><ul><li>Wordnik extracts Meaning from Text </li></ul><ul><ul><li>Lexicographic and Computational Linguistic algorithms </li></ul></ul><ul><ul><li>Data & Algorithms exposed via Swagger API </li></ul></ul><ul><li>Self-updating English Language Dictionary </li></ul><ul><ul><li>Based on in-context usage </li></ul></ul><ul><ul><li>Proprietary Text Corpus </li></ul></ul><ul><ul><ul><li>Word Graph relates all words in English </li></ul></ul></ul><ul><li>Micro Service Architecture Infrastructure </li></ul><ul><ul><li>Java/Scala/MongoDB </li></ul></ul>Who is Wordnik
  3. 3. Who I am <ul><li>Twitter: @jfarcand </li></ul>Creator of Grizzly Framework
  4. 4. Who I am Creator of Grizzly Framework Significant contributor of GlassFish <ul><li>Twitter: @jfarcand </li></ul>
  5. 5. Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of the AsyncHttpClient <ul><li>Twitter: @jfarcand </li></ul>
  6. 6. Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpClient <ul><li>Twitter: @jfarcand </li></ul>
  7. 7. Who I am Creator of Grizzly Framework Significant contributor of GlassFish Creator of Atmosphere Creator of the AsyncHttpClient <ul><li>Twitter: @jfarcand </li></ul>Tomcat, Apache Digester, Sitebricks, Jersey, Aether/Maven, etc.
  8. 8. The Atmosphere Framework A Portable Comet Framework
  9. 9. The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0
  10. 10. The Atmosphere Framework A Portable Comet Framework Support All native Comet API and Servlet 3.0 Atmosphere Client JQuery Plugin
  11. 11. 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
  12. 12. 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.
  13. 13. 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
  14. 14. The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side
  15. 15. The Atmosphere Framework WebSocket Spec is evolving fast on both Browser and Server Side Chrome/Safari/Opera: WebSocket FF: MozWebSocket IE: (crikets … ~10)
  16. 16. 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
  17. 17. 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
  18. 18. Java Landscape Jetty 7.0: First to Support WebSocket
  19. 19. Java Landscape Jetty 7.0: First to Support WebSocket Jetty 7.2.x -> API Changes, break compatibility
  20. 20. 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
  21. 21. 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
  22. 22. 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
  23. 23. 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
  24. 24. 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!!
  25. 25. 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?
  26. 26. 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 ?
  27. 27. How? Integrate with all framework? Check!
  28. 28. How? Integrate with all framework? Check! Want Servlet API? Check!
  29. 29. How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check!
  30. 30. How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check!
  31. 31. How? Integrate with all framework? Check! Want Servlet API? Check! Want REST like API? Check! Fallback to Comet? Check! Pure WebSocket? Check!
  32. 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. 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. 34. Concepts Upgrade/Suspend
  35. 35. Concepts Upgrade/Suspend Broadcast
  36. 36. Concepts Upgrade/Suspend Broadcast Resume
  37. 37. Concepts Upgrade/Suspend Broadcast Resume Client choose the best technique (ws or comet) Async I/O (Input/Output Stream)
  38. 38. Concepts Upgrade/Suspend Broadcast Resume Cloud enabled (zzzzzz) Async I/O (Input/Output Stream) Survive Proxy Cloud Enabled
  39. 39. Zzzzzzzzz Enough Bla Bla Bla, let ’s do Scala!
  40. 40. API Atmosphere Handler
  41. 41. API Jersey to the rescue! (@ and Prog API) Atmosphere Handler
  42. 42. API Atmosphere Handler WebSocket Protocol Jersey to the rescue! (@ and Prog API)
  43. 43. API Atmosphere Handler WebSocket Protocol Servlet API Jersey to the rescue! (@ and Prog API)
  44. 44. The Demo Jetty 8 Tomcat 6 Redis Chrome Redis CLI Safari WebSocket WebSocket FAIL -> Streaming Broadcaster Broadcaster
  45. 45. <ul><li>def onRequest(r: AtmosphereResource[HttpServletRequest, HttpServletResponse]): Unit = { </li></ul><ul><li>var req: HttpServletRequest = r.getRequest </li></ul><ul><li>var res: HttpServletResponse = r.getResponse </li></ul><ul><li>var method: String = req.getMethod </li></ul><ul><li>if (&quot; GET &quot;.equalsIgnoreCase(method)) { </li></ul><ul><li>var b: Broadcaster = lookupBroadcaster(req.getPathInfo) </li></ul><ul><li>r.setBroadcaster(b) </li></ul><ul><li>if (req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT).equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT)) { </li></ul><ul><li>req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, true) </li></ul><ul><li>r.suspend(-1, false) </li></ul><ul><li>} else { </li></ul><ul><li>r.suspend(-1) </li></ul><ul><li>} </li></ul><ul><li>} else if (&quot; POST &quot;.equalsIgnoreCase(method)) { </li></ul><ul><li>var b: Broadcaster = lookupBroadcaster(req.getPathInfo) </li></ul><ul><li>var message: String = req.getReader.readLine </li></ul><ul><li>if (message != null && message.indexOf(&quot;message&quot;) != -1) { </li></ul><ul><li>b.broadcast(message.substring(&quot;message=&quot;.length)) </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>2005- AtmosphereHandler http://is.gd/hH3AaH
  46. 46. <ul><li>override def doGet (req: HttpServletRequest, res: HttpServletResponse): Unit = { </li></ul><ul><li>var m: org.atmosphere.cpr.Meteor = org.atmosphere.cpr.Meteor.build(req) </li></ul><ul><li>m.addListener(new Console) </li></ul><ul><li>res.setContentType(&quot;text/html;charset=ISO-8859-1&quot;) </li></ul><ul><li>var b: Broadcaster = lookupBroadcaster(req.getPathInfo) </li></ul><ul><li>m.setBroadcaster(b) </li></ul><ul><li>if (req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT).equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT)) { </li></ul><ul><li>req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, true) </li></ul><ul><li>m.suspend(-1, false) </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li>m.suspend(-1) </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>override def doPost (req: HttpServletRequest, res: HttpServletResponse): Unit = { </li></ul><ul><li>var b: Broadcaster = lookupBroadcaster(req.getPathInfo) </li></ul><ul><li>var message: String = req.getReader.readLine </li></ul><ul><li>if (message != null && message.indexOf(&quot;message&quot;) != -1) { </li></ul><ul><li>b.broadcast(message.substring(&quot;message=&quot;.length)) </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>1999 – Servlet API http://is.gd/GcnG0A
  47. 47. <ul><li>@Path(&quot;/resource/{topic}&quot;) </li></ul><ul><li>@Produces(Array(&quot;text/html;charset=ISO-8859-1&quot;)) </li></ul><ul><li>class Resource { </li></ul><ul><li>@ PathParam (&quot;topic&quot;) private var topic: Broadcaster = null </li></ul><ul><li>@ GET </li></ul><ul><li>def subscribe: SuspendResponse[String] = { </li></ul><ul><li>return new SuspendResponse.SuspendResponseBuilder[String]() </li></ul><ul><li>.broadcaster(topic) </li></ul><ul><li>.outputComments(true) </li></ul><ul><li>.addListener(new Console) </li></ul><ul><li>.build </li></ul><ul><li>} </li></ul><ul><li>@ POST </li></ul><ul><li>@Broadcast </li></ul><ul><li>def publish(@FormParam(&quot;message&quot;) message: String): Broadcastable = { </li></ul><ul><li>return new Broadcastable(message, &quot;&quot;, topic) </li></ul><ul><li>} </li></ul>2007 – REST API http://is.gd/Df9Uvm
  48. 48. 2011 – WebSocket API http://is.gd/SEa4AK
  49. 49. 2011 – Client API http://is.gd/9jumKt
  50. 50. SwaggerSocket Protocol HTTP/REST Over WebSocket
  51. 51. SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol
  52. 52. SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol Support Pipelined Requests
  53. 53. SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol Support Pipelined Requests Fully ASYNCHRONOUS
  54. 54. SwaggerSocket Protocol HTTP/REST Over WebSocket JSON based protocol Support Pipelined Request Fully ASYNCHRONOUS <ul><li>Work with ANY existing technology, without any changes </li></ul><ul><li>No need to use Atmosphere API directly </li></ul><ul><li>Protocol easily extensible </li></ul>
  55. 55. SwaggerSocket Protocol WebServer Atmosphere WebSocket WebSocket Protocol Jersey REST Resource
  56. 56. <ul><li>Comparing HTTP/keep-alive vs WebSocket </li></ul>Benchmark
  57. 57. <ul><li>Writing WebSocket doesn ’t have to be complex </li></ul><ul><li>Use technology/API that you know, don’t re-invent the wheel again! </li></ul><ul><li>Twitter: @atmo_framework </li></ul><ul><li>Github: http://github.com/Atmosphere/atmosphere </li></ul><ul><li>Wordnik: http://wordnik.com </li></ul>Conclusion
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×