GPars: Groovy Parallelism for Java

1,442 views

Published on

GPars is a concurrency and parallelism toolkit for the JVM. Founded on java.util.concurrent, it extends it with additional models of concurrency and parallelism, e.g. dataflow, CSP, actors, agents. Although GPars requires Groovy to run it is a toolkit usable from Java as well as Groovy codes.

This was presented at DevoxxUK 2013 2013-03-27T15:50

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

  • Be the first to like this

No Downloads
Views
Total views
1,442
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

GPars: Groovy Parallelism for Java

  1. 1. Groovy Parallelism for Java Prof Russel Winder Director Itz Interactive Ltd e: russel@itzinteractive.com e: russel@winder.org.uk t: @russel_winder
  2. 2. Prof Russel Winder ■ Company director, independent consultant, analyst, author, expert witness, trainer, mentor,… ■ Involved with GPars, Groovy, Gant, Gradle, GroovyFX, Python, SCons ■ Ex-theoretical physicist, ex-UNIX systems programmer, ex-computer science academic. Still human.
  3. 3. Interstitial Advert ?
  4. 4. Introduction
  5. 5. Concurrency ■ A technique for doing lots of little bits of work, one at a time, and then leaving them for later. ■ Co-routines.
  6. 6. Concurrency ■ Concurrency is also a technique for simulating parallelism on a uni-processor. ■ Time-division multiplexing.
  7. 7. Concurrency ■ Locks, semaphores, monitors all introduced to manage shared mutable memory in the presence of concurrency. ■ Operating systems techniques.
  8. 8. Parallelism ■ Having more than one thing happening at the same time: multiple processors or cores working on a single program at the same time. ■ The only reason for using parallelism is to make computations take less time.
  9. 9. Observation ■ Squirrels use locks when managing their food resources.
  10. 10. SomeInteraction
  11. 11. Question ■ Who is interested in harnessing parallelism for performance improvement?
  12. 12. Question ■ Who uses synchronized in Java?
  13. 13. Question ■ Who uses synchronized in Java? You are doing it wrong.
  14. 14. Question (with subsidiaries) ■ Who uses explicit locks in Java? ■ Who is not using java.util.concurrent? ■ Who is using java.util.concurrent?
  15. 15. Question (with subsidiaries) ■ Who uses explicit locks in Java? ■ Who is not using java.util.concurrent? ■ Who is using java.util.concurrent? You are definitely doing it wrong.
  16. 16. Rationale ■ The purpose of locks is to prevent parallelism. ■ Locks prevent performance improvement.
  17. 17. Consequence ■ Squirrels deny parallelism of consumption. ■ Squirrels deny performance improvement.
  18. 18. BeingPositive
  19. 19. Forward Looking Can Java 8 make things better?
  20. 20. Java 8 Streams ■ Internal rather than external iteration. ■ Functional programming approaches. ■ Threads as infrastructure. This is the real “biggy”, programmers do not explicitly manage threads.
  21. 21. Example π
  22. 22. What is the value of π ? ■ Easy, its π obviously. Its simples Александр Орлов 2009
  23. 23. Approximating π ? ■ Find an estimate of the value of π.  11 =∫0 dx ■ Approximate an integration with a 4 1x 2 summation. 4 n 1 π≈ ∑i=1 n i−0.5 2 1+( ) n
  24. 24. Quadrature Sum all the areas of the rectangles. Addition is associative and commutative. a + b + c + d = (a + b) + (c + d) Can sum partial sums. Embarrassingly parallel
  25. 25. Parallelism Scatter/gather Farmer/worker Fork/join Map/reduce
  26. 26. Code
  27. 27. Software Architectures Actors Independent Dataflow processes Operators connected communicating via by channels with asynchronous activity triggered by exchange of arrival of data on the messages. channels. Data Parallel Transform a sequence to CSP another sequence where Sequential processes all individual actions connected by channels happen at the same time. using synchronous message exchange (rendezvous).
  28. 28. Software Architectures Data Parallel Transform a sequence to another sequence where all individual actions happen at the same time.
  29. 29. Software Architectures Actors Independent processes communicating via asynchronous exchange of messages.
  30. 30. Software Architectures Dataflow Operators connected by channels with activity triggered by arrival of data on the channels.
  31. 31. Software Architectures CSP Sequential processes connected by channels using synchronous message exchange (rendezvous).
  32. 32. Software Architectures Active Objects Fork/Join An object that is An toolkit for tree structured actually an actor but concurrency and looks like a full parallelism. service object. Agents A wrapper for some Software Transactional shared mutable state. Memory Wrappers for mutable values that uses transactions rather than locks.
  33. 33. MoreCode
  34. 34. Mantra ■ Squirrels deny parallelism. ■ Squirrels deny performance improvement. ■ Programmers code should not emulate squirrel behaviour.
  35. 35. Q&A
  36. 36. Endnote
  37. 37. Source Code The sample codes are in a Git repository on GitHub and my own website.
  38. 38. The End
  39. 39. Interstitial Advert ?
  40. 40. Groovy Parallelism for Java Prof Russel Winder Director Itz Interactive Ltd e: russel@itzinteractive.com e: russel@winder.org.uk t: @russel_winder

×