Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive とは何か? #reactive_shinjuku

Reactive とは何か? #reactive_shinjuku

2015/08/18 Reactive System Meetup in 西新宿 by @okapies
http://reactive-shinjuku.connpass.com/event/17991/

Ef45a84b10aa3cb5acd2ea0c9846bd3b?s=128

Yuta Okamoto

August 18, 2015
Tweet

Transcript

  1. Reactive System Meetup in ੢৽॓ 
 Reactive ͱ͸Կ͔? Yuta Okamoto

    (@okapies) 2015/08/18ʢվగ1ʣ
  2. Who are you? • Ԭຊ ༤ଠ (@okapies) • ڵຯ͕͋Δ͜ͱɿ •

    Scala ͱ͔ؔ਺ܕϓϩάϥϛϯάͱ͔ • ΢ΣϒαʔϏεͷΠϯϑϥपΓʢBash ৬ਓʣ • Scala Matsuri 2016 ४උҕһʢ຋༁νʔϜʣ
  3. ॻ͍ͨهࣄ • ւ֎จݙͷ຋༁ • Reactive Manifesto (http://www.reactivemanifesto.org/) • Effective Scala

    (http://twitter.github.io/effectivescala/) • ϒϩάهࣄ (http://okapies.hateblo.jp/) • ʮؔ਺ܕϓϩάϥϚͷͨΊͷ Rx ೖ໳ʯγϦʔζ • ʮϚΠΫϩαʔϏε͕ Scala ΛબͿ̏ͭͷཧ༝ʯ
  4. Scala Matsuri 2016 ! ! • དྷ೥1݄30ʙ31೔ʹ։࠵ܾఆʂ http://scalamatsuri.org/ • ొஃऀืूதɻԠืΛ͓଴ͪͯ͠·͢ʂ

    • ४උҕһձͷελοϑืूதʢ࣍ճఆྫ 9/12ʢ౔ʣʣ
  5. ࠓ೔͓࿩͍ͨ͜͠ͱ • Reactive ͱ͸Կ͔ʁʢʹ͍ͭͯͷࢲͷཧղʣ • Reactive ͷഎܠʹ͋ΔύϥμΠϜγϑτ • खଓ͖ܕ (how)

    ͔Βએݴܕ (what) ΁ • ϓϩάϥϛϯάϞσϧ͔ΒϥϯλΠϜ΁ • ಉظతͳϞϊϦε͔Βඇಉظతͳ෼ࢄγεςϜ΁
  6. Reactive?

  7. ͦ΋ͦ΋ Reactive ͱ͸ʁ • ਓʹΑͬͯɺͦΕͧΕશ͘ҟͳΔཱ৔Ͱٞ࿦ ͍ͯ͠Δͷ͕ݱঢ় http://reactive-shinjuku.connpass.com/event/17991/

  8. Reactive ͷࡾͭͷཱ৔ Reactive Systems Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ:

    γεςϜΞʔΩςΫνϟ:
  9. Reactive ͷ
 Ϣʔεέʔε

  10. Reactive ͕ٻΊΒΕΔ৔໘ • Frontend • GUIɾϑϩϯτΤϯυ • Backend • ϚΠΫϩαʔϏε

    • Ϗοάσʔλॲཧ ϓϩάϥϛϯάϞσϧ͕ओͳؔ৺ Ճ͑ͯΞʔΩςΫνϟʹؔ৺
  11. ղܾ͍ͨ͠՝୊ • ػೳ໘: • Πϕϯτʢϝοηʔδʣۦಈ • ඇಉظͳίϯϙʔωϯτؒ࿈ܞ • ฒߦɾฒྻॲཧ •

    ඇػೳ໘: • ଱ো֐ੑɺεέʔϥϏϦςΟ ՝୊΍ͦΕʹର͢ΔΞϓϩʔν͸
 ڞ௨͍ͯ͠Δ͕…
  12. “Reactive” in Frontend • Reactive Extensions • Bacon.js • Elm

    • React.js • …
  13. GUIɾϑϩϯτΤϯυ ྫ: RxJS ඇಉظͷΫϦοΫετϦʔϜ͔Β
 μϒϧΫϦοΫ͚ͩΛநग़͢Δ https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 ΫϦοΫΛ 250ms
 ͝ͱʹ·ͱΊͯ ͦΕͧΕΛ


    ௕͞ʹม׵͢Δ
  14. GUIɾϑϩϯτΤϯυ https://github.com/tehmou/rx-android-architecture RxJava + Android
 ͷσϞΞϓϦ ςΩετϘοΫε͕ߋ৽͞Ε
 Δ౓ʹ JSON API

    Ͱݕࡧɻ ໭͖ͬͯͨ݁ՌΛඇಉظʹ Widget ʹ൓ө
  15. “Reactive” in Backend • ϚΠΫϩαʔϏε • Ϗοάσʔλॲཧ ෼ࢄॲཧ΍ฒྻॲཧ͸ɺ΋͸΍
 ಛผͳ΋ͷͰ͸ͳ͘ͳΓͭͭ͋Δ

  16. ϚΠΫϩαʔϏε val userAndTweets = Future.join( userService.findByUserId(userId), tweetService.findByUserId(userId) ) find find

    userId userAndTweets User
 Service Tweet
 Service http://www.slideshare.net/knoldus/finagle-by-twitter-engineer/16 join ଞͷϚΠΫϩαʔϏε (UserService, TweetService) ʹΫΤϦΛඇಉظʹ౤͛ ͯɺ݁Ռ͕ೋͭͱ΋ฦ͖ͬͯͨ࣌఺Ͱ
 ଋͶͯग़ྗ ྫ: Twitter Finagle
  17. େن໛ͳϚΠΫϩαʔϏεͷྫ http://www.slideshare.net/adriancockcroft/goto-berlin/76

  18. Ϗοάσʔλॲཧ https://speakerdeck.com/googlecloudjapan/google-cloud-dataflowwoli-jie-suru ྫ: Google Cloud Dataflow େྔͷ tweet Λूܭ͠ hashtag

    ͷτοϓ3Λग़ྗ
  19. αʔϏεʹର͢ΔཁٻͷมԽ ਺೥લ ݱࡏ αʔό਺ ʙ਺ेϊʔυ ਺ઍҎ্ʙ ཁٻԠ౴࣌ؒ ʙ਺ඵ ʙϛϦඵ ཁٻՔಇ཰

    ਺࣌ؒͷΦϑϥΠϯ
 ϝϯςφϯεΛڐ༰ 100% σʔλྔ ΪΨόΠτ୯Ґ ϖλόΠτ୯Ґ
  20. Reactive Manifesto http://www.reactivemanifesto.org/ja

  21. Reactive Manifesto • Reactive Systems ΁ͷࢧ࣋Λݺͼ͔͚Δจॻ • ࣾͷ CTO Β͕ओಋ

    • ଞʹ Dave Farley (”ܧଓతσϦόϦʔ”ͷஶऀ) ΍ Martin Thompson (ݩ LMAX CTO) ͳͲ • ϚʔέςΟϯάจॻͱͯ͠ͷ৭࠼͕ೱ͍ʢํ޲ੑ ͱͯ͠͸ “The Twelve-Factor App” ʹ͍ۙʣ ͦΖͦΖࢍಉऀ
 12,000 ਓ௒͑
  22. Reactive Streams • “Back-Pressure ෇͖ͷඇಉظετϦʔϜॲཧ” ͷ ඪ४ΛఆΊΔ࢓༷ • ඇಉظετϦʔϜॲཧʹ͖ͭ·ͱ͏ϑϩʔ੍ޚ ͷ՝୊ʢόοϑΝᷓΕ໰୊ʣͷղܾࡦΛఏࣔ

    • ࢓༷ʹ४ڌͨ͠ϥϯλΠϜͷ૬ޓ઀ଓੑΛอূ • JDK 9 Ͱͷඪ४Խʹ޲͚ͯ࡞ۀத Reactive Systems
 ͷٕज़త՝୊Λղܾ
  23. ܦҢ • Reactive Manifesto ͷൃද(2013೥9݄) • Typesafe ͷओಋͰɺඇಉظετϦʔϜٕज़Λ ։ൃ͢Δϕϯμʔ֤ࣾͷؒͰɺϑϩʔ੍ޚͷٕ ज़՝୊ͷղܾࡦΛ࿩͠߹͏ίϛϡχςΟ͕ൃ଍

    • GitHub ʹ reactive-streams άϧʔϓΛ࡞੒ɻ ਖ਼ࣜʹڞಉͰ࢓༷ࡦఆΛ࢝ΊΔ(2014೥ॳ಄)
  24. ओͳࢀՃϕϯμʔ • (Akka) • (RxJava) • (Reactor) • (Vert.x) Scala

    ݴޠͷ։ൃݩ ถࠃ࠷େखͷ
 ಈը഑৴αʔϏε Spring Framework
 ͷ։ൃݩ
  25. ओͳࢀՃऀ • Doug Lea • JSR 166 (java.util.concurrent)
 ͷ Specification

    Lead • “Java Concurrency in Practice”
 ͷஶऀͷҰਓ • JDK Ͱͷඪ४Խ͸ࢯͷओಋͰਐΊΒΕ͍ͯΔ http://www.amazon.co.jp/dp/4797337206/
  26. OpenJDK Ͱͷඪ४Խ׆ಈ http://openjdk.java.net/jeps/8132960

  27. https://www.flickr.com/photos/sdstrowes/8248580877 Reactive ͷ
 جຊతͳߟ͑ํ

  28. Reactive ͳίϯϙʔωϯτ • ཱ৔ͷҧ͍͸લఏͱͯ͠ɺͦͷதͰ΋ڞ௨͠ ͯݴ͑ͦ͏ͳ͜ͱΛׅΓͩͯ͠ΈΔ ʁ ※ ఆٛͷҰྫͰ͢

  29. Reactive ͳίϯϙʔωϯτ • σʔλͷೖྗʹ൓Ԡ (react) ͯ͠ɺͦΕΛม׵ ͯ͠ग़ྗ͢Δ ʁ ೖྗ ग़ྗ

    • ؔ਺ʁ • ΦϒδΣΫτʁ • ΞΫλʔʁ • αϒγεςϜʁ ίϯϙʔωϯτͷதͰ
 ಈ࡞͕׬݁͢Δ
  30. ๬·͍͠ੑ࣭: ૄ݁߹ੑɺִ཭ੑ • ϞδϡʔϧԽ, ඇಉظԽ, ฒྻԽ͕༰қʹͳΔ ʁ ೖྗ ग़ྗ ?

    ? ࣗ෼͕Կͷίϯϙʔωϯτ ʹґଘ͢Δ͔͸ҙࣝ͠ͳ͍ × × ֎ଆͷঢ়ଶ΍ಈ࡞ʹ
 ʢ҉໧తʹʣ
 ӨڹΛ༩͑ͳ͍ ೖྗσʔλʹͷΈґଘ͢Δ
  31. σʔλϑϩʔ Input Input Output ૄ݁߹ͳίϯϙʔωϯτΛ૊Έཱͯͨσʔλϑϩʔ ೖྗ ग़ྗ

  32. Reactive Programming https://www.flickr.com/photos/kovah/15331505770

  33. Reactive Programming Reactive Systems Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ

    γεςϜΞʔΩςΫνϟ
  34. Reactive ͳϓϩάϥϜ Input Input Output ೖྗ ग़ྗ Reactive ͳίϯϙʔωϯτΛ
 σʔλϑϩʔͱͯ͠૊ΈཱͯΔ


    ͜ͱͰϓϩάϥϛϯά͢Δ
  35. ैདྷͷखଓ͖ܕϓϩάϥϜ A = 1; B = 2; C = (A+1)

    + (B-1)*2; ※”Ͳ͏΍࣮ͬͯߦ͢Δ͔”͸ࣗ໌ ʢʹ ࣮ߦϞσϧʣ ্͔Βॱ൪ʹ࣮ߦ͢Δ
  36. खଓ͖ܕ vs Reactive • ैདྷͷखଓ͖ܕͷϓϩάϥϛϯάϞσϧͱશ ͘૬༰Εͳ͍Α͏ʹݟ͑Δɺ͕… 1 2 A =

    1; B = 2; C = (A+1) + (B-1)*2; ೖྗ ग़ྗ
  37. -1 ×2 + +1 A B C खଓ͖͸σʔλϑϩʔͰදݱͰ͖Δ A =

    1; B = 2; C = (A+1) + (B-1)*2; 1 2 4 1 2 2 ※Ͳ͏࣮ߦ͢Δ͔͸๨ΕΑ͏ ʢม਺ͱԋࢉࢠͷؔ܎͚ͩݟΔʣ
  38. σʔλϑϩʔͱ࣮ߦϞσϧ • खଓ͖ܕͱ Reactive ͸ͲͪΒ΋σʔλϑϩʔ Ͱදݱ͢Δ͜ͱ͕Ͱ͖Δ
 㱺 ҧ͍͸࣮ߦϞσϧʹ͋Δ A B

    C A = 1; B = 2; C = (A+1) + (B-1)*2; ೖྗ ग़ྗ
  39. -1 ×2 + +1 A B C ม਺Λߋ৽: खଓ͖ܕͷ৔߹ A

    = 1; B = 2; C = (A+1) + (B-1)*2;
 A = 2; 1 $ 2 2 4 C ʹ͸
 ൓ө͞Εͳ͍ खଓ͖ܕͷ࣮ߦϞσϧ × × × × × ×
  40. -1 ×2 + +1 A B C Reactive ͳมߋͷ఻೻ A

    := 1; B := 2;
 C := (A+1) + (B-1)*2;
 A := 2; 1 $ 2 4 $ 5 2 1 $ 3 1 2 A ͷมߋ͕
 C ʹ൓ө͞ΕΔ Reactive ͳ࣮ߦϞσϧ
  41. -1 ×2 + +1 A B C Reactive ͳมߋͷ఻೻ 2

    5 $ 7 2 $ 3 1 $ 2 2 $ 4 3 C := (A+1) + (B-1)*2;
 A := 2; B := 3; B ͷมߋ͕
 C ʹ൓ө͞ΕΔ Reactive ͳ࣮ߦϞσϧ
  42. -1 ×2 + +1 A B C Reactive ͳมߋͷ఻೻ 2

    $ 0 7 $ 5 3 2 4 3 $ 1 A := 2;
 B := 3;
 A := 0; A ͷมߋ͕
 C ʹ൓ө͞ΕΔ Reactive ͳ࣮ߦϞσϧ
  43. ྫ (RxJava): Observable<Integer> a = …; Observable<Integer> b = …;

    ! Observable<Integer> a1 = a.map( (i) -> i + 1 ); Observable<Integer> b1 = b.map( (j) -> j - 1 ) .map( (k) -> k * 2 ); ! ! Observable<Integer> c = Observable.combineLatest(a1, b1, (i, j) -> i + j ); A B C +1 —1 ×2 +
  44. ྫ (RxJava): Observable<Integer> a = …; Observable<Integer> b = …;

    ! Observable<Integer> a1 = a.map( (i) -> i + 1 ); Observable<Integer> b1 = b.map( (j) -> j - 1 ) .map( (k) -> k * 2 ); ! ! Observable<Integer> c = Observable.combineLatest(a1, b1, (i, j) -> i + j ); σʔλϑϩʔΛܨ͛Δϝιου ؔ਺ ೖྗ A B C +1 —1 ×2 + “Ͳ͏࣮ߦ͢Δ͔” ͸
 Ͳ͜ʹ΋ॻ͍ͯͳ͍ʂ
  45. ϓϩάϥϛϯάϞσϧ + ϥϯλΠϜ Input Input Output (2) ϥϯλΠϜ (1) ϓϩάϥϛϯάϞσϧ

    ʢมߋͷ఻೻ (how) ΛϓϩάϥϚʹ୅Θ࣮ͬͯߦ͢Δʣ ʢσʔλϑϩʔ (what) Λهड़͢Δखஈʣ
  46. ϓϩάϥϛϯάϞσϧ + ϥϯλΠϜ Reactive Systems Reactive Programming ??? ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ:

    γεςϜΞʔΩςΫνϟ ϥϯλΠϜʹΑΔ
 มߋͷ఻೻͕ RP ͷಛ௃
  47. ղܾ͍ͨ͠՝୊ʢ࠶ܝʣ • ػೳ໘: • Πϕϯτʢϝοηʔδʣۦಈ • ඇಉظͳίϯϙʔωϯτؒ࿈ܞ • ฒߦɾฒྻॲཧ •

    ඇػೳ໘: • ଱ো֐ੑɺεέʔϥϏϦςΟ खଓ͖తͳϓϩάϥϛϯάख๏
 Ͱهड़͢Δͷ͸େมͩͬͨ
  48. Reactive ͳϞσϧͷϝϦοτ • ֎͔ΒͷΠϕϯτ͕
 ࣗಈతʹ఻೻͞ΕΔ • ඇಉظԽɾฒྻԽ͠΍͍͢ • “What” ͱ

    “How” ͕෼཭͞ΕΔͷͰ
 ૊Έ߹ΘͤՄೳ (composable) ʹ͠΍͍͢ }ϥϯλΠϜʹ೚ͤΔ
  49. “What” ͱ “How” ͷ෼཭ • ϓϩάϥϚ͸”ೖྗΛԿʹม׵͢Δ͔“͚ͩʹ
 ஫໨ͯ͠ϩδοΫΛॻ͘
 㱺 ֎෦ͷঢ়ଶʹӨڹΛड͚ͣૄ݁߹ੑ͕ߴ·Δ •

    ”Ͳ͏΍࣮ͬͯߦ͢Δ͔”͸ϥϯλΠϜͷ໾ׂ ʢ࣮ߦϞσϧʣ ? ? ? ? ?
  50. σʔλϑϩʔͷ࠷దԽ • ϥϯλΠϜ͸ɺσʔλϑϩʔͷ࣮ߦํ๏Λࣗ ಈతʹ࠷దԽ͢Δ༨஍͕͋Δ • ܭࢉͷ݁߹ (fuse) ΍ہॴԽ • ฒྻԽ

    • ෼ࢄԽ
  51. ྫ: Akka Streams • ܕ҆શͳ DSL Ͱهड़ͨ͠σʔλϑϩʔΛ Akka Actor ্Ͱ࣮ߦ͢ΔϥϯλΠϜ

    implicit val system = ActorSystem() implicit val mat = ActorFlowMaterializer() ! val source = Source[Int](1 to 5) val sink = Sink.foreach[Int](println) ! source.map(_ * 2).runWith(sink) Actor ͷ४උ Materializer Λ࢖࣮ͬͯߦ
  52. FlowGraph DSL val g = FlowGraph { implicit builder =>

    import akka.stream.scaladsl.FlowGraphImplicits._ ! source ~> f1 ~> bcast ~> f2 ~> merge ~> f3 ~> sink bcast ~> f4 ~> merge } Source f2 Sink f4 f1 Broadcast f3 Merge
  53. Materializer ʹΑΔ࠷దԽ • DSL Ͱهड़ͨ͠ FlowGraph Λ Materializeʢ۩ ݱԽʣ࣮ͯ͠ߦ͢Δ •

    Materializer ͷ࣮૷࣍ୈͰ༷ʑͳ࠷దԽΛࢪ ͤΔ࢓૊Έʹͳ͍ͬͯΔ • Akka ࣗମ͕෼ࢄϑϨʔϜϫʔΫͳͷͰɺকདྷ తʹ͸ࣗಈతͳ෼ࢄԽʹ΋ରԠͰ͖Δʁ
  54. ϥϯλΠϜͱͯ͠ͷΫϥ΢υ https://speakerdeck.com/googlecloudjapan/google-cloud-dataflowwoli-jie-suru Google Ϋϥ΢υ͕
 ϥϯλΠϜʹ͋ͨΔ σʔλϑϩʔఆٛ

  55. Reactive Programming ͷར఺ • σʔλϑϩʔͷ࣮ߦΛϥϯλΠϜʹ೚ͤΔ͜ͱͰ • Πϕϯτۦಈɺඇಉظॲཧɺฒߦɾฒྻॲཧ ͕ඞཁͳίʔυ͕༰қʹهड़Ͱ͖Δ • “What”

    ͱ “How” ͕෼཭͞ΕΔ͜ͱͰૄ݁߹ ੑ͕ߴ·Δ • ࣮ߦͷࣗಈతͳ࠷దԽ͕ՄೳʹͳΔ
  56. Reactive Systems http://www.reactivemanifesto.org/ja

  57. Reactive Systems Reactive Systems Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ ϥϯλΠϜ

    γεςϜΞʔΩςΫνϟ:
  58. ཁٻͷมԽʢ࠶ܝʣ ਺೥લ ݱࡏ αʔό਺ ʙ਺ेϊʔυ ਺ઍҎ্ʙ ཁٻԠ౴࣌ؒ ʙ਺ඵ ʙϛϦඵ ཁٻՔಇ཰

    ਺࣌ؒͷΦϑϥΠϯ
 ϝϯςφϯεΛڐ༰ 100% σʔλྔ ΪΨόΠτ୯Ґ ϖλόΠτ୯Ґ
  59. ղܾ͍ͨ͠՝୊ʢ࠶ܝʣ • ػೳ໘: • Πϕϯτʢϝοηʔδʣۦಈ • ඇಉظͳίϯϙʔωϯτؒ࿈ܞ • ฒߦɾฒྻॲཧ •

    ඇػೳ໘: • ଱ো֐ੑɺεέʔϥϏϦςΟ
  60. Reactive Systems “େن໛γεςϜΛߏங͢Δ૊৫͸
 ͜ͷมԽʹରॲ͢ΔઃܭݪଇΛ
 ͢Ͱʹൃݟ͍ͯ͠Δ” ! ! ! “ͦͷΑ͏ͳಛ௃Λඋ͑ΔγεςϜΛ Reactive

    Systems ͱݺ΅͏” http://www.reactivemanifesto.org/ja
  61. Reactive Systems ͷ۩ମྫ ࢲ͕࢓ࣄͰؔΘͬͨɺେ͖ͳγεςϜͷΞʔΩςΫνϟ ʹ͸ྨࣅ఺͕͋ͬͨɻ ͦ͏ͨ͠γεςϜͰ͸ɺ໰୊ྖҬʹ͓͚Δ໌֬ͳ Bounded Context Λ࣮૷ͨ͠αʔϏε͕ૄ݁߹Ͱ݁ͼ ͍͓ͭͯΓɺޓ͍ͷ௨৴͸ඇಉظϝοηʔδͷΈͰߦ

    ͏ɻ ͜ΕΒ͸ɺRDB ͷ্ʹߏங͞Εͨശग़͠ͷඪ४తͳࡾ૚ ΞʔΩςΫνϟͷγεςϜͷ΍Γํͱ͸ࣅͯ΋ࣅ͔ͭͳ ͍ɻ “The Reactive Manifesto | Dave Farley's Weblog” ΑΓົ༁
  62. ैདྷͷࡾ૚ΞʔΩςΫνϟ ϓϨθϯςʔγϣϯ ϏδωεϩδοΫ RDB ಉظݺग़ ಉظݺग़ Ұຕؠͷ
 ΞϓϦέʔγϣϯ

  63. Reactive Systems ͷ۩ମྫ ϓϨθϯςʔγϣϯ ϏδωεϩδοΫ RDB ಉظݺग़ ಉظݺग़ RDB ඇಉظ

    ඇಉظ ඇಉظ KVS ඇಉظ Reactive ͳ
 σʔλϑϩʔ
  64. STORAGE & RETRIEVAL LOGIC PRESENTATION ROUTING Redis Memcache Flock T-Bird

    MySQL Tweet User Timeline Social Graph DMs API Web Monorail TFE HTTP Thrift “Stuff” http://monkey.org/~marius/scala2015.pdf Twitter ͷ
 ϚΠΫϩαʔϏεߏ଄
  65. Spark 1.4 ͷ
 DAG Visualization ػೳ https://cloud.githubusercontent.com/assets/2133137/7625997/e0878f8c-f9b4-11e4-8df3-7dd611b13c87.png

  66. Reactive Systems ͷಛ௃ http://www.reactivemanifesto.org/ja

  67. Reactive Systems ͷಛ௃ http://www.reactivemanifesto.org/ja ࣮ݱ͍ͨ͠Ձ஋:
 Ϣʔβ΁ਝ଎͔ͭҰ؏ͨ͠
 ଎౓ͰαʔϏεΛఏڙ͢Δ ো֐࣌ʹ΋
 ଈԠੑΛҡ࣋͢Δ ඇಉظϝοηʔδύογϯά͕


    શͯͷج൫Ͱ͋Δ ෛՙ͕มಈͯ͠΋
 ଈԠੑΛҡ࣋͢Δ
  68. ϝοηʔδۦಈͱ଱ো֐ੑ • ϝοηʔδۦಈͷγεςϜͰ͸ɿ • ίϯϙʔωϯτಉ࢜͸ඇಉظڥքͰִ཭͞ΕΔ ͷͰɺো֐ͷӨڹΛ෧͡ࠐΊΔ͜ͱ͕Ͱ͖Δ • ճ෮ॲཧΛଞͷίϯϙʔωϯτ (Supervisor) ʹ

    ҕৡͰ͖Δ (”Let it crash”) • ίϯϙʔωϯτΛෳ੡ͯ͠ಉ͡ϦΫΤετΛฒ ྻʹॲཧ͢Δ͜ͱͰ଱ো֐ੑΛߴΊΒΕΔ
  69. ϝοηʔδۦಈͱ஄ྗੑ • ஄ྗੑ = Scale Out + Scale In •

    ϝοηʔδۦಈͷγεςϜͰ͸ɿ • γϟʔσΟϯά΍ϨϓϦέʔγϣϯʹΑͬ ͯϦΫΤετΛ෼ࢄͰ͖Δ • Ґஔಁաੑ͕͋ΔͷͰɺίϯϙʔωϯτΛ ೚ҙͷ৔ॴʹ഑උͰ͖Δ
  70. Reactive Streams https://www.flickr.com/photos/jeremybrooks/3546105970

  71. Reactive Streams Reactive Manifesto Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ:

    ΞʔΩςΫνϟ:
  72. Programming vs Systems • ͲͪΒ΋ϦΞΫςΟϒͳίϯϙʔωϯτΛ૊ Έ্͛ͨσʔλϑϩʔͳͷͰಉ͡…Ͱ͸ͳ͍ A B C A

    B C Reactive Programming Reactive Systems ʹ ?
  73. Reactive Systems ͷ՝୊ • Reactive Systems ͸େ༰ྔσʔλΛѻ͏ඇಉ ظσʔλετϦʔϜ • ಉظܕͱҧ͍ɺγεςϜʹྲྀΕࠐΉσʔλྲྀ

    ྔΛ੍ޚ͢Δ࢓૊Έʢϑϩʔ੍ޚʣ͕ඞཁ • ϑϩʔ੍ޚʹࣦഊ͢Δͱɺσʔλϑϩʔ͕ܾ յͯ͠γεςϜશମͷΫϥογϡʹܨ͕Δ
  74. σʔλϑϩʔͷܾյ • Publisher ͸ Subscriber ΁ϝοηʔδΛૹΔ Publisher Subscriber … 3

    msgs/sec 3 msgs/sec ϝοηʔδόοϑΝ ॲཧೳྗ ૹ৴ೳྗ =
  75. σʔλϑϩʔͷܾյ • Subscriber ͕଎͍ͱ͖͸ՋʹͳΔ
 → ܭࢉػࢿݯΛ༗ޮ׆༻Ͱ͖ͳ͍ … < Publisher Subscriber

    3 msgs/sec དྷͳ͍… ͋Μ·ૹΔͱ
 ѱ͍͔ͳ… 1 msg/sec
  76. σʔλϑϩʔͷܾյ • Publisher ͕଎͗͢ΔͱόοϑΝ͕ᷓΕͯࢮ͵ … > Publisher Subscriber 3 msgs/sec

    100 msgs/sec ΍Ίͯʂ Զʹ
 ·͔ͤΖʔʂ
  77. https://www.flickr.com/photos/chiaralily/4978843623/

  78. Reactive Streams • Back-Pressure Ͱϑϩʔ੍ޚΛߦ͏ • ඇಉظετϦʔϜॲཧϥϯλΠϜͷ ૬ޓӡ༻ੑΛ֬อ͢ΔͨΊͷඪ४࢓༷

  79. Back-Pressure • Publisher ͸ϦΫΤετ͞Εͨ෼͚ͩϝοηʔ δΛૹΔ → ҆શ … 100 msgs/sec

    [Request(3)] Publisher Subscriber 3 msgs/sec ࣍ɺ3 ݸ͍ͩ͘͞ ͍͋Αʔ
  80. Back-Pressure • Back-Pressure ͸఻೻͢Δ • C ͕஗͘ͳͬͨΒ B, A ΋εϩʔμ΢ϯ͢Δ

    B C … ࠓ͸͍͍Ͱ͢ A … ࠓ͸͍͍Ͱ͢ ͍͋Αʔ
  81. SPI ͷΠϯλϑΣʔε public interface Publisher<T> { public void subscribe(Subscriber<? super

    T> s); } public interface Subscriber<T> { public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete(); } public interface Subscription { public void request(long n); public void cancel(); } ͢΂ͯ໭Γ஋ͳ͠ʹඇಉظ ޠኮ͸ RxJava ͕ϕʔε
  82. ࢓༷ॻͱTCK • ϥϯλΠϜؒͷ૬ޓ઀ଓੑΛอূ͢Δ

  83. ४ڌ࣮૷ • Akka Streams (Typesafe) • Ratpack • Reactor (Spring)

    • RxJava (Netflix) • Vert.x 3.0 (Red Hat)
  84. DB ΞΫηεϥΠϒϥϦͷ४ڌ࣮૷ • Slick 3.0 a.k.a “Reactive Slick” (JDBC) •

    ReactiveMongo • Reactive Rabbit (AMQP) • Reactive Kafka • etc…
  85. ͳͥ Reactive ͳ DB Ξμϓλ͕ඞཁʁ • ྫ͑͹ɺJDBC ͸ಉظ API ͳͷͰɺඇಉظͳ

    ϑϨʔϜϫʔΫΛ࢖͍ͬͯͯ΋ worker thread ΁ͷॲཧͷҕৡΛࣗ෼Ͱॻ͘ඞཁ͕͋ͬͨ • context switch ͷίετɺεϨου਺ʹԠ͡ ͨϝϞϦফඅɺεϨουؒ௨৴ͷϩοΫڝ߹ • ϫʔΧεϨου਺ͱɺDB ίωΫγϣϯϓʔϧ ͷαΠζΛ”ਖ਼͘͠”ઃఆ͢Δඞཁ͕͋Δ
  86. ͢΂͕ͯ Reactive ʹͳΔ • Reactive Systems ΛɺReactive Streams ४ڌ ͷίϯϙʔωϯτΛ࢖ͬͯೖޱ͔Βग़ޱ·Ͱ

    ૊Έ্͛Δ͜ͱ͕Ͱ͖Δ AMQP Rx
 Java Akka Vert.x RDB ྫ:
  87. ·ͱΊ

  88. ·ͱΊ • ඇಉظϓϩάϥϛϯά΍෼ࢄγεςϜͷීٴ ʹ൐ͬͯɺ৽ͨͳϓϩάϥϛϯάϞσϧ΍γ εςϜΞʔΩςΫνϟ͕ٻΊΒΕ͍ͯΔ • Reactive ͷߟ͑ํ͸ɺ͜͏ͨ͠՝୊Λղܾ͢ ΔπʔϧΛఏڙ͢Δ

  89. ·ͱΊ • ʮಉظతͳจ๏Ͱඇಉظϓϩάϥϛϯάʯʹ ߆ΔΑΓɺͦΕΒͷ੍໿Λੵۃతʹड͚ೖΕ ͯ৽͍͠΍ΓํΛशಘ͢Δͷ͕ۙಓ • ϓϩάϥϛϯάϞσϧࣗମΑΓ΋ɺͦΕΒΛ Լࢧ͑͢ΔϥϯλΠϜͷੑೳ΍଱ো֐ੑɺӡ ༻ੑ͕ΑΓॏཁʹͳ͖͍ͬͯͯΔ

  90. Thank you!