Slide 1

Slide 1 text

Reactive System Meetup in ੢৽॓ 
 Reactive ͱ͸Կ͔? Yuta Okamoto (@okapies) 2015/08/18ʢվగ1ʣ

Slide 2

Slide 2 text

Who are you? • Ԭຊ ༤ଠ (@okapies) • ڵຯ͕͋Δ͜ͱɿ • Scala ͱ͔ؔ਺ܕϓϩάϥϛϯάͱ͔ • ΢ΣϒαʔϏεͷΠϯϑϥपΓʢBash ৬ਓʣ • Scala Matsuri 2016 ४උҕһʢ຋༁νʔϜʣ

Slide 3

Slide 3 text

ॻ͍ͨهࣄ • ւ֎จݙͷ຋༁ • Reactive Manifesto (http://www.reactivemanifesto.org/) • Effective Scala (http://twitter.github.io/effectivescala/) • ϒϩάهࣄ (http://okapies.hateblo.jp/) • ʮؔ਺ܕϓϩάϥϚͷͨΊͷ Rx ೖ໳ʯγϦʔζ • ʮϚΠΫϩαʔϏε͕ Scala ΛબͿ̏ͭͷཧ༝ʯ

Slide 4

Slide 4 text

Scala Matsuri 2016 ! ! • དྷ೥1݄30ʙ31೔ʹ։࠵ܾఆʂ http://scalamatsuri.org/ • ొஃऀืूதɻԠืΛ͓଴ͪͯ͠·͢ʂ • ४උҕһձͷελοϑืूதʢ࣍ճఆྫ 9/12ʢ౔ʣʣ

Slide 5

Slide 5 text

ࠓ೔͓࿩͍ͨ͜͠ͱ • Reactive ͱ͸Կ͔ʁʢʹ͍ͭͯͷࢲͷཧղʣ • Reactive ͷഎܠʹ͋ΔύϥμΠϜγϑτ • खଓ͖ܕ (how) ͔Βએݴܕ (what) ΁ • ϓϩάϥϛϯάϞσϧ͔ΒϥϯλΠϜ΁ • ಉظతͳϞϊϦε͔Βඇಉظతͳ෼ࢄγεςϜ΁

Slide 6

Slide 6 text

Reactive?

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Reactive ͷࡾͭͷཱ৔ Reactive Systems Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ: γεςϜΞʔΩςΫνϟ:

Slide 9

Slide 9 text

Reactive ͷ
 Ϣʔεέʔε

Slide 10

Slide 10 text

Reactive ͕ٻΊΒΕΔ৔໘ • Frontend • GUIɾϑϩϯτΤϯυ • Backend • ϚΠΫϩαʔϏε • Ϗοάσʔλॲཧ ϓϩάϥϛϯάϞσϧ͕ओͳؔ৺ Ճ͑ͯΞʔΩςΫνϟʹؔ৺

Slide 11

Slide 11 text

ղܾ͍ͨ͠՝୊ • ػೳ໘: • Πϕϯτʢϝοηʔδʣۦಈ • ඇಉظͳίϯϙʔωϯτؒ࿈ܞ • ฒߦɾฒྻॲཧ • ඇػೳ໘: • ଱ো֐ੑɺεέʔϥϏϦςΟ ՝୊΍ͦΕʹର͢ΔΞϓϩʔν͸
 ڞ௨͍ͯ͠Δ͕…

Slide 12

Slide 12 text

“Reactive” in Frontend • Reactive Extensions • Bacon.js • Elm • React.js • …

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

GUIɾϑϩϯτΤϯυ https://github.com/tehmou/rx-android-architecture RxJava + Android
 ͷσϞΞϓϦ ςΩετϘοΫε͕ߋ৽͞Ε
 Δ౓ʹ JSON API Ͱݕࡧɻ ໭͖ͬͯͨ݁ՌΛඇಉظʹ Widget ʹ൓ө

Slide 15

Slide 15 text

“Reactive” in Backend • ϚΠΫϩαʔϏε • Ϗοάσʔλॲཧ ෼ࢄॲཧ΍ฒྻॲཧ͸ɺ΋͸΍
 ಛผͳ΋ͷͰ͸ͳ͘ͳΓͭͭ͋Δ

Slide 16

Slide 16 text

ϚΠΫϩαʔϏε 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

Slide 17

Slide 17 text

େن໛ͳϚΠΫϩαʔϏεͷྫ http://www.slideshare.net/adriancockcroft/goto-berlin/76

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

αʔϏεʹର͢ΔཁٻͷมԽ ਺೥લ ݱࡏ αʔό਺ ʙ਺ेϊʔυ ਺ઍҎ্ʙ ཁٻԠ౴࣌ؒ ʙ਺ඵ ʙϛϦඵ ཁٻՔಇ཰ ਺࣌ؒͷΦϑϥΠϯ
 ϝϯςφϯεΛڐ༰ 100% σʔλྔ ΪΨόΠτ୯Ґ ϖλόΠτ୯Ґ

Slide 20

Slide 20 text

Reactive Manifesto http://www.reactivemanifesto.org/ja

Slide 21

Slide 21 text

Reactive Manifesto • Reactive Systems ΁ͷࢧ࣋Λݺͼ͔͚Δจॻ • ࣾͷ CTO Β͕ओಋ • ଞʹ Dave Farley (”ܧଓతσϦόϦʔ”ͷஶऀ) ΍ Martin Thompson (ݩ LMAX CTO) ͳͲ • ϚʔέςΟϯάจॻͱͯ͠ͷ৭࠼͕ೱ͍ʢํ޲ੑ ͱͯ͠͸ “The Twelve-Factor App” ʹ͍ۙʣ ͦΖͦΖࢍಉऀ
 12,000 ਓ௒͑

Slide 22

Slide 22 text

Reactive Streams • “Back-Pressure ෇͖ͷඇಉظετϦʔϜॲཧ” ͷ ඪ४ΛఆΊΔ࢓༷ • ඇಉظετϦʔϜॲཧʹ͖ͭ·ͱ͏ϑϩʔ੍ޚ ͷ՝୊ʢόοϑΝᷓΕ໰୊ʣͷղܾࡦΛఏࣔ • ࢓༷ʹ४ڌͨ͠ϥϯλΠϜͷ૬ޓ઀ଓੑΛอূ • JDK 9 Ͱͷඪ४Խʹ޲͚ͯ࡞ۀத Reactive Systems
 ͷٕज़త՝୊Λղܾ

Slide 23

Slide 23 text

ܦҢ • Reactive Manifesto ͷൃද(2013೥9݄) • Typesafe ͷओಋͰɺඇಉظετϦʔϜٕज़Λ ։ൃ͢Δϕϯμʔ֤ࣾͷؒͰɺϑϩʔ੍ޚͷٕ ज़՝୊ͷղܾࡦΛ࿩͠߹͏ίϛϡχςΟ͕ൃ଍ • GitHub ʹ reactive-streams άϧʔϓΛ࡞੒ɻ ਖ਼ࣜʹڞಉͰ࢓༷ࡦఆΛ࢝ΊΔ(2014೥ॳ಄)

Slide 24

Slide 24 text

ओͳࢀՃϕϯμʔ • (Akka) • (RxJava) • (Reactor) • (Vert.x) Scala ݴޠͷ։ൃݩ ถࠃ࠷େखͷ
 ಈը഑৴αʔϏε Spring Framework
 ͷ։ൃݩ

Slide 25

Slide 25 text

ओͳࢀՃऀ • Doug Lea • JSR 166 (java.util.concurrent)
 ͷ Specification Lead • “Java Concurrency in Practice”
 ͷஶऀͷҰਓ • JDK Ͱͷඪ४Խ͸ࢯͷओಋͰਐΊΒΕ͍ͯΔ http://www.amazon.co.jp/dp/4797337206/

Slide 26

Slide 26 text

OpenJDK Ͱͷඪ४Խ׆ಈ http://openjdk.java.net/jeps/8132960

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Reactive ͳίϯϙʔωϯτ • σʔλͷೖྗʹ൓Ԡ (react) ͯ͠ɺͦΕΛม׵ ͯ͠ग़ྗ͢Δ ʁ ೖྗ ग़ྗ • ؔ਺ʁ • ΦϒδΣΫτʁ • ΞΫλʔʁ • αϒγεςϜʁ ίϯϙʔωϯτͷதͰ
 ಈ࡞͕׬݁͢Δ

Slide 30

Slide 30 text

๬·͍͠ੑ࣭: ૄ݁߹ੑɺִ཭ੑ • ϞδϡʔϧԽ, ඇಉظԽ, ฒྻԽ͕༰қʹͳΔ ʁ ೖྗ ग़ྗ ? ? ࣗ෼͕Կͷίϯϙʔωϯτ ʹґଘ͢Δ͔͸ҙࣝ͠ͳ͍ × × ֎ଆͷঢ়ଶ΍ಈ࡞ʹ
 ʢ҉໧తʹʣ
 ӨڹΛ༩͑ͳ͍ ೖྗσʔλʹͷΈґଘ͢Δ

Slide 31

Slide 31 text

σʔλϑϩʔ Input Input Output ૄ݁߹ͳίϯϙʔωϯτΛ૊Έཱͯͨσʔλϑϩʔ ೖྗ ग़ྗ

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

Reactive Programming Reactive Systems Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ γεςϜΞʔΩςΫνϟ

Slide 34

Slide 34 text

Reactive ͳϓϩάϥϜ Input Input Output ೖྗ ग़ྗ Reactive ͳίϯϙʔωϯτΛ
 σʔλϑϩʔͱͯ͠૊ΈཱͯΔ
 ͜ͱͰϓϩάϥϛϯά͢Δ

Slide 35

Slide 35 text

ैདྷͷखଓ͖ܕϓϩάϥϜ A = 1; B = 2; C = (A+1) + (B-1)*2; ※”Ͳ͏΍࣮ͬͯߦ͢Δ͔”͸ࣗ໌ ʢʹ ࣮ߦϞσϧʣ ্͔Βॱ൪ʹ࣮ߦ͢Δ

Slide 36

Slide 36 text

खଓ͖ܕ vs Reactive • ैདྷͷखଓ͖ܕͷϓϩάϥϛϯάϞσϧͱશ ͘૬༰Εͳ͍Α͏ʹݟ͑Δɺ͕… 1 2 A = 1; B = 2; C = (A+1) + (B-1)*2; ೖྗ ग़ྗ

Slide 37

Slide 37 text

-1 ×2 + +1 A B C खଓ͖͸σʔλϑϩʔͰදݱͰ͖Δ A = 1; B = 2; C = (A+1) + (B-1)*2; 1 2 4 1 2 2 ※Ͳ͏࣮ߦ͢Δ͔͸๨ΕΑ͏ ʢม਺ͱԋࢉࢠͷؔ܎͚ͩݟΔʣ

Slide 38

Slide 38 text

σʔλϑϩʔͱ࣮ߦϞσϧ • खଓ͖ܕͱ Reactive ͸ͲͪΒ΋σʔλϑϩʔ Ͱදݱ͢Δ͜ͱ͕Ͱ͖Δ
 㱺 ҧ͍͸࣮ߦϞσϧʹ͋Δ A B C A = 1; B = 2; C = (A+1) + (B-1)*2; ೖྗ ग़ྗ

Slide 39

Slide 39 text

-1 ×2 + +1 A B C ม਺Λߋ৽: खଓ͖ܕͷ৔߹ A = 1; B = 2; C = (A+1) + (B-1)*2;
 A = 2; 1 $ 2 2 4 C ʹ͸
 ൓ө͞Εͳ͍ खଓ͖ܕͷ࣮ߦϞσϧ × × × × × ×

Slide 40

Slide 40 text

-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 ͳ࣮ߦϞσϧ

Slide 41

Slide 41 text

-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 ͳ࣮ߦϞσϧ

Slide 42

Slide 42 text

-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 ͳ࣮ߦϞσϧ

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

ྫ (RxJava): Observable a = …; Observable b = …; ! Observable a1 = a.map( (i) -> i + 1 ); Observable b1 = b.map( (j) -> j - 1 ) .map( (k) -> k * 2 ); ! ! Observable c = Observable.combineLatest(a1, b1, (i, j) -> i + j ); σʔλϑϩʔΛܨ͛Δϝιου ؔ਺ ೖྗ A B C +1 —1 ×2 + “Ͳ͏࣮ߦ͢Δ͔” ͸
 Ͳ͜ʹ΋ॻ͍ͯͳ͍ʂ

Slide 45

Slide 45 text

ϓϩάϥϛϯάϞσϧ + ϥϯλΠϜ Input Input Output (2) ϥϯλΠϜ (1) ϓϩάϥϛϯάϞσϧ ʢมߋͷ఻೻ (how) ΛϓϩάϥϚʹ୅Θ࣮ͬͯߦ͢Δʣ ʢσʔλϑϩʔ (what) Λهड़͢Δखஈʣ

Slide 46

Slide 46 text

ϓϩάϥϛϯάϞσϧ + ϥϯλΠϜ Reactive Systems Reactive Programming ??? ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ: γεςϜΞʔΩςΫνϟ ϥϯλΠϜʹΑΔ
 มߋͷ఻೻͕ RP ͷಛ௃

Slide 47

Slide 47 text

ղܾ͍ͨ͠՝୊ʢ࠶ܝʣ • ػೳ໘: • Πϕϯτʢϝοηʔδʣۦಈ • ඇಉظͳίϯϙʔωϯτؒ࿈ܞ • ฒߦɾฒྻॲཧ • ඇػೳ໘: • ଱ো֐ੑɺεέʔϥϏϦςΟ खଓ͖తͳϓϩάϥϛϯάख๏
 Ͱهड़͢Δͷ͸େมͩͬͨ

Slide 48

Slide 48 text

Reactive ͳϞσϧͷϝϦοτ • ֎͔ΒͷΠϕϯτ͕
 ࣗಈతʹ఻೻͞ΕΔ • ඇಉظԽɾฒྻԽ͠΍͍͢ • “What” ͱ “How” ͕෼཭͞ΕΔͷͰ
 ૊Έ߹ΘͤՄೳ (composable) ʹ͠΍͍͢ }ϥϯλΠϜʹ೚ͤΔ

Slide 49

Slide 49 text

“What” ͱ “How” ͷ෼཭ • ϓϩάϥϚ͸”ೖྗΛԿʹม׵͢Δ͔“͚ͩʹ
 ஫໨ͯ͠ϩδοΫΛॻ͘
 㱺 ֎෦ͷঢ়ଶʹӨڹΛड͚ͣૄ݁߹ੑ͕ߴ·Δ • ”Ͳ͏΍࣮ͬͯߦ͢Δ͔”͸ϥϯλΠϜͷ໾ׂ ʢ࣮ߦϞσϧʣ ? ? ? ? ?

Slide 50

Slide 50 text

σʔλϑϩʔͷ࠷దԽ • ϥϯλΠϜ͸ɺσʔλϑϩʔͷ࣮ߦํ๏Λࣗ ಈతʹ࠷దԽ͢Δ༨஍͕͋Δ • ܭࢉͷ݁߹ (fuse) ΍ہॴԽ • ฒྻԽ • ෼ࢄԽ

Slide 51

Slide 51 text

ྫ: 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 Λ࢖࣮ͬͯߦ

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Materializer ʹΑΔ࠷దԽ • DSL Ͱهड़ͨ͠ FlowGraph Λ Materializeʢ۩ ݱԽʣ࣮ͯ͠ߦ͢Δ • Materializer ͷ࣮૷࣍ୈͰ༷ʑͳ࠷దԽΛࢪ ͤΔ࢓૊Έʹͳ͍ͬͯΔ • Akka ࣗମ͕෼ࢄϑϨʔϜϫʔΫͳͷͰɺকདྷ తʹ͸ࣗಈతͳ෼ࢄԽʹ΋ରԠͰ͖Δʁ

Slide 54

Slide 54 text

ϥϯλΠϜͱͯ͠ͷΫϥ΢υ https://speakerdeck.com/googlecloudjapan/google-cloud-dataflowwoli-jie-suru Google Ϋϥ΢υ͕
 ϥϯλΠϜʹ͋ͨΔ σʔλϑϩʔఆٛ

Slide 55

Slide 55 text

Reactive Programming ͷར఺ • σʔλϑϩʔͷ࣮ߦΛϥϯλΠϜʹ೚ͤΔ͜ͱͰ • Πϕϯτۦಈɺඇಉظॲཧɺฒߦɾฒྻॲཧ ͕ඞཁͳίʔυ͕༰қʹهड़Ͱ͖Δ • “What” ͱ “How” ͕෼཭͞ΕΔ͜ͱͰૄ݁߹ ੑ͕ߴ·Δ • ࣮ߦͷࣗಈతͳ࠷దԽ͕ՄೳʹͳΔ

Slide 56

Slide 56 text

Reactive Systems http://www.reactivemanifesto.org/ja

Slide 57

Slide 57 text

Reactive Systems Reactive Systems Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ ϥϯλΠϜ γεςϜΞʔΩςΫνϟ:

Slide 58

Slide 58 text

ཁٻͷมԽʢ࠶ܝʣ ਺೥લ ݱࡏ αʔό਺ ʙ਺ेϊʔυ ਺ઍҎ্ʙ ཁٻԠ౴࣌ؒ ʙ਺ඵ ʙϛϦඵ ཁٻՔಇ཰ ਺࣌ؒͷΦϑϥΠϯ
 ϝϯςφϯεΛڐ༰ 100% σʔλྔ ΪΨόΠτ୯Ґ ϖλόΠτ୯Ґ

Slide 59

Slide 59 text

ղܾ͍ͨ͠՝୊ʢ࠶ܝʣ • ػೳ໘: • Πϕϯτʢϝοηʔδʣۦಈ • ඇಉظͳίϯϙʔωϯτؒ࿈ܞ • ฒߦɾฒྻॲཧ • ඇػೳ໘: • ଱ো֐ੑɺεέʔϥϏϦςΟ

Slide 60

Slide 60 text

Reactive Systems “େن໛γεςϜΛߏங͢Δ૊৫͸
 ͜ͷมԽʹରॲ͢ΔઃܭݪଇΛ
 ͢Ͱʹൃݟ͍ͯ͠Δ” ! ! ! “ͦͷΑ͏ͳಛ௃Λඋ͑ΔγεςϜΛ Reactive Systems ͱݺ΅͏” http://www.reactivemanifesto.org/ja

Slide 61

Slide 61 text

Reactive Systems ͷ۩ମྫ ࢲ͕࢓ࣄͰؔΘͬͨɺେ͖ͳγεςϜͷΞʔΩςΫνϟ ʹ͸ྨࣅ఺͕͋ͬͨɻ ͦ͏ͨ͠γεςϜͰ͸ɺ໰୊ྖҬʹ͓͚Δ໌֬ͳ Bounded Context Λ࣮૷ͨ͠αʔϏε͕ૄ݁߹Ͱ݁ͼ ͍͓ͭͯΓɺޓ͍ͷ௨৴͸ඇಉظϝοηʔδͷΈͰߦ ͏ɻ ͜ΕΒ͸ɺRDB ͷ্ʹߏங͞Εͨശग़͠ͷඪ४తͳࡾ૚ ΞʔΩςΫνϟͷγεςϜͷ΍Γํͱ͸ࣅͯ΋ࣅ͔ͭͳ ͍ɻ “The Reactive Manifesto | Dave Farley's Weblog” ΑΓົ༁

Slide 62

Slide 62 text

ैདྷͷࡾ૚ΞʔΩςΫνϟ ϓϨθϯςʔγϣϯ ϏδωεϩδοΫ RDB ಉظݺग़ ಉظݺग़ Ұຕؠͷ
 ΞϓϦέʔγϣϯ

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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 ͷ
 ϚΠΫϩαʔϏεߏ଄

Slide 65

Slide 65 text

Spark 1.4 ͷ
 DAG Visualization ػೳ https://cloud.githubusercontent.com/assets/2133137/7625997/e0878f8c-f9b4-11e4-8df3-7dd611b13c87.png

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

ϝοηʔδۦಈͱ଱ো֐ੑ • ϝοηʔδۦಈͷγεςϜͰ͸ɿ • ίϯϙʔωϯτಉ࢜͸ඇಉظڥքͰִ཭͞ΕΔ ͷͰɺো֐ͷӨڹΛ෧͡ࠐΊΔ͜ͱ͕Ͱ͖Δ • ճ෮ॲཧΛଞͷίϯϙʔωϯτ (Supervisor) ʹ ҕৡͰ͖Δ (”Let it crash”) • ίϯϙʔωϯτΛෳ੡ͯ͠ಉ͡ϦΫΤετΛฒ ྻʹॲཧ͢Δ͜ͱͰ଱ো֐ੑΛߴΊΒΕΔ

Slide 69

Slide 69 text

ϝοηʔδۦಈͱ஄ྗੑ • ஄ྗੑ = Scale Out + Scale In • ϝοηʔδۦಈͷγεςϜͰ͸ɿ • γϟʔσΟϯά΍ϨϓϦέʔγϣϯʹΑͬ ͯϦΫΤετΛ෼ࢄͰ͖Δ • Ґஔಁաੑ͕͋ΔͷͰɺίϯϙʔωϯτΛ ೚ҙͷ৔ॴʹ഑උͰ͖Δ

Slide 70

Slide 70 text

Reactive Streams https://www.flickr.com/photos/jeremybrooks/3546105970

Slide 71

Slide 71 text

Reactive Streams Reactive Manifesto Reactive Programming Reactive Streams ϓϩάϥϛϯάϞσϧ: ϥϯλΠϜ: ΞʔΩςΫνϟ:

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

Reactive Systems ͷ՝୊ • Reactive Systems ͸େ༰ྔσʔλΛѻ͏ඇಉ ظσʔλετϦʔϜ • ಉظܕͱҧ͍ɺγεςϜʹྲྀΕࠐΉσʔλྲྀ ྔΛ੍ޚ͢Δ࢓૊Έʢϑϩʔ੍ޚʣ͕ඞཁ • ϑϩʔ੍ޚʹࣦഊ͢Δͱɺσʔλϑϩʔ͕ܾ յͯ͠γεςϜશମͷΫϥογϡʹܨ͕Δ

Slide 74

Slide 74 text

σʔλϑϩʔͷܾյ • Publisher ͸ Subscriber ΁ϝοηʔδΛૹΔ Publisher Subscriber … 3 msgs/sec 3 msgs/sec ϝοηʔδόοϑΝ ॲཧೳྗ ૹ৴ೳྗ =

Slide 75

Slide 75 text

σʔλϑϩʔͷܾյ • Subscriber ͕଎͍ͱ͖͸ՋʹͳΔ
 → ܭࢉػࢿݯΛ༗ޮ׆༻Ͱ͖ͳ͍ … < Publisher Subscriber 3 msgs/sec དྷͳ͍… ͋Μ·ૹΔͱ
 ѱ͍͔ͳ… 1 msg/sec

Slide 76

Slide 76 text

σʔλϑϩʔͷܾյ • Publisher ͕଎͗͢ΔͱόοϑΝ͕ᷓΕͯࢮ͵ … > Publisher Subscriber 3 msgs/sec 100 msgs/sec ΍Ίͯʂ Զʹ
 ·͔ͤΖʔʂ

Slide 77

Slide 77 text

https://www.flickr.com/photos/chiaralily/4978843623/

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

Back-Pressure • Publisher ͸ϦΫΤετ͞Εͨ෼͚ͩϝοηʔ δΛૹΔ → ҆શ … 100 msgs/sec [Request(3)] Publisher Subscriber 3 msgs/sec ࣍ɺ3 ݸ͍ͩ͘͞ ͍͋Αʔ

Slide 80

Slide 80 text

Back-Pressure • Back-Pressure ͸఻೻͢Δ • C ͕஗͘ͳͬͨΒ B, A ΋εϩʔμ΢ϯ͢Δ B C … ࠓ͸͍͍Ͱ͢ A … ࠓ͸͍͍Ͱ͢ ͍͋Αʔ

Slide 81

Slide 81 text

SPI ͷΠϯλϑΣʔε public interface Publisher { public void subscribe(Subscriber super T> s); } public interface Subscriber { 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 ͕ϕʔε

Slide 82

Slide 82 text

࢓༷ॻͱTCK • ϥϯλΠϜؒͷ૬ޓ઀ଓੑΛอূ͢Δ

Slide 83

Slide 83 text

४ڌ࣮૷ • Akka Streams (Typesafe) • Ratpack • Reactor (Spring) • RxJava (Netflix) • Vert.x 3.0 (Red Hat)

Slide 84

Slide 84 text

DB ΞΫηεϥΠϒϥϦͷ४ڌ࣮૷ • Slick 3.0 a.k.a “Reactive Slick” (JDBC) • ReactiveMongo • Reactive Rabbit (AMQP) • Reactive Kafka • etc…

Slide 85

Slide 85 text

ͳͥ Reactive ͳ DB Ξμϓλ͕ඞཁʁ • ྫ͑͹ɺJDBC ͸ಉظ API ͳͷͰɺඇಉظͳ ϑϨʔϜϫʔΫΛ࢖͍ͬͯͯ΋ worker thread ΁ͷॲཧͷҕৡΛࣗ෼Ͱॻ͘ඞཁ͕͋ͬͨ • context switch ͷίετɺεϨου਺ʹԠ͡ ͨϝϞϦফඅɺεϨουؒ௨৴ͷϩοΫڝ߹ • ϫʔΧεϨου਺ͱɺDB ίωΫγϣϯϓʔϧ ͷαΠζΛ”ਖ਼͘͠”ઃఆ͢Δඞཁ͕͋Δ

Slide 86

Slide 86 text

͢΂͕ͯ Reactive ʹͳΔ • Reactive Systems ΛɺReactive Streams ४ڌ ͷίϯϙʔωϯτΛ࢖ͬͯೖޱ͔Βग़ޱ·Ͱ ૊Έ্͛Δ͜ͱ͕Ͱ͖Δ AMQP Rx
 Java Akka Vert.x RDB ྫ:

Slide 87

Slide 87 text

·ͱΊ

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

Thank you!