O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

GPars Quick Hits

Use GPars quickly without having to re-architect your app.

  • Entre para ver os comentários

GPars Quick Hits

  1. 1. GPars Quick Hits Eric Sword
  2. 2. Who am I <ul><li>Professional geek for 17 years
  3. 3. Former head of engineering here at Group Logic
  4. 4. Now full-time dev and tech lead for SAIC
  5. 5. Blog: http://www.swordsystems.com
  6. 6. [email_address] </li></ul>
  7. 7. All Together Now <ul>JEEPERS! </ul>
  8. 8. Why GPars? <ul><li>Concise
  9. 9. Avoids errors with thread management </li><ul><li>No creating threads or managing pool </li></ul><li>Easy to Start </li><ul><li>Rolled into Groovy 1.8
  10. 10. import groovyx.gpars.XXX </li></ul></ul>
  11. 11. Who? <ul><li>Vaclav Pech started it in 2008
  12. 12. http://www.jroller.com/vaclav/
  13. 13. Jetbrains (makers of Intellij IDEA) employee?
  14. 14. Very responsive
  15. 15. Keeps an eye on GPars news </li></ul>
  16. 16. How? <ul><li>Grab
  17. 17. Maven </li></ul><ul><li><dependency>
  18. 18. <groupId>org.codehaus.groovy</groupId>
  19. 19. <artifactId>groovy-all</artifactId>
  20. 20. <version>1.8.2</version>
  21. 21. </dependency>
  22. 22. <dependency>
  23. 23. <groupId>org.codehaus.gpars</groupId>
  24. 24. <artifactId>gpars</artifactId>
  25. 25. <version>0.12</version>
  26. 26. </dependency> </li></ul><ul><li>@Grab('org.codehaus.gpars:gpars:0.12') </li></ul>
  27. 27. Version Dependency Hassles <ul><li>Groovy bundled with 0.11, but 0.12 is out
  28. 28. 0.11 -> org.coconut.forkjoin:jsr166y-070108.jar </li><ul><li>Or maybe jsr166y-070108.jar??? </li></ul><li>0.12 -> org.codehaus.jsr166-mirror </li><ul><li>jsr166y-1.7.0.jar
  29. 29. extra166y-1.7.0.jar </li></ul></ul>
  30. 30. 4 Main Parts <ul><li>Async Collections and Closures
  31. 31. Actors like Scala
  32. 32. Dataflow
  33. 33. Agents like Clojure </li></ul>
  34. 34. 4 Main Parts <ul><li>Async Collections and Closures
  35. 35. Actors like Scala
  36. 36. Dataflow
  37. 37. Agents like Clojure </li></ul>
  38. 38. Collection Fork-Join <ul><li>each,collect,find , etc become parallel </li><ul><li>See Re-GINA 17.2.2 for full list </li></ul><li>Insert wherever you want
  39. 39. No re-architecture </li></ul>
  40. 40. Collections - code import static groovyx.gpars.GParsPool.withPool def urls = [...some urls here...] withPool { urls.collectParallel{it.text} } <ul><li>You will see withPool a lot </li></ul>
  41. 41. Collections – code withPool { urls.makeConcurrent().collect{it.text} } //chain together withPool { urls.makeConcurrent() .collect{it.text} .findAll{it.contains 'GROOVY'} .size()} }
  42. 42. Warning: Breaking API Changes <ul><li>Big changes from 0.10 to 0.12 </li><ul><li>Calls deprecated in 0.11, removed in 0.12 </li></ul><li>makeTransparent -> makeConcurrent
  43. 43. Beware some examples in Ref Guide
  44. 44. Beware tutorials written for <=0.10
  45. 45. http://gpars.codehaus.org/Breaking+Changes </li></ul>
  46. 46. Collection cont... <ul><li>Show me some code... </li></ul>
  47. 47. Exception Handling <ul><li>If one call throws exception, whole closure will throw after all complete.
  48. 48. Example... </li></ul>
  49. 49. Map-Reduce <ul><li>Like regular collections, but no choke point
  50. 50. map -> collect, filter -> findAll </li></ul>From ReGina, Figure 17.1
  51. 51. Closures <ul><li>AsyncFun </li></ul>
  52. 52. Testing <ul><li>Test your code, not Gpars </li></ul>
  53. 53. Testing <ul><li>Test your code, not Gpars
  54. 54. Bonus! Your code doesn't change </li></ul>
  55. 55. Using Gpars for Testing <ul><li>http://www.slideshare.net/paulk_asert/groovy-and-concurrency - slide 102 </li></ul>
  56. 56. Behind The Scenes <ul><li>withPool uses a category to add the methods to collections, closures, etc.
  57. 57. Actual code in GparsPoolUtil
  58. 58. Map-Reduce methods also in that file in contained class PAWrapper </li></ul>
  59. 59. Resources <ul><li>http://gpars.codehaus.org
  60. 60. http://git.codehaus.org/gitweb.cgi?p=gpars.git;a=tree;f=src/test/groovy/groovyx/gpars/samples
  61. 61. http://www.manning.com/koenig2/
  62. 62. http://www.slideshare.net/gr8conf/g-pars-vaclavpech2011
  63. 63. http://www.slideshare.net/VaclavPech/pick-up-the-lowhanging-concurrency-fruit
  64. 64. http://skillsmatter.com/podcast/groovy-grails/concurrent-programming-for-you-and-me </li><ul><li>starts a little slow, but around minute 16, gives some good examples </li></ul><li>http://groovy.codehaus.org/Guy+Steele%27s+word+split+example+using+Groovy+and+GPars
  65. 65. http://www.slideshare.net/paulk_asert/groovy-and-concurrency </li></ul>
  66. 66. Thanks! <ul><li>Happy Parallelizing
  67. 67. http://www.swordsystems.com
  68. 68. http://www.slideshare.net/ericsword/gpars-quick-hits
  69. 69. [email_address] </li></ul>

×