Successfully reported this slideshow.
Concurrency andParallelism with Scala       Timothy Perrett    BrisFunctional, June 2011           software. done right.
About Me  Big Scala Geek  Author of Lift in Action  Coding Scala since 2007  Background in both dynamic   and statical...
Concurrency       vsParallelism   software. done right.
ConcurrencyMutable state is   Plain Evil     software. done right.
ConcurrencyThreads and Locks    are EOL      software. done right.
Concurrency Actors tothe Rescue  software. done right.
Concurrency   msg              msg msg        msg           msg                                Mailbox            msg     ...
Concurrency  Simpler mental model  Much easier to avoid common issues:    Deadlocks    Race Conditions    Starvation ...
Concurrencycase class Increment(amount: Int)	class Counter extends Actor {	   private var count = 0	   def receive = {	   ...
Concurrencyval counter = actorOf[Counter]	        counter.start	            software. done right.
Concurrencycounter ! Increment(10) 	        Fire	  and	  forget	           software. done right.
Concurrencycounter !!! Increment(10) 	        Fire	  yielding	  a	  Future	               software. done right.
Concurrency  software. done right.
Concurrency  software. done right.
ConcurrencyDon’t Block.    Ever.  (it’s	  a	  zen	  thing)	      software. done right.
Parallelism   software. done right.
ParallelismCollectionson crack i-core      ____________      Mult  software. done right.
list.filter(predicate)	        software. done right.
list.filter(predicate).par	          software. done right.
ParallelismCreate	  small	  units	  of	  work	  to	  split	  over	  available	  processor	  capacity	                     ...
Parallelism              Stolen!Processor A                   Processor B          software. done right.
PlainLazysoftware. done right.
Not 100%Toll Free software. done right.
Summary  Manually handling threads and locks sucks  Actors provide a sane model for concurrency  Build completely async...
Further Reading  Scala Language  http://scala-lang.org  Akka Actor Toolkit  http://akka.io/  State: You’re Doing It Wro...
Questions?twitter.com/timperrett                      Lift in Actiongithub.com/timperrett                  manning.com/per...
Upcoming SlideShare
Loading in …5
×

Concurrency and Parallelism with Scala

4,124 views

Published on

Published in: Technology
  • Be the first to comment

Concurrency and Parallelism with Scala

  1. 1. Concurrency andParallelism with Scala Timothy Perrett BrisFunctional, June 2011 software. done right.
  2. 2. About Me  Big Scala Geek  Author of Lift in Action  Coding Scala since 2007  Background in both dynamic and statically typed languages  Manufacturing and marketing automation is my day job h"p://manning.com/perre"/   software. done right.
  3. 3. Concurrency vsParallelism software. done right.
  4. 4. ConcurrencyMutable state is Plain Evil software. done right.
  5. 5. ConcurrencyThreads and Locks are EOL software. done right.
  6. 6. Concurrency Actors tothe Rescue software. done right.
  7. 7. Concurrency msg msg msg msg msg Mailbox msg Actor software. done right.
  8. 8. Concurrency  Simpler mental model  Much easier to avoid common issues:   Deadlocks   Race Conditions   Starvation   etc software. done right.
  9. 9. Concurrencycase class Increment(amount: Int) class Counter extends Actor { private var count = 0 def receive = { case Increment(by) => count += by println(count) } } software. done right.
  10. 10. Concurrencyval counter = actorOf[Counter] counter.start software. done right.
  11. 11. Concurrencycounter ! Increment(10) Fire  and  forget   software. done right.
  12. 12. Concurrencycounter !!! Increment(10) Fire  yielding  a  Future   software. done right.
  13. 13. Concurrency software. done right.
  14. 14. Concurrency software. done right.
  15. 15. ConcurrencyDon’t Block. Ever. (it’s  a  zen  thing)   software. done right.
  16. 16. Parallelism software. done right.
  17. 17. ParallelismCollectionson crack i-core ____________ Mult software. done right.
  18. 18. list.filter(predicate) software. done right.
  19. 19. list.filter(predicate).par software. done right.
  20. 20. ParallelismCreate  small  units  of  work  to  split  over  available  processor  capacity   software. done right.
  21. 21. Parallelism Stolen!Processor A Processor B software. done right.
  22. 22. PlainLazysoftware. done right.
  23. 23. Not 100%Toll Free software. done right.
  24. 24. Summary  Manually handling threads and locks sucks  Actors provide a sane model for concurrency  Build completely asynchronous systems  Get the most out of your hardware investment software. done right.
  25. 25. Further Reading  Scala Language http://scala-lang.org  Akka Actor Toolkit http://akka.io/  State: You’re Doing It Wrong http://www.slideshare.net/jboner/state-youre-doing-it-wrong-javaone-2009  A Generic Parallel Collection Framework http://infoscience.epfl.ch/record/150220/files/pc.pdf software. done right.
  26. 26. Questions?twitter.com/timperrett Lift in Actiongithub.com/timperrett manning.com/perrett/blog.getintheloop.eu software. done right.

×