Your SlideShare is downloading. ×
0
Kicking butt on concurrent
enterprise application with
           Scala




                  By
             Azrul MADISA...
Plat du jour
The concurrent
enterprise
The next billion users
Asynchronous
messaging
Enter Scala
Scala concurrency
Scala a...
The ever concurrent
      enterprise

Service A         Service A                 Service A



Service B
                 ...
Commerce example
                                  Choose your
                                     things
Choose from    ...
Other sectors

Telco
   Switch board → Exchanges →
    NGN
Government
   Counter based → E-Government
Finance
   Counter →...
The next billion users
                                                 Sum of Bandwidth:
                                ...
Don't mean to scare ya
 but...
People are more network centric
   Every mobile device is a potential
     terminal to your...
One word to rule them all
...
One word to rule them all
...


                        i t y
                  i l
            a b
      a l
   S c
What technology will allow
     this?
Criteria
    Play well with current enterprise
      systems
      Play well on the ...
Why asynchronous
         messaging important
E-commerce example:
                                               Verify
  ...
Why asynchronous
messaging important
Verify stock
  Millions of items
  Kicker... need to lock
    an item while
    reser...
Why asynchronous
         messaging important
Simplified e-
                                                    End
  comm...
Why asynchronous
         messaging important
Simplified e-
                                                              ...
Long running transaction

                 Short          OLTP
High volume
               processes


                    ...
Long running transaction

   Client pay




Package an item




Ship to client's
   premise




 Client sign off
Long running transaction

   Client pay




Package an item
                                   Reimburse 80%
             ...
Enter Scala
Created by Martin Odersky
Made is Swiss
    (no, it's not a knife nor a kind of cheese)
Run on Java JVM
    Ja...
Why not the other JVM
              languages
            JRuby, Jython , <The
              dynamic language of the
     ...
Scala concurrency:
Immutable variables
Immutable variables
  Variable that cannot change its
   value
  Useful in concurre...
Scala concurrency:
Immutable variables
Can Java do this?
  Java does this on String
  For other object:
    Tedious since ...
Scala concurrency: Easy
singleton
Often times, we need one single object per
  application
   E.g. Some utility class to a...
Scala concurrency: Easy
singleton
Can we do this in Java
  Sure, but, again, it's tedious
  You have to create all the boi...
Scala concurrency: Actors


Scala has actors
  … and no, they're not as
   bad as Paris Hilton
Scala concurrency: Actors
Actors
  Actors are objects
  Receive message asynchronously
  Reply with a Future
     Future =...
Scala concurrency: Actors
Event driven architecture
  Unlike threads, actors are
   event-driven
    Only become alive whe...
Scala concurrency: Actors

                  MainApp                                       End


               User choos...
Scala concurrency: Actors
case class MyMessage(myPaylod:String) //declare type of message
object Actor1 extends Actor {
 d...
Scala concurrency: Actors
Can we do this in Java
  In plain old Java, thread can be used
  Thread can not be created in a ...
Scala concurrency:
Reliability
Short-comings of Scala messages
  They do not live in a transaction
  They cannot travel th...
Combining actors and
message driven beans
Scala Actors   Message driven bean




                       `
Combining actors and
message driven beans
Scala Actors                                 Message driven bean




           ...
Combining actors and
     message driven beans
               Scala world                  JMS world

                    ...
Performance




Shamelessly plucked from
http://shootout.alioth.debian.org/u32q/benchmark.php?test=binarytrees&lang=all
Tools

Netbeans, Eclipse and IDEA plugin
My wish list

Scala actors working in XA
Developing EJB 3.1 in Scala
Seamlessly portable Scala apps to .Net
Better IDE sup...
Other interesting stuff

Lift
  Scala web framework based on
   actors
Scala books




Testing
  ScalaTest
References

The Scala official website
   scala-lang.org
Ted Neward's Scala For Busy Java
  Developer
Daniel Spiewak's Sca...
End note
Scala is a sharp weapon to use in
  the coming “highly concurrent”
  age
Hope to get you excited over
  Scala
   ...
Upcoming SlideShare
Loading in...5
×

Kicking Butt on Concurrent Enterprise Application with Scala

3,827

Published on

Kicking Butt on Concurrent Enterprise Application with Scala

MSC Malaysia Open Source Conference 2009 1 June 2009. Developers Track

http://www.mscmalaysia.my/opensource

http://www.mscoscon.my/

http://www.osdc,my/

more from Azrul

Lightning talk MSC Malaysia Open Source Conference 2009
3 June 2009. 5pm Bronx V

Archive

http://mscoscon.blogspot.com/2009/06/cyber-merdeka-cyber-sovereignity-by.html

Published in: Technology
2 Comments
6 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,827
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
67
Comments
2
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Kicking Butt on Concurrent Enterprise Application with Scala"

  1. 1. Kicking butt on concurrent enterprise application with Scala By Azrul MADISA Freelance Java Developer azrulhasni@gmail.com
  2. 2. Plat du jour The concurrent enterprise The next billion users Asynchronous messaging Enter Scala Scala concurrency Scala actors Scala and Message Driven Beans
  3. 3. The ever concurrent enterprise Service A Service A Service A Service B Service B Service B Service C Service C Service C Service D Service D Service D Traditional Modern Web N.0 (large # of instances)
  4. 4. Commerce example Choose your things Choose from Choose from things in the things in the store store Pay Queue up Queue up (1 counter in (Many counters the shop) In the shop) Inventory Packaging Pay and delivery Pay Traditional Hypermarkets E-Commerce
  5. 5. Other sectors Telco Switch board → Exchanges → NGN Government Counter based → E-Government Finance Counter → ATM → E-Banking Others Millitary, logistics, media & content
  6. 6. The next billion users Sum of Bandwidth: Google, Twitter, Facebook etc. HPC (High performance Computing) Genomics, Animation *Prise (Enterprise) Cloud based, Saas, * http://blogs.sun.com/Gregp/entry/a_word_or_two_on
  7. 7. Don't mean to scare ya but... People are more network centric Every mobile device is a potential terminal to your services How many mobile devices are there? A couple of billion ? People are not the only ones accessing your services [Please hum the X-Files theme song in your head right now] => Computing demand grows faster than Moore's law Also known as the red shift
  8. 8. One word to rule them all ...
  9. 9. One word to rule them all ... i t y i l a b a l S c
  10. 10. What technology will allow this? Criteria Play well with current enterprise systems Play well on the JVM Fault tolerent Share-nothing philosophy Asynchronous messaging No side effect (Maybe functional) Easy to learn (tool support, language LAF) Performance – At least as good as current offerings Take advantage of multi-core tech.
  11. 11. Why asynchronous messaging important E-commerce example: Verify stock User choose Go to Start products checkout No Inform user End Stock exist? Take payment Yes End from user
  12. 12. Why asynchronous messaging important Verify stock Millions of items Kicker... need to lock an item while reserving it To avoid 2 person buying the same thing Lengthy => Clients will run away
  13. 13. Why asynchronous messaging important Simplified e- End commerce User choose Go to Take payment Start products checkout from user
  14. 14. Why asynchronous messaging important Simplified e- End commerce User choose Go to Take payment Start products checkout from user Fire another process Yes Packaging + End Shipment Verify stock Stock exist? Email to user – item would be End No a bit late
  15. 15. Long running transaction Short OLTP High volume processes We somewhat know how to do this High volume Long running processes ?
  16. 16. Long running transaction Client pay Package an item Ship to client's premise Client sign off
  17. 17. Long running transaction Client pay Package an item Reimburse 80% Back to client Exception! Ship to client's premise Ship back to Client cancel vendor's premise Client sign off
  18. 18. Enter Scala Created by Martin Odersky Made is Swiss (no, it's not a knife nor a kind of cheese) Run on Java JVM Java is king of the enterprise, running on JVM ensures adoption. Can use and inherit Java classes. Also runs on .Net CLR Object oriented and functional at the same time Statically typed with type inference Recently used by Twitter on the back-end ... replacing that other you-know-which language ;)
  19. 19. Why not the other JVM languages JRuby, Jython , <The dynamic language of the day> Duck typing? No thanks Clojure Interesting but syntax is too “lisp-y” - My personal opinion Plain old Java Are you kidding me? Image from: http://www.travelblog.org/Europe/Netherlands/North-Holland/Volendam/blog-385862.html
  20. 20. Scala concurrency: Immutable variables Immutable variables Variable that cannot change its value Useful in concurrent apps State cannot be inconsistent Easily declare variables as immutable The “val” keyword automatically makes variable immutable val movie = new Movie(“Wolverine”)
  21. 21. Scala concurrency: Immutable variables Can Java do this? Java does this on String For other object: Tedious since Java don't have operator overloading
  22. 22. Scala concurrency: Easy singleton Often times, we need one single object per application E.g. Some utility class to access the database Scala provide easy singleton: object MySingleton{ //singleton's body } The singleton's constructor is fully synchronized
  23. 23. Scala concurrency: Easy singleton Can we do this in Java Sure, but, again, it's tedious You have to create all the boilerplat code yourself Refer to the Gang Of Four book
  24. 24. Scala concurrency: Actors Scala has actors … and no, they're not as bad as Paris Hilton
  25. 25. Scala concurrency: Actors Actors Actors are objects Receive message asynchronously Reply with a Future Future = placeholder of future result Concurrency without threading Event-driven Unlike real-world actors, Scala actors are Cheap Totally ignored by politicians
  26. 26. Scala concurrency: Actors Event driven architecture Unlike threads, actors are event-driven Only become alive when there are messages to be processed. Execute on a thread pool With message passing, number of locks are low Great for multicore processors
  27. 27. Scala concurrency: Actors MainApp End User choose Go to Take payment Start products checkout from user Fire another process Yes Packaging + End Shipment Verify stock Stock exist? Email to user – item would be End Actor1 No a bit late
  28. 28. Scala concurrency: Actors case class MyMessage(myPaylod:String) //declare type of message object Actor1 extends Actor { def act = { loop { react { case MyMessage(“Continue e-commerce process”) => //Manage Stock verification, Packaging and Delivery here … //closing curly braces } object MainApp extends Application { //Do your business logic here, once you get to Payment ... Actor1.start Actor1 ! MyMessage(“Continue”) //send message to actor Actor1 }
  29. 29. Scala concurrency: Actors Can we do this in Java In plain old Java, thread can be used Thread can not be created in a Java EE container Have to use JMS OpenMQ ActiveMQ Message Driven Beans Message Driven Pojo with Spring
  30. 30. Scala concurrency: Reliability Short-comings of Scala messages They do not live in a transaction They cannot travel through a network There are projects to address this short coming Scala OTP (Equivalent to Erlang OTP) ActiveObject Another approach is to combine Scala and Java EE
  31. 31. Combining actors and message driven beans Scala Actors Message driven bean `
  32. 32. Combining actors and message driven beans Scala Actors Message driven bean ` Bridging agent acting like a “worm-hole” d Between the Scala world and MDB el ate re kr ! ! ta r T used uck d : S eing ek, NG e R NI is b t a g y WA alog e no an ou'r If y
  33. 33. Combining actors and message driven beans Scala world JMS world Request Actor javax.jms.MessageListener Queue WormholeActor MDB Scala object Spring's Message Driven Pojo Response Queue
  34. 34. Performance Shamelessly plucked from http://shootout.alioth.debian.org/u32q/benchmark.php?test=binarytrees&lang=all
  35. 35. Tools Netbeans, Eclipse and IDEA plugin
  36. 36. My wish list Scala actors working in XA Developing EJB 3.1 in Scala Seamlessly portable Scala apps to .Net Better IDE support Scala actors that can travel through a grid/cloud/network Pi-calculus Scala + SOA An international Scala conf. in Malaysia A magic flying talking pony err... car
  37. 37. Other interesting stuff Lift Scala web framework based on actors Scala books Testing ScalaTest
  38. 38. References The Scala official website scala-lang.org Ted Neward's Scala For Busy Java Developer Daniel Spiewak's Scala for Java Refugees Debasish Ghosh's Scala Actors 101 Various blogs, forums, people (too many to name … )
  39. 39. End note Scala is a sharp weapon to use in the coming “highly concurrent” age Hope to get you excited over Scala Play with it Test it Use it Twitt/blog about it Get something moving in Malaysia
  1. A particular slide catching your eye?

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

×