WebObjects + ScalaBuilding Concurrent WebObjects applications with Scala                     Ravi Mendis
Why Concurrent Programming?
2005The year of Dual Core
2010Today
Entry-Level                    Cores   ThreadsAMD Opteron            4       4IBM Power7             4      16 Intel Xeon ...
High-End                   Cores   ThreadsAMD Opteron          12      12IBM Power7           8       32 Intel Xeon       ...
2011Tomorrow
Roadmap                  Cores   ThreadsAMD Opteron         16      16IBM Power7          ?       ?? Intel Xeon         8 ...
“By 2015 we will likely have over 100 cores on a many-   core processing chip in our notebook computers.”                 ...
Welcome to the world of Multi-cores!
Q: How do we take advantage of    multi-core processors?
A: Concurrent Programming
#1 Threads & Locks
“Concurrency is hard. It involves a lot of problems that are very difficult         to think about and reason about and und...
#1 Threads & Locks•   HARD to program•   HARD to scale•   Contentious
java.lang.IllegalArgumentException: Cannot determine primary key for entity ASCCarveout from row: {charge = 3027.00;claimI...
BBC2, Top Gear - Series 15, Episode 1 - June 27 ’10
#2 Actor Model  (A Share NOTHING Model)
Slowmation
Demo
html5 <video><video poster="/slowmation/screenshots/0/2/4/425.jpg">!   <source type="video/ogg" src="/slowmation/videos/6/...
HTML5 Video Conversion                                Thumbnail (.jpg)                             Screenshot (.jpg)      ...
Slowmation Actor                           (Video Processor)•   actor ! THUMBNAIL•   actor ! GRAB•   actor ! CONVERT2H264•...
!
Actor Messaging•   Asynchronous    •   Non-blocking•   Immutable Messages    •   NO shared data
Scala
Scala•   Immutable/Mutable datatypes•   Anonymous Functions (~Closures)•   No Static variables and methods•   Extensible
Scalaval greeting: String = “Hello World”;
Scalaval greeting = “Hello World”;
Scalaval greeting = “Hello World”
Scalaval greeting = “Hello World”   // immutablevar response = new String()    // mutableresponse = “Hey!”
Java - Static Varspublic class _Talent extends EOGenericRecord {	    public static final String ENTITY_NAME	 = "Talent";}
Scala - Companion Objectobject Talent extends EOGenericRecord {	    val ENTITY_NAME = "Talent"}
Thread-Safe
Scala - Pattern Matchingcase a => {   ...}
Scala - Pattern Matchingtry {     var epi: EditPageInterface = D2W.factory.editPageForNewObjectWithEntityNamed(entityName,...
Scala - Case Classescase class PINGcase class PONG
Scala - Case Classesactor ! PINGactor ! PONG
Scala - Case Classescase PING => {   ...}case PONG => {   ...}
Scala - Anonymous Functionsx => x^2
Scala - Anonymous Functionsx, y => x + y
Scala - Anonymous Functionsx, y => {x + y}
Scala - Anonymous Functionscase (PING => {...})case (PONG => {...})
λ - Expressions
Scala Actors - Examplecase class THUMBNAIL(filepath: String)	    // Actor msg case classval processor = actor {	    loop {...
#2 Actor Model•   EASY to program•   Scalable•   NO Deadlocks!
Q: Why can Scala be used with WebObjects?
A: Scala compiles to Java Byte-code
WebObjects + Concurrency
Why?
Performance•   Exploit multi-core processors
Ajax•   More responsive UI
How?
PropertiesWOAllowsConcurrentRequestHandling=true
Java - Synchronize Static Variablesprivate static String greeting = “Hello”;     // privatepublic void setGreeting(String ...
Free!
WO - What is Shared?•   Application•   Session (concurrent WO)
Use ERXEC•   Project Wonder•   Automatic lock/unlock handling
Propertieser.extensions.ERXEC.safeLocking=true
Debugging
Demo
Properties-Dcom.sun.management.jmxremote=true-Dcom.sun.management.jmxremote.authenticate=false-Dcom.sun.management.jmxremo...
Bottlenecks
EOF - Bottleneck•   Shared Object-cache    •   Antithesis to Share Nothing        model    •   Uses single database connec...
#3 STM(Software Transactional Memory)
EOF + Scala•   DOESN’T work in Scala Actors!•
Solutions•   Use Raw SQL•   Alternative database access    •   Squeryl    •   ...
Squeryl
Demo
Squeryl•   POSOs•   Actor Compatible•   Concurrent
“Scala as a concurrent programming language is         powerful, safe and easy-to-use”
Benchmarks
The Test•   ERWOAdaptor (Mina)    •   WO Worker as Actor•   Apache bench    •   c = 5...65    •   n = 500
Results
Time per req. (mean)200 ms150 ms100 ms 50 ms  0 ms         5   10   15   20   25   30   35   40   45   50   55   60   65  ...
Requests per second800600400200  0      5   10   15   20    25   30   35   40   45   50   55   60   65WOAdaptor           ...
“Scala as a concurrent programming language is powerful,                  safe and easy-to-use”
The R&D Imperative       In life long love            The key             Is R&D   The ladder of invention  Has eternal sl...
Q&A
References•   What will YOU do with 100 cores?    http://www.computerworld.com.au/article/354261/•   WebObjects with Scala...
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
Upcoming SlideShare
Loading in...5
×

Building Concurrent WebObjects applications with Scala

1,005

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,005
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Building Concurrent WebObjects applications with Scala

  1. 1. WebObjects + ScalaBuilding Concurrent WebObjects applications with Scala Ravi Mendis
  2. 2. Why Concurrent Programming?
  3. 3. 2005The year of Dual Core
  4. 4. 2010Today
  5. 5. Entry-Level Cores ThreadsAMD Opteron 4 4IBM Power7 4 16 Intel Xeon 4 8
  6. 6. High-End Cores ThreadsAMD Opteron 12 12IBM Power7 8 32 Intel Xeon 6 12
  7. 7. 2011Tomorrow
  8. 8. Roadmap Cores ThreadsAMD Opteron 16 16IBM Power7 ? ?? Intel Xeon 8 16
  9. 9. “By 2015 we will likely have over 100 cores on a many- core processing chip in our notebook computers.” - Computerworld
  10. 10. Welcome to the world of Multi-cores!
  11. 11. Q: How do we take advantage of multi-core processors?
  12. 12. A: Concurrent Programming
  13. 13. #1 Threads & Locks
  14. 14. “Concurrency is hard. It involves a lot of problems that are very difficult to think about and reason about and understand” - Tim Bray co-inventor of XML
  15. 15. #1 Threads & Locks• HARD to program• HARD to scale• Contentious
  16. 16. java.lang.IllegalArgumentException: Cannot determine primary key for entity ASCCarveout from row: {charge = 3027.00;claimID = 321839138; }! at com.webobjects.eoaccess.EODatabaseChannel._fetchObject(EODatabaseChannel.java:348)! at com.webobjects.eoaccess.EODatabaseContext._objectsWithFetchSpecificationEditingContext(EODatabaseContext.java:3071)! at com.webobjects.eoaccess.EODatabaseContext.objectsWithFetchSpecification(EODatabaseContext.java:3195)! at com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsWithFetchSpecification(EOObjectStoreCoordinator.java:488)! at com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecification(EOEditingContext.java:4069) ...Deadlock!! at er.extensions.eof.ERXEC.objectsWithFetchSpecification(ERXEC.java:1211)! at com.webobjects.eoaccess.EODatabaseContext.objectsForSourceGlobalID(EODatabaseContext.java:4084)! at com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsForSourceGlobalID(EOObjectStoreCoordinator.java:634)! at com.webobjects.eocontrol.EOEditingContext.objectsForSourceGlobalID(EOEditingContext.java:3923)! at er.extensions.eof.ERXEC.objectsForSourceGlobalID(ERXEC.java:1169)! at com.webobjects.eoaccess.EODatabaseContext._fireArrayFault(EODatabaseContext.java:4245)! at com.webobjects.eoaccess.EOAccessArrayFaultHandler.completeInitializationOfObject(EOAccessArrayFaultHandler.java:77)! at com.webobjects.eocontrol._EOCheapCopyMutableArray.willRead(_EOCheapCopyMutableArray.java:37)! at com.webobjects.eocontrol._EOCheapCopyMutableArray.count(_EOCheapCopyMutableArray.java:86)! at com.mpv.evaluation.ClaimEvaluator.validateClaim(ClaimEvaluator.java:398)! ...
  17. 17. BBC2, Top Gear - Series 15, Episode 1 - June 27 ’10
  18. 18. #2 Actor Model (A Share NOTHING Model)
  19. 19. Slowmation
  20. 20. Demo
  21. 21. html5 <video><video poster="/slowmation/screenshots/0/2/4/425.jpg">! <source type="video/ogg" src="/slowmation/videos/6/d/8/423.ogg" />! <source type="video/mp4" src="/slowmation/videos/d/6/4/424.mp4" /></video>
  22. 22. HTML5 Video Conversion Thumbnail (.jpg) Screenshot (.jpg) Video (.mp4) Video (.ogg)
  23. 23. Slowmation Actor (Video Processor)• actor ! THUMBNAIL• actor ! GRAB• actor ! CONVERT2H264• actor ! CONVERT2OGG
  24. 24. !
  25. 25. Actor Messaging• Asynchronous • Non-blocking• Immutable Messages • NO shared data
  26. 26. Scala
  27. 27. Scala• Immutable/Mutable datatypes• Anonymous Functions (~Closures)• No Static variables and methods• Extensible
  28. 28. Scalaval greeting: String = “Hello World”;
  29. 29. Scalaval greeting = “Hello World”;
  30. 30. Scalaval greeting = “Hello World”
  31. 31. Scalaval greeting = “Hello World” // immutablevar response = new String() // mutableresponse = “Hey!”
  32. 32. Java - Static Varspublic class _Talent extends EOGenericRecord { public static final String ENTITY_NAME = "Talent";}
  33. 33. Scala - Companion Objectobject Talent extends EOGenericRecord { val ENTITY_NAME = "Talent"}
  34. 34. Thread-Safe
  35. 35. Scala - Pattern Matchingcase a => { ...}
  36. 36. Scala - Pattern Matchingtry { var epi: EditPageInterface = D2W.factory.editPageForNewObjectWithEntityNamed(entityName, session)} catch { case e: IllegalArgumentException => { var epf: ErrorPageInterface = D2W.factory.errorPage(session) epf.setMessage(e.toString) }}
  37. 37. Scala - Case Classescase class PINGcase class PONG
  38. 38. Scala - Case Classesactor ! PINGactor ! PONG
  39. 39. Scala - Case Classescase PING => { ...}case PONG => { ...}
  40. 40. Scala - Anonymous Functionsx => x^2
  41. 41. Scala - Anonymous Functionsx, y => x + y
  42. 42. Scala - Anonymous Functionsx, y => {x + y}
  43. 43. Scala - Anonymous Functionscase (PING => {...})case (PONG => {...})
  44. 44. λ - Expressions
  45. 45. Scala Actors - Examplecase class THUMBNAIL(filepath: String) // Actor msg case classval processor = actor { loop { react() { case THUMBNAIL(filepath: String) => { ... } } }}// asynchronousprocessor ! THUMBNAIL(“/Library/WebServer/Documents/slowmation/screenshots/0/2/4/422.jpg”)
  46. 46. #2 Actor Model• EASY to program• Scalable• NO Deadlocks!
  47. 47. Q: Why can Scala be used with WebObjects?
  48. 48. A: Scala compiles to Java Byte-code
  49. 49. WebObjects + Concurrency
  50. 50. Why?
  51. 51. Performance• Exploit multi-core processors
  52. 52. Ajax• More responsive UI
  53. 53. How?
  54. 54. PropertiesWOAllowsConcurrentRequestHandling=true
  55. 55. Java - Synchronize Static Variablesprivate static String greeting = “Hello”; // privatepublic void setGreeting(String aGreeting) { synchronized(greeting) { // synchronized block greeting = aGreeting; }}
  56. 56. Free!
  57. 57. WO - What is Shared?• Application• Session (concurrent WO)
  58. 58. Use ERXEC• Project Wonder• Automatic lock/unlock handling
  59. 59. Propertieser.extensions.ERXEC.safeLocking=true
  60. 60. Debugging
  61. 61. Demo
  62. 62. Properties-Dcom.sun.management.jmxremote=true-Dcom.sun.management.jmxremote.authenticate=false-Dcom.sun.management.jmxremote.ssl=false// Specific port-Dcom.sun.management.jmxremote.port=20102
  63. 63. Bottlenecks
  64. 64. EOF - Bottleneck• Shared Object-cache • Antithesis to Share Nothing model • Uses single database connection • Single-Threaded
  65. 65. #3 STM(Software Transactional Memory)
  66. 66. EOF + Scala• DOESN’T work in Scala Actors!•
  67. 67. Solutions• Use Raw SQL• Alternative database access • Squeryl • ...
  68. 68. Squeryl
  69. 69. Demo
  70. 70. Squeryl• POSOs• Actor Compatible• Concurrent
  71. 71. “Scala as a concurrent programming language is powerful, safe and easy-to-use”
  72. 72. Benchmarks
  73. 73. The Test• ERWOAdaptor (Mina) • WO Worker as Actor• Apache bench • c = 5...65 • n = 500
  74. 74. Results
  75. 75. Time per req. (mean)200 ms150 ms100 ms 50 ms 0 ms 5 10 15 20 25 30 35 40 45 50 55 60 65 WOAdaptor ERWOScalaAdaptor ERWOAdaptor
  76. 76. Requests per second800600400200 0 5 10 15 20 25 30 35 40 45 50 55 60 65WOAdaptor ERWOScalaAdaptor ERWOAdaptor
  77. 77. “Scala as a concurrent programming language is powerful, safe and easy-to-use”
  78. 78. The R&D Imperative In life long love The key Is R&D The ladder of invention Has eternal slide extension Rung by rung You’ll climb to heaven above. Constant innovation Guarantees a satiation Of that ever changing want And deepening need Nourishment and care To think anew… Makes passions flair And lets a culture breed Between the sheets… - by Emma Ahmad
  79. 79. Q&A
  80. 80. References• What will YOU do with 100 cores? http://www.computerworld.com.au/article/354261/• WebObjects with Scala http://wiki.objectstyle.org/confluence/display/WO/WebObjects+with+Scala• Case Study: Slowmation http://slowmation.uow.edu.au• Source: ERWOScalaAdaptor http://services.wocommunity.org/wowodc/ERWOScalaAdaptor
  1. A particular slide catching your eye?

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

×